1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /********************************************************************20**
21 Name: System Services -- packing
25 Desc: Source code for System Services packing functions.
29 *********************************************************************21*/
32 /* header include files (.h) */
34 #include "envopt.h" /* environment options */
35 #include "envdep.h" /* environment dependent */
36 #include "envind.h" /* environment independent */
38 #include "gen.h" /* general layer */
39 #include "ssi.h" /* system services */
41 #include "ss_err.h" /* errors */
42 #include "ss_dep.h" /* implementation-specific */
43 #include "ss_queue.h" /* queues */
44 #include "ss_msg.h" /* messaging */
45 #include "ss_mem.h" /* memory management interface */
46 #include "ss_gen.h" /* general */
47 #include "cm_mem.h" /* memory management */
51 /* header/extern include files (.x) */
53 #include "gen.x" /* general layer */
54 #include "ssi.x" /* system services */
56 #include "ss_dep.x" /* implementation-specific */
57 #include "ss_queue.x" /* queues */
58 #include "ss_task.x" /* tasking */
59 #include "ss_timer.x" /* timers */
60 #include "ss_strm.x" /* STREAMS */
61 #include "ss_msg.x" /* messaging */
62 #include "ss_mem.x" /* memory management interface */
63 #include "ss_drvr.x" /* driver tasks */
64 #ifdef SS_LOCKLESS_MEMORY
67 #include "cm_mem_wl.x" /* common memory manager */
69 #include "cm_mem.x" /* common memory manager */
70 #endif /* SS_LOCKLESS_MEMORY */
71 #include "ss_gen.x" /* general */
79 * Desc: This function packs a signed 8 bit value into a message.
82 * RFAILED - failed, general (optional)
83 * ROUTRES - failed, out of resources (optional)
94 Buffer *mBuf /* message buffer */
97 S16 ret; /* return code */
98 ret = SAddPreMsg((Data) val, mBuf);
99 #if (ERRCLASS & ERRCLS_ADD_RES)
101 SSLOGERROR(ERRCLS_ADD_RES, ESS242, (ErrVal)ret, "SAddPreMsg() failed");
110 * Fun: oduUnpackUInt8
112 * Desc: This function packs an unsigned 8 bit value into a message.
115 * RFAILED - failed, general (optional)
116 * ROUTRES - failed, out of resources (optional)
126 uint8_t val, /* value */
127 Buffer *mBuf /* message buffer */
130 S16 ret; /* return code */
131 ret = SAddPreMsg((Data) val, mBuf);
132 #if (ERRCLASS & ERRCLS_ADD_RES)
134 SSLOGERROR(ERRCLS_ADD_RES, ESS243, (ErrVal)ret, "SAddPreMsg() failed");
137 } /* end of oduUnpackUInt8 */
143 * Desc: This function packs a signed 16 bit value into a message.
146 * RFAILED - failed, general (optional)
147 * ROUTRES - failed, out of resources (optional)
158 Buffer *mBuf /* message buffer */
161 Data pkArray[2]; /* array for packing */
162 S16 ret; /* return code */
164 #ifndef FCSPKINT /* backward compatibility, packing order */
165 pkArray[0] = (Data) GetHiByte(val);
166 pkArray[1] = (Data) GetLoByte(val);
167 #else /* forward compatibility, packing order */
168 pkArray[1] = (Data) GetHiByte(val);
169 pkArray[0] = (Data) GetLoByte(val);
171 ret = SAddPreMsgMult(pkArray, (MsgLen) 2, mBuf);
172 #if (ERRCLASS & ERRCLS_ADD_RES)
174 SSLOGERROR(ERRCLS_ADD_RES, ESS244, (ErrVal)ret, "SAddPreMsgMult() failed");
177 } /* end of SPkS16 */
182 * Fun: oduUnpackUInt16
184 * Desc: This function packs an unsigned 16 bit value into a message.
187 * RFAILED - failed, general (optional)
188 * ROUTRES - failed, out of resources (optional)
198 uint16_t val, /* value */
199 Buffer *mBuf /* message buffer */
202 Data pkArray[2]; /* array for packing */
203 S16 ret; /* return code */
205 #ifndef FCSPKINT /* backward compatibility, packing order */
206 pkArray[0] = (Data) GetHiByte(val);
207 pkArray[1] = (Data) GetLoByte(val);
208 #else /* forward compatibility, packing order */
209 pkArray[1] = (Data) GetHiByte(val);
210 pkArray[0] = (Data) GetLoByte(val);
212 ret = SAddPreMsgMult(pkArray, (MsgLen) 2, mBuf);
213 #if (ERRCLASS & ERRCLS_ADD_RES)
215 SSLOGERROR(ERRCLS_ADD_RES, ESS245, (ErrVal)ret, "SAddPreMsgMult() failed");
218 } /* end of oduUnpackUInt16 */
225 * Desc: This function packs a signed 32 bit value into a message.
228 * RFAILED - failed, general (optional)
229 * ROUTRES - failed, out of resources (optional)
240 Buffer *mBuf /* message buffer */
243 uint16_t tmp; /* temporary value */
244 Data pkArray[4]; /* packing array */
245 S16 ret; /* return code */
247 #ifndef FCSPKINT /* backward compatibility, packing order */
248 tmp = (uint16_t) GetHiWord(val);
249 pkArray[0] = (Data) GetHiByte(tmp);
250 pkArray[1] = (Data) GetLoByte(tmp);
251 tmp = (uint16_t) GetLoWord(val);
252 pkArray[2] = (Data) GetHiByte(tmp);
253 pkArray[3] = (Data) GetLoByte(tmp);
254 #else /* forward compatibility, packing order */
255 tmp = (uint16_t) GetHiWord(val);
256 pkArray[3] = (Data) GetHiByte(tmp);
257 pkArray[2] = (Data) GetLoByte(tmp);
258 tmp = (uint16_t) GetLoWord(val);
259 pkArray[1] = (Data) GetHiByte(tmp);
260 pkArray[0] = (Data) GetLoByte(tmp);
262 ret = SAddPreMsgMult(pkArray, (MsgLen) 4, mBuf);
263 #if (ERRCLASS & ERRCLS_ADD_RES)
265 SSLOGERROR(ERRCLS_ADD_RES, ESS246, (ErrVal)ret, "SAddPreMsgMult() failed");
268 } /* end of SPkS32 */
273 * Fun: oduUnpackUInt32
275 * Desc: This function packs an unsigned 32 bit value into a message.
278 * RFAILED - failed, general (optional)
279 * ROUTRES - failed, out of resources (optional)
289 uint32_t val, /* value */
290 Buffer *mBuf /* message buffer */
293 uint16_t tmp; /* temporary value */
294 Data pkArray[4]; /* packing array */
295 S16 ret; /* return code */
297 #ifndef FCSPKINT /* backward compatibility, packing order */
298 tmp = (uint16_t) GetHiWord(val);
299 pkArray[0] = (Data) GetHiByte(tmp);
300 pkArray[1] = (Data) GetLoByte(tmp);
301 tmp = (uint16_t) GetLoWord(val);
302 pkArray[2] = (Data) GetHiByte(tmp);
303 pkArray[3] = (Data) GetLoByte(tmp);
304 #else /* forward compatibility, packing order */
305 tmp = (uint16_t) GetHiWord(val);
306 pkArray[3] = (Data) GetHiByte(tmp);
307 pkArray[2] = (Data) GetLoByte(tmp);
308 tmp = (uint16_t) GetLoWord(val);
309 pkArray[1] = (Data) GetHiByte(tmp);
310 pkArray[0] = (Data) GetLoByte(tmp);
312 ret = SAddPreMsgMult(pkArray, (MsgLen) 4, mBuf);
313 #if (ERRCLASS & ERRCLS_ADD_RES)
315 SSLOGERROR(ERRCLS_ADD_RES, ESS247, (ErrVal)ret, "SAddPreMsgMult() failed");
318 } /* end of oduUnpackUInt32 */
320 /*ss038.103 1. Added Floating point support*/
326 * Desc: This function packs an 32 bit ieee-754 format float value into a message.
329 * RFAILED - failed, general (optional)
330 * ROUTRES - failed, out of resources (optional)
341 Buffer *mBuf /* message buffer */
344 S16 ret; /* return code */
345 S8 tmpArray[15]; /* temporary array */
346 #ifdef FCSPKINT /* backward compatibility, packing order */
347 S32 tIdx = 14; /* counters */
348 S32 kIdx = 0; /* counters */
349 S8 pkArray[15]; /* packing array */
352 sprintf(tmpArray, "%.7e", val);
354 #ifndef FCSPKINT /* backward compatibility, packing order */
355 ret = SAddPreMsgMult((Data*)tmpArray, (MsgLen) 15, mBuf);
359 pkArray[kIdx] = tmpArray[tIdx];
362 ret = SAddPreMsgMult((Data*)pkArray, (MsgLen) 15, mBuf);
366 #if (ERRCLASS & ERRCLS_ADD_RES)
368 SSLOGERROR(ERRCLS_ADD_RES, ESS248, (ErrVal)ret, "SAddPreMsgMult() failed");
371 } /* end of SPkF32 */
377 * Desc: This function packs an 64 bit ieee-754 format float value into a message.
380 * RFAILED - failed, general (optional)
381 * ROUTRES - failed, out of resources (optional)
392 Buffer *mBuf /* message buffer */
396 S16 ret; /* return code */
397 S8 tmpArray[25]; /* temporary array */
398 #ifdef FCSPKINT /* backward compatibility, packing order */
399 S32 tIdx = 24; /* counters */
400 S32 kIdx = 0; /* counters */
401 S8 pkArray[25]; /* packing array */
404 sprintf(tmpArray, "%.16le", val);
406 #ifndef FCSPKINT /* backward compatibility, packing order */
407 ret = SAddPreMsgMult((Data*)tmpArray, (MsgLen) 25, mBuf);
411 pkArray[kIdx] = tmpArray[tIdx];
414 ret = SAddPreMsgMult((Data*)pkArray, (MsgLen) 25, mBuf);
418 #if (ERRCLASS & ERRCLS_ADD_RES)
420 SSLOGERROR(ERRCLS_ADD_RES, ESS249, (ErrVal)ret, "SAddPreMsgMult() failed");
424 } /* end of SPkF64 */
425 #endif /* SS_FLOAT */
431 * Desc: This function unpacks a signed 8 bit value from a message.
443 S8 *val, /* pointer to value */
444 Buffer *mBuf /* message buffer */
447 Data tmp; /* temporary value */
448 S16 ret; /* return code */
450 /* ss021.103 - Addition of data pointer check */
451 #if (ERRCLASS & ERRCLS_INT_PAR)
452 /* check data pointer */
455 SSLOGERROR(ERRCLS_INT_PAR, ESS250, ERRZERO, "SUnpkS8 : Null value");
458 #endif /* ERRCLASS & ERRCLS_INT_PAR */
460 ret = SRemPreMsg(&tmp, mBuf);
461 #if (ERRCLASS & ERRCLS_DEBUG)
463 SSLOGERROR(ERRCLS_DEBUG, ESS251, (ErrVal)ret, "SRemPreMsg() failed");
467 } /* end of SUnpkS8 */
474 * Desc: This function unpacks an unsigned 8 bit value from a message.
486 uint8_t *val, /* pointer to value */
487 Buffer *mBuf /* message buffer */
490 Data tmp; /* temporary value */
491 S16 ret; /* return code */
493 /* ss021.103 - Addition of data pointer check */
494 #if (ERRCLASS & ERRCLS_INT_PAR)
495 /* check data pointer */
498 SSLOGERROR(ERRCLS_INT_PAR, ESS252, ERRZERO, "oduPackUInt8 : Null value");
501 #endif /* ERRCLASS & ERRCLS_INT_PAR */
503 ret = SRemPreMsg(&tmp, mBuf);
504 #if (ERRCLASS & ERRCLS_DEBUG)
506 SSLOGERROR(ERRCLS_DEBUG, ESS253, (ErrVal)ret, "SRemPreMsg() failed");
508 *val = (uint8_t) tmp;
510 } /* end of oduPackUInt8 */
516 * Desc: This function unpacks a signed 16 bit value from a message.
528 S16 *val, /* pointer to value */
529 Buffer *mBuf /* message buffer */
532 uint16_t tmp16; /* temporary value */
533 Data unpkArray[2]; /* unpacking array */
534 S16 ret; /* return code */
536 /* ss021.103 - Addition of data pointer check */
537 #if (ERRCLASS & ERRCLS_INT_PAR)
538 /* check data pointer */
541 SSLOGERROR(ERRCLS_INT_PAR, ESS254, ERRZERO, "SUnpkS16 : Null value");
544 #endif /* ERRCLASS & ERRCLS_INT_PAR */
546 ret = SRemPreMsgMult(unpkArray, (MsgLen) 2, mBuf);
547 #if (ERRCLASS & ERRCLS_DEBUG)
549 SSLOGERROR(ERRCLS_DEBUG, ESS255, (ErrVal)ret, "SRemPreMsgMult() failed");
552 #ifndef FCSPKINT /* backward compatibility, packing order */
553 tmp16 = (uint16_t) PutHiByte(tmp16, (uint8_t) unpkArray[1]);
554 tmp16 = (uint16_t) PutLoByte(tmp16, (uint8_t) unpkArray[0]);
555 #else /* forward compatibility, packing order */
556 tmp16 = (uint16_t) PutHiByte(tmp16, (uint8_t) unpkArray[0]);
557 tmp16 = (uint16_t) PutLoByte(tmp16, (uint8_t) unpkArray[1]);
561 } /* end of SUnpkS16 */
568 * Desc: This function unpacks an unsigned 16 bit value from a message.
580 uint16_t *val, /* pointer to value */
581 Buffer *mBuf /* message buffer */
584 uint16_t tmp16; /* temporary value */
585 Data unpkArray[2]; /* unpacking array */
586 S16 ret; /* return code */
588 /* ss021.103 - Addition of data pointer check */
589 #if (ERRCLASS & ERRCLS_INT_PAR)
590 /* check data pointer */
593 SSLOGERROR(ERRCLS_INT_PAR, ESS256, ERRZERO, "oduPackUInt16 : Null value");
596 #endif /* ERRCLASS & ERRCLS_INT_PAR */
598 ret = SRemPreMsgMult(unpkArray, (MsgLen) 2, mBuf);
599 #if (ERRCLASS & ERRCLS_DEBUG)
601 SSLOGERROR(ERRCLS_DEBUG, ESS257, (ErrVal)ret, "SRemPreMsgMult failed");
604 #ifndef FCSPKINT /* backward compatibility, packing order */
605 tmp16 = (uint16_t) PutHiByte(tmp16, (uint8_t) unpkArray[1]);
606 tmp16 = (uint16_t) PutLoByte(tmp16, (uint8_t) unpkArray[0]);
607 #else /* forward compatibility, packing order */
608 tmp16 = (uint16_t) PutHiByte(tmp16, (uint8_t) unpkArray[0]);
609 tmp16 = (uint16_t) PutLoByte(tmp16, (uint8_t) unpkArray[1]);
613 } /* end of oduPackUInt16 */
620 * Desc: This function unpacks a signed 32 bit value from a message.
632 S32 *val, /* pointer to value */
633 Buffer *mBuf /* message buffer */
636 uint16_t tmp16; /* temporary value */
637 uint32_t tmp32; /* temporary value */
638 Data unpkArray[4]; /* unpacking array */
639 S16 ret; /* return code */
641 /* ss021.103 - Addition of data pointer check */
642 #if (ERRCLASS & ERRCLS_INT_PAR)
643 /* check data pointer */
646 SSLOGERROR(ERRCLS_INT_PAR, ESS258, ERRZERO, "SUnpkS32 : Null value");
649 #endif /* ERRCLASS & ERRCLS_INT_PAR */
651 ret = SRemPreMsgMult(unpkArray, (MsgLen) 4, mBuf);
652 #if (ERRCLASS & ERRCLS_DEBUG)
654 SSLOGERROR(ERRCLS_DEBUG, ESS259, (ErrVal)ret, "SRemPreMsgMult() failed");
658 #ifndef FCSPKINT /* backward compatibility, packing order */
659 tmp16 = (uint16_t) PutHiByte(tmp16, (uint8_t) unpkArray[3]);
660 tmp16 = (uint16_t) PutLoByte(tmp16, (uint8_t) unpkArray[2]);
661 tmp32 = (uint32_t) PutHiWord(tmp32, (uint16_t) tmp16);
662 tmp16 = (uint16_t) PutHiByte(tmp16, (uint8_t) unpkArray[1]);
663 tmp16 = (uint16_t) PutLoByte(tmp16, (uint8_t) unpkArray[0]);
664 tmp32 = (uint32_t) PutLoWord(tmp32, (uint16_t) tmp16);
665 #else /* forward compatibility, packing order */
666 tmp16 = (uint16_t) PutHiByte(tmp16, (uint8_t) unpkArray[0]);
667 tmp16 = (uint16_t) PutLoByte(tmp16, (uint8_t) unpkArray[1]);
668 tmp32 = (uint32_t) PutHiWord(tmp32, (uint16_t) tmp16);
669 tmp16 = (uint16_t) PutHiByte(tmp16, (uint8_t) unpkArray[2]);
670 tmp16 = (uint16_t) PutLoByte(tmp16, (uint8_t) unpkArray[3]);
671 tmp32 = (uint32_t) PutLoWord(tmp32, (uint16_t) tmp16);
675 } /* end of SUnpkS32 */
682 * Desc: This function unpacks an unsigned 32 bit value from a message.
694 uint32_t *val, /* pointer to value */
695 Buffer *mBuf /* message buffer */
698 uint16_t tmp16; /* temporary value */
699 uint32_t tmp32; /* temporary value */
700 Data unpkArray[4]; /* unpacking array */
702 S16 ret; /* return code */
703 #endif /* ERRCLASS */
705 /* ss021.103 - Addition of data pointer check */
706 #if (ERRCLASS & ERRCLS_INT_PAR)
707 /* check data pointer */
710 SSLOGERROR(ERRCLS_INT_PAR, ESS260, ERRZERO, "oduPackUInt32 : Null value");
713 #endif /* ERRCLASS & ERRCLS_INT_PAR */
715 ret = SRemPreMsgMult(unpkArray, (MsgLen) 4, mBuf);
716 #if (ERRCLASS & ERRCLS_DEBUG)
718 SSLOGERROR(ERRCLS_DEBUG, ESS261, (ErrVal)ret, "SRemPreMsgMult() failed");
723 #ifndef FCSPKINT /* backward compatibility, packing order */
724 tmp16 = (uint16_t) PutHiByte(tmp16, (uint8_t) unpkArray[3]);
725 tmp16 = (uint16_t) PutLoByte(tmp16, (uint8_t) unpkArray[2]);
726 tmp32 = (uint32_t) PutHiWord(tmp32, (uint16_t) tmp16);
727 tmp16 = (uint16_t) PutHiByte(tmp16, (uint8_t) unpkArray[1]);
728 tmp16 = (uint16_t) PutLoByte(tmp16, (uint8_t) unpkArray[0]);
729 tmp32 = (uint32_t) PutLoWord(tmp32, (uint16_t) tmp16);
730 #else /* forward compatibility, packing order */
731 tmp16 = (uint16_t) PutHiByte(tmp16, (uint8_t) unpkArray[0]);
732 tmp16 = (uint16_t) PutLoByte(tmp16, (uint8_t) unpkArray[1]);
733 tmp32 = (uint32_t) PutHiWord(tmp32, (uint16_t) tmp16);
734 tmp16 = (uint16_t) PutHiByte(tmp16, (uint8_t) unpkArray[2]);
735 tmp16 = (uint16_t) PutLoByte(tmp16, (uint8_t) unpkArray[3]);
736 tmp32 = (uint32_t) PutLoWord(tmp32, (uint16_t) tmp16);
740 } /* end of oduPackUInt32 */
742 /*ss038.103 1. Added Floating point support*/
748 * Desc: This function unpacks an 32 bit ieee-754 format float value from a message.
760 F32 *val, /* pointer to value */
761 Buffer *mBuf /* message buffer */
764 S16 ret; /* return code */
765 S8 tmpArray[15]; /* temporary array */
766 #ifndef FCSPKINT /* backward compatibility, packing order */
767 S32 tIdx = 14; /* temparory array index */
768 S32 kIdx = 0; /* unpacking array index */
769 S8 unpkArray[15]; /* unpacking array */
770 #endif /* FCSPKINT */
772 #if (ERRCLASS & ERRCLS_INT_PAR)
773 /* check data pointer */
776 SSLOGERROR(ERRCLS_INT_PAR, ESS262, ERRZERO, "SUnpkF32 : Null value");
779 #endif /* ERRCLASS & ERRCLS_INT_PAR */
781 ret = SRemPreMsgMult((Data*)tmpArray, (MsgLen) 15, mBuf);
782 #if (ERRCLASS & ERRCLS_DEBUG)
784 SSLOGERROR(ERRCLS_DEBUG, ESS263, (ErrVal)ret, "SRemPreMsgMult() failed");
787 #ifndef FCSPKINT /* backward compatibility, packing order */
790 unpkArray[kIdx] = tmpArray[tIdx];
793 sscanf(unpkArray, "%f", val);
795 sscanf(tmpArray, "%f", val);
800 } /* end of SUnpkF32 */
806 * Desc: This function unpacks an 64 bit ieee-754 format float value from a message.
818 F64 *val, /* pointer to value */
819 Buffer *mBuf /* message buffer */
823 S16 ret; /* return code */
824 S8 tmpArray[25]; /* temporary array */
825 #ifndef FCSPKINT /* backward compatibility, packing order */
826 S32 tIdx = 24; /* temparory array index */
827 S32 kIdx = 0; /* unpacking array index */
828 S8 unpkArray[25]; /* unpacking array */
829 #endif /* FCSPKINT */
831 #if (ERRCLASS & ERRCLS_INT_PAR)
832 /* check data pointer */
835 SSLOGERROR(ERRCLS_INT_PAR, ESS264, ERRZERO, "SUnpkF64 : Null value");
838 #endif /* ERRCLASS & ERRCLS_INT_PAR */
840 ret = SRemPreMsgMult((Data*)tmpArray, (MsgLen) 25, mBuf);
841 #if (ERRCLASS & ERRCLS_DEBUG)
843 SSLOGERROR(ERRCLS_DEBUG, ESS265, (ErrVal)ret, "SRemPreMsgMult() failed");
846 #ifndef FCSPKINT /* backward compatibility, packing order */
849 unpkArray[kIdx] = tmpArray[tIdx];
852 sscanf(unpkArray, "%lf", val);
854 sscanf(tmpArray, "%lf", val);
859 } /* end of SUnpkF64 */
860 #endif /* SS_FLOAT */
862 /**********************************************************************
864 **********************************************************************/