Skip to content

Commit fb59d71

Browse files
committed
Support access to integers of size not a power of two
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
1 parent b5a754f commit fb59d71

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Diff for: src/co_od.c

+40
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,32 @@ uint32_t co_od_get_value (
176176
*value = co_atomic_get_uint16 (data);
177177
break;
178178

179+
case DTYPE_UNSIGNED24:
180+
case DTYPE_INTEGER24:
181+
*value = co_atomic_get_uint32 (data) & 0xFFFFFF;
182+
break;
183+
179184
case DTYPE_REAL32:
180185
case DTYPE_UNSIGNED32:
181186
case DTYPE_INTEGER32:
182187
*value = co_atomic_get_uint32 (data);
183188
break;
184189

190+
case DTYPE_UNSIGNED40:
191+
case DTYPE_INTEGER40:
192+
*value = co_atomic_get_uint64 (data) & 0xFFFFFFFFFF;
193+
break;
194+
195+
case DTYPE_UNSIGNED48:
196+
case DTYPE_INTEGER48:
197+
*value = co_atomic_get_uint64 (data) & 0xFFFFFFFFFFFF;
198+
break;
199+
200+
case DTYPE_UNSIGNED56:
201+
case DTYPE_INTEGER56:
202+
*value = co_atomic_get_uint64 (data) & 0xFFFFFFFFFFFFFF;
203+
break;
204+
185205
case DTYPE_REAL64:
186206
case DTYPE_UNSIGNED64:
187207
case DTYPE_INTEGER64:
@@ -243,12 +263,32 @@ uint32_t co_od_set_value (
243263
co_atomic_set_uint16 (data, value & UINT16_MAX);
244264
break;
245265

266+
case DTYPE_UNSIGNED24:
267+
case DTYPE_INTEGER24:
268+
co_atomic_set_uint32 (data, value & 0xFFFFFF);
269+
break;
270+
246271
case DTYPE_REAL32:
247272
case DTYPE_UNSIGNED32:
248273
case DTYPE_INTEGER32:
249274
co_atomic_set_uint32 (data, value & UINT32_MAX);
250275
break;
251276

277+
case DTYPE_UNSIGNED40:
278+
case DTYPE_INTEGER40:
279+
co_atomic_set_uint64 (data, value & 0xFFFFFFFFFF);
280+
break;
281+
282+
case DTYPE_UNSIGNED48:
283+
case DTYPE_INTEGER48:
284+
co_atomic_set_uint64 (data, value & 0xFFFFFFFFFFFF);
285+
break;
286+
287+
case DTYPE_UNSIGNED56:
288+
case DTYPE_INTEGER56:
289+
co_atomic_set_uint64 (data, value & 0xFFFFFFFFFFFFFF);
290+
break;
291+
252292
case DTYPE_REAL64:
253293
case DTYPE_UNSIGNED64:
254294
case DTYPE_INTEGER64:

0 commit comments

Comments
 (0)