-
Notifications
You must be signed in to change notification settings - Fork 134
Add type Integer48 #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
giuliobenetti
wants to merge
1
commit into
embedded-office:develop
Choose a base branch
from
Benetti-Engineering:dev/add-integer48
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add type Integer48 #128
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /****************************************************************************** | ||
| Copyright 2020 Embedded Office GmbH & Co. KG | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| ******************************************************************************/ | ||
|
|
||
| /****************************************************************************** | ||
| * INCLUDES | ||
| ******************************************************************************/ | ||
|
|
||
| #include "co_core.h" | ||
|
|
||
| /****************************************************************************** | ||
| * PRIVATE DEFINES | ||
| ******************************************************************************/ | ||
|
|
||
| #define COT_ENTRY_SIZE (uint32_t)6 | ||
|
|
||
| /****************************************************************************** | ||
| * PRIVATE FUNCTIONS | ||
| ******************************************************************************/ | ||
|
|
||
| static uint32_t COTInt48Size (struct CO_OBJ_T *obj, struct CO_NODE_T *node, uint32_t width); | ||
| static CO_ERR COTInt48Read (struct CO_OBJ_T *obj, struct CO_NODE_T *node, void *buffer, uint32_t size); | ||
| static CO_ERR COTInt48Write(struct CO_OBJ_T *obj, struct CO_NODE_T *node, void *buffer, uint32_t size); | ||
|
|
||
| /****************************************************************************** | ||
| * PUBLIC GLOBALS | ||
| ******************************************************************************/ | ||
|
|
||
| const CO_OBJ_TYPE COTInt48 = { COTInt48Size, 0, COTInt48Read, COTInt48Write, 0 }; | ||
|
|
||
| /****************************************************************************** | ||
| * FUNCTIONS | ||
| ******************************************************************************/ | ||
|
|
||
| static uint32_t COTInt48Size(struct CO_OBJ_T *obj, struct CO_NODE_T *node, uint32_t width) | ||
| { | ||
| uint32_t result = (uint32_t)0; | ||
|
|
||
| CO_UNUSED(node); | ||
| CO_UNUSED(width); | ||
|
|
||
| if (CO_IS_DIRECT(obj->Key) != 0) { | ||
| CONodeFatalError(); | ||
| } else { | ||
| /* check for valid reference */ | ||
| if ((obj->Data) != (CO_DATA)0) { | ||
| result = (uint32_t)COT_ENTRY_SIZE; | ||
| } | ||
| } | ||
| return (result); | ||
| } | ||
|
|
||
| static CO_ERR COTInt48Read(struct CO_OBJ_T *obj, struct CO_NODE_T *node, void *buffer, uint32_t size) | ||
| { | ||
| CO_ERR result = CO_ERR_NONE; | ||
| uint64_t value; | ||
|
|
||
| CO_UNUSED(node); | ||
| ASSERT_PTR_ERR(obj, CO_ERR_BAD_ARG); | ||
| ASSERT_PTR_ERR(buffer, CO_ERR_BAD_ARG); | ||
|
|
||
| if (CO_IS_DIRECT(obj->Key) != 0) { | ||
| return CO_ERR_OBJ_READ; | ||
| } else { | ||
| value = *((uint64_t *)(obj->Data)); | ||
| } | ||
| if (CO_IS_NODEID(obj->Key) != 0) { | ||
| value += node->NodeId; | ||
| } | ||
| if (size == COT_ENTRY_SIZE) { | ||
| *((uint64_t *)buffer) = value; | ||
| } else { | ||
| result = CO_ERR_BAD_ARG; | ||
| } | ||
| return (result); | ||
| } | ||
|
|
||
| static CO_ERR COTInt48Write(struct CO_OBJ_T *obj, struct CO_NODE_T *node, void *buffer, uint32_t size) | ||
| { | ||
| CO_ERR result = CO_ERR_NONE; | ||
| uint64_t value; | ||
| uint64_t oldValue; | ||
|
|
||
| CO_UNUSED(node); | ||
| ASSERT_PTR_ERR(obj, CO_ERR_BAD_ARG); | ||
| ASSERT_PTR_ERR(buffer, CO_ERR_BAD_ARG); | ||
|
|
||
| value = *((uint64_t *)buffer); | ||
giuliobenetti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (size == COT_ENTRY_SIZE) { | ||
| if (CO_IS_NODEID(obj->Key) != 0) { | ||
| value -= node->NodeId; | ||
| } | ||
| if (CO_IS_DIRECT(obj->Key) != 0) { | ||
| return CO_ERR_OBJ_WRITE; | ||
| } else { | ||
| oldValue = *((uint64_t *)(obj->Data)); | ||
| *((uint64_t *)(obj->Data)) = value; | ||
| } | ||
| if ((CO_IS_ASYNC(obj->Key) != 0 ) && | ||
| (CO_IS_PDOMAP(obj->Key) != 0 ) && | ||
| (oldValue != value)) { | ||
| COTPdoTrigObj(node->TPdo, obj); | ||
| } | ||
| } else { | ||
| result = CO_ERR_BAD_ARG; | ||
| } | ||
| return (result); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /****************************************************************************** | ||
| Copyright 2020 Embedded Office GmbH & Co. KG | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| ******************************************************************************/ | ||
|
|
||
| #ifndef CO_INTEGER48_H_ | ||
| #define CO_INTEGER48_H_ | ||
|
|
||
| #ifdef __cplusplus /* for compatibility with C++ environments */ | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /****************************************************************************** | ||
| * INCLUDES | ||
| ******************************************************************************/ | ||
|
|
||
| #include "co_types.h" | ||
| #include "co_err.h" | ||
| #include "co_obj.h" | ||
|
|
||
| /****************************************************************************** | ||
| * DEFINES | ||
| ******************************************************************************/ | ||
|
|
||
| #define CO_TUNSIGNED48 ((const CO_OBJ_TYPE *)&COTInt48) | ||
| #define CO_TSIGNED48 ((const CO_OBJ_TYPE *)&COTInt48) | ||
|
|
||
| /****************************************************************************** | ||
| * PUBLIC CONSTANTS | ||
| ******************************************************************************/ | ||
|
|
||
| /*! \brief OBJECT TYPE SIGNED48 / UNSIGNED48 | ||
| * | ||
| * This type is a basic type for 48bit values, regardless of signed or | ||
| * unsigned usage. | ||
| */ | ||
| extern const CO_OBJ_TYPE COTInt48; | ||
|
|
||
| #ifdef __cplusplus /* for compatibility with C++ environments */ | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* #ifndef CO_INTEGER48_H_ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.