Skip to content

Commit

Permalink
Support access to integers of size not a power of two
Browse files Browse the repository at this point in the history
Data types such as UNSIGNED48 was not supported, except via the access
function with the previous commit. Add all the non-power-of-two variants
of UNSIGNED and INTEGER to the OD get/set functions.

Note that defining an array of these objects using OD_ARRAY is broken,
because it produces unaligned accesses, that even if they may be
supported by the platform, will not necessarily be atomic.

Signed-off-by: Andreas Fritiofson <[email protected]>
Change-Id: Id7ee68cc50921b9b6705e95a5867b7f99eb319be
  • Loading branch information
Andreas Fritiofson committed Sep 10, 2021
1 parent 9c73a28 commit 0db3d15
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/co_od.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,32 @@ uint32_t co_od_get_value (
*value = co_atomic_get_uint16 (data);
break;

case DTYPE_UNSIGNED24:
case DTYPE_INTEGER24:
*value = co_atomic_get_uint32 (data) & 0xFFFFFF;
break;

case DTYPE_REAL32:
case DTYPE_UNSIGNED32:
case DTYPE_INTEGER32:
*value = co_atomic_get_uint32 (data);
break;

case DTYPE_UNSIGNED40:
case DTYPE_INTEGER40:
*value = co_atomic_get_uint64 (data) & 0xFFFFFFFFFF;
break;

case DTYPE_UNSIGNED48:
case DTYPE_INTEGER48:
*value = co_atomic_get_uint64 (data) & 0xFFFFFFFFFFFF;
break;

case DTYPE_UNSIGNED56:
case DTYPE_INTEGER56:
*value = co_atomic_get_uint64 (data) & 0xFFFFFFFFFFFFFF;
break;

case DTYPE_REAL64:
case DTYPE_UNSIGNED64:
case DTYPE_INTEGER64:
Expand Down Expand Up @@ -243,12 +263,32 @@ uint32_t co_od_set_value (
co_atomic_set_uint16 (data, value & UINT16_MAX);
break;

case DTYPE_UNSIGNED24:
case DTYPE_INTEGER24:
co_atomic_set_uint32 (data, value & 0xFFFFFF);
break;

case DTYPE_REAL32:
case DTYPE_UNSIGNED32:
case DTYPE_INTEGER32:
co_atomic_set_uint32 (data, value & UINT32_MAX);
break;

case DTYPE_UNSIGNED40:
case DTYPE_INTEGER40:
co_atomic_set_uint64 (data, value & 0xFFFFFFFFFF);
break;

case DTYPE_UNSIGNED48:
case DTYPE_INTEGER48:
co_atomic_set_uint64 (data, value & 0xFFFFFFFFFFFF);
break;

case DTYPE_UNSIGNED56:
case DTYPE_INTEGER56:
co_atomic_set_uint64 (data, value & 0xFFFFFFFFFFFFFF);
break;

case DTYPE_REAL64:
case DTYPE_UNSIGNED64:
case DTYPE_INTEGER64:
Expand Down

0 comments on commit 0db3d15

Please sign in to comment.