|
| 1 | +/****************************************************************************** |
| 2 | + Copyright 2020 Embedded Office GmbH & Co. KG |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +******************************************************************************/ |
| 16 | + |
| 17 | +/****************************************************************************** |
| 18 | +* INCLUDES |
| 19 | +******************************************************************************/ |
| 20 | + |
| 21 | +#include "co_core.h" |
| 22 | + |
| 23 | +/****************************************************************************** |
| 24 | +* PRIVATE DEFINES |
| 25 | +******************************************************************************/ |
| 26 | + |
| 27 | +#define COT_ENTRY_SIZE (uint32_t)6 |
| 28 | + |
| 29 | +/****************************************************************************** |
| 30 | +* PRIVATE FUNCTIONS |
| 31 | +******************************************************************************/ |
| 32 | + |
| 33 | +static uint32_t COTInt48Size (struct CO_OBJ_T *obj, struct CO_NODE_T *node, uint32_t width); |
| 34 | +static CO_ERR COTInt48Read (struct CO_OBJ_T *obj, struct CO_NODE_T *node, void *buffer, uint32_t size); |
| 35 | +static CO_ERR COTInt48Write(struct CO_OBJ_T *obj, struct CO_NODE_T *node, void *buffer, uint32_t size); |
| 36 | + |
| 37 | +/****************************************************************************** |
| 38 | +* PUBLIC GLOBALS |
| 39 | +******************************************************************************/ |
| 40 | + |
| 41 | +const CO_OBJ_TYPE COTInt48 = { COTInt48Size, 0, COTInt48Read, COTInt48Write, 0 }; |
| 42 | + |
| 43 | +/****************************************************************************** |
| 44 | +* FUNCTIONS |
| 45 | +******************************************************************************/ |
| 46 | + |
| 47 | +static uint32_t COTInt48Size(struct CO_OBJ_T *obj, struct CO_NODE_T *node, uint32_t width) |
| 48 | +{ |
| 49 | + uint32_t result = (uint32_t)0; |
| 50 | + |
| 51 | + CO_UNUSED(node); |
| 52 | + CO_UNUSED(width); |
| 53 | + |
| 54 | + if (CO_IS_DIRECT(obj->Key) != 0) { |
| 55 | + result = (uint32_t)COT_ENTRY_SIZE; |
| 56 | + } else { |
| 57 | + /* check for valid reference */ |
| 58 | + if ((obj->Data) != (CO_DATA)0) { |
| 59 | + result = (uint32_t)COT_ENTRY_SIZE; |
| 60 | + } |
| 61 | + } |
| 62 | + return (result); |
| 63 | +} |
| 64 | + |
| 65 | +static CO_ERR COTInt48Read(struct CO_OBJ_T *obj, struct CO_NODE_T *node, void *buffer, uint32_t size) |
| 66 | +{ |
| 67 | + CO_ERR result = CO_ERR_NONE; |
| 68 | + uint64_t value; |
| 69 | + |
| 70 | + CO_UNUSED(node); |
| 71 | + ASSERT_PTR_ERR(obj, CO_ERR_BAD_ARG); |
| 72 | + ASSERT_PTR_ERR(buffer, CO_ERR_BAD_ARG); |
| 73 | + |
| 74 | + if (CO_IS_DIRECT(obj->Key) != 0) { |
| 75 | + value = (uint64_t)(obj->Data); |
| 76 | + } else { |
| 77 | + value = *((uint64_t *)(obj->Data)); |
| 78 | + } |
| 79 | + if (CO_IS_NODEID(obj->Key) != 0) { |
| 80 | + value += node->NodeId; |
| 81 | + } |
| 82 | + if (size == COT_ENTRY_SIZE) { |
| 83 | + *((uint64_t *)buffer) = value; |
| 84 | + } else { |
| 85 | + result = CO_ERR_BAD_ARG; |
| 86 | + } |
| 87 | + return (result); |
| 88 | +} |
| 89 | + |
| 90 | +static CO_ERR COTInt48Write(struct CO_OBJ_T *obj, struct CO_NODE_T *node, void *buffer, uint32_t size) |
| 91 | +{ |
| 92 | + CO_ERR result = CO_ERR_NONE; |
| 93 | + uint64_t value; |
| 94 | + uint64_t oldValue; |
| 95 | + |
| 96 | + CO_UNUSED(node); |
| 97 | + ASSERT_PTR_ERR(obj, CO_ERR_BAD_ARG); |
| 98 | + ASSERT_PTR_ERR(buffer, CO_ERR_BAD_ARG); |
| 99 | + |
| 100 | + value = *((uint64_t *)buffer); |
| 101 | + if (size == COT_ENTRY_SIZE) { |
| 102 | + if (CO_IS_NODEID(obj->Key) != 0) { |
| 103 | + value -= node->NodeId; |
| 104 | + } |
| 105 | + if (CO_IS_DIRECT(obj->Key) != 0) { |
| 106 | + oldValue = (uint64_t)obj->Data; |
| 107 | + obj->Data = (CO_DATA)(value); |
| 108 | + } else { |
| 109 | + oldValue = *((uint64_t *)(obj->Data)); |
| 110 | + *((uint64_t *)(obj->Data)) = value; |
| 111 | + } |
| 112 | + if ((CO_IS_ASYNC(obj->Key) != 0 ) && |
| 113 | + (CO_IS_PDOMAP(obj->Key) != 0 ) && |
| 114 | + (oldValue != value)) { |
| 115 | + COTPdoTrigObj(node->TPdo, obj); |
| 116 | + } |
| 117 | + } else { |
| 118 | + result = CO_ERR_BAD_ARG; |
| 119 | + } |
| 120 | + return (result); |
| 121 | +} |
0 commit comments