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)
95 Buffer *mBuf /* message buffer */
98 PUBLIC S16 SPkS8(val, mBuf)
100 Buffer *mBuf; /* message buffer */
103 S16 ret; /* return code */
105 ret = SAddPreMsg((Data) val, mBuf);
106 #if (ERRCLASS & ERRCLS_ADD_RES)
108 SSLOGERROR(ERRCLS_ADD_RES, ESS242, (ErrVal)ret, "SAddPreMsg() failed");
119 * Desc: This function packs an unsigned 8 bit value into a message.
122 * RFAILED - failed, general (optional)
123 * ROUTRES - failed, out of resources (optional)
135 Buffer *mBuf /* message buffer */
138 PUBLIC S16 SPkU8(val, mBuf)
140 Buffer *mBuf; /* message buffer */
143 S16 ret; /* return code */
145 ret = SAddPreMsg((Data) val, mBuf);
146 #if (ERRCLASS & ERRCLS_ADD_RES)
148 SSLOGERROR(ERRCLS_ADD_RES, ESS243, (ErrVal)ret, "SAddPreMsg() failed");
157 * Desc: This function packs a signed 16 bit value into a message.
160 * RFAILED - failed, general (optional)
161 * ROUTRES - failed, out of resources (optional)
173 Buffer *mBuf /* message buffer */
176 PUBLIC S16 SPkS16(val, mBuf)
178 Buffer *mBuf; /* message buffer */
181 Data pkArray[2]; /* array for packing */
182 S16 ret; /* return code */
185 #ifndef FCSPKINT /* backward compatibility, packing order */
186 pkArray[0] = (Data) GetHiByte(val);
187 pkArray[1] = (Data) GetLoByte(val);
188 #else /* forward compatibility, packing order */
189 pkArray[1] = (Data) GetHiByte(val);
190 pkArray[0] = (Data) GetLoByte(val);
192 ret = SAddPreMsgMult(pkArray, (MsgLen) 2, mBuf);
193 #if (ERRCLASS & ERRCLS_ADD_RES)
195 SSLOGERROR(ERRCLS_ADD_RES, ESS244, (ErrVal)ret, "SAddPreMsgMult() failed");
198 } /* end of SPkS16 */
205 * Desc: This function packs an unsigned 16 bit value into a message.
208 * RFAILED - failed, general (optional)
209 * ROUTRES - failed, out of resources (optional)
221 Buffer *mBuf /* message buffer */
224 PUBLIC S16 SPkU16(val, mBuf)
226 Buffer *mBuf; /* message buffer */
229 Data pkArray[2]; /* array for packing */
230 S16 ret; /* return code */
233 #ifndef FCSPKINT /* backward compatibility, packing order */
234 pkArray[0] = (Data) GetHiByte(val);
235 pkArray[1] = (Data) GetLoByte(val);
236 #else /* forward compatibility, packing order */
237 pkArray[1] = (Data) GetHiByte(val);
238 pkArray[0] = (Data) GetLoByte(val);
240 ret = SAddPreMsgMult(pkArray, (MsgLen) 2, mBuf);
241 #if (ERRCLASS & ERRCLS_ADD_RES)
243 SSLOGERROR(ERRCLS_ADD_RES, ESS245, (ErrVal)ret, "SAddPreMsgMult() failed");
246 } /* end of SPkU16 */
253 * Desc: This function packs a signed 32 bit value into a message.
256 * RFAILED - failed, general (optional)
257 * ROUTRES - failed, out of resources (optional)
269 Buffer *mBuf /* message buffer */
272 PUBLIC S16 SPkS32(val, mBuf)
274 Buffer *mBuf; /* message buffer */
277 U16 tmp; /* temporary value */
278 Data pkArray[4]; /* packing array */
279 S16 ret; /* return code */
282 #ifndef FCSPKINT /* backward compatibility, packing order */
283 tmp = (U16) GetHiWord(val);
284 pkArray[0] = (Data) GetHiByte(tmp);
285 pkArray[1] = (Data) GetLoByte(tmp);
286 tmp = (U16) GetLoWord(val);
287 pkArray[2] = (Data) GetHiByte(tmp);
288 pkArray[3] = (Data) GetLoByte(tmp);
289 #else /* forward compatibility, packing order */
290 tmp = (U16) GetHiWord(val);
291 pkArray[3] = (Data) GetHiByte(tmp);
292 pkArray[2] = (Data) GetLoByte(tmp);
293 tmp = (U16) GetLoWord(val);
294 pkArray[1] = (Data) GetHiByte(tmp);
295 pkArray[0] = (Data) GetLoByte(tmp);
297 ret = SAddPreMsgMult(pkArray, (MsgLen) 4, mBuf);
298 #if (ERRCLASS & ERRCLS_ADD_RES)
300 SSLOGERROR(ERRCLS_ADD_RES, ESS246, (ErrVal)ret, "SAddPreMsgMult() failed");
303 } /* end of SPkS32 */
310 * Desc: This function packs an unsigned 32 bit value into a message.
313 * RFAILED - failed, general (optional)
314 * ROUTRES - failed, out of resources (optional)
326 Buffer *mBuf /* message buffer */
329 PUBLIC S16 SPkU32(val, mBuf)
331 Buffer *mBuf; /* message buffer */
334 U16 tmp; /* temporary value */
335 Data pkArray[4]; /* packing array */
336 S16 ret; /* return code */
339 #ifndef FCSPKINT /* backward compatibility, packing order */
340 tmp = (U16) GetHiWord(val);
341 pkArray[0] = (Data) GetHiByte(tmp);
342 pkArray[1] = (Data) GetLoByte(tmp);
343 tmp = (U16) GetLoWord(val);
344 pkArray[2] = (Data) GetHiByte(tmp);
345 pkArray[3] = (Data) GetLoByte(tmp);
346 #else /* forward compatibility, packing order */
347 tmp = (U16) GetHiWord(val);
348 pkArray[3] = (Data) GetHiByte(tmp);
349 pkArray[2] = (Data) GetLoByte(tmp);
350 tmp = (U16) GetLoWord(val);
351 pkArray[1] = (Data) GetHiByte(tmp);
352 pkArray[0] = (Data) GetLoByte(tmp);
354 ret = SAddPreMsgMult(pkArray, (MsgLen) 4, mBuf);
355 #if (ERRCLASS & ERRCLS_ADD_RES)
357 SSLOGERROR(ERRCLS_ADD_RES, ESS247, (ErrVal)ret, "SAddPreMsgMult() failed");
360 } /* end of SPkU32 */
362 /*ss038.103 1. Added Floating point support*/
368 * Desc: This function packs an 32 bit ieee-754 format float value into a message.
371 * RFAILED - failed, general (optional)
372 * ROUTRES - failed, out of resources (optional)
384 Buffer *mBuf /* message buffer */
387 PUBLIC S16 SPkF32(val, mBuf)
389 Buffer *mBuf; /* message buffer */
392 S16 ret; /* return code */
393 S8 tmpArray[15]; /* temporary array */
394 #ifdef FCSPKINT /* backward compatibility, packing order */
395 S32 tIdx = 14; /* counters */
396 S32 kIdx = 0; /* counters */
397 S8 pkArray[15]; /* packing array */
402 sprintf(tmpArray, "%.7e", val);
404 #ifndef FCSPKINT /* backward compatibility, packing order */
405 ret = SAddPreMsgMult((Data*)tmpArray, (MsgLen) 15, mBuf);
409 pkArray[kIdx] = tmpArray[tIdx];
412 ret = SAddPreMsgMult((Data*)pkArray, (MsgLen) 15, mBuf);
416 #if (ERRCLASS & ERRCLS_ADD_RES)
418 SSLOGERROR(ERRCLS_ADD_RES, ESS248, (ErrVal)ret, "SAddPreMsgMult() failed");
421 } /* end of SPkF32 */
427 * Desc: This function packs an 64 bit ieee-754 format float value into a message.
430 * RFAILED - failed, general (optional)
431 * ROUTRES - failed, out of resources (optional)
443 Buffer *mBuf /* message buffer */
446 PUBLIC S16 SPkF64(val, mBuf)
448 Buffer *mBuf; /* message buffer */
452 S16 ret; /* return code */
453 S8 tmpArray[25]; /* temporary array */
454 #ifdef FCSPKINT /* backward compatibility, packing order */
455 S32 tIdx = 24; /* counters */
456 S32 kIdx = 0; /* counters */
457 S8 pkArray[25]; /* packing array */
462 sprintf(tmpArray, "%.16le", val);
464 #ifndef FCSPKINT /* backward compatibility, packing order */
465 ret = SAddPreMsgMult((Data*)tmpArray, (MsgLen) 25, mBuf);
469 pkArray[kIdx] = tmpArray[tIdx];
472 ret = SAddPreMsgMult((Data*)pkArray, (MsgLen) 25, mBuf);
476 #if (ERRCLASS & ERRCLS_ADD_RES)
478 SSLOGERROR(ERRCLS_ADD_RES, ESS249, (ErrVal)ret, "SAddPreMsgMult() failed");
482 } /* end of SPkF64 */
483 #endif /* SS_FLOAT */
489 * Desc: This function unpacks a signed 8 bit value from a message.
502 S8 *val, /* pointer to value */
503 Buffer *mBuf /* message buffer */
506 PUBLIC S16 SUnpkS8(val, mBuf)
507 S8 *val; /* pointer to value */
508 Buffer *mBuf; /* message buffer */
511 Data tmp; /* temporary value */
512 S16 ret; /* return code */
515 /* ss021.103 - Addition of data pointer check */
516 #if (ERRCLASS & ERRCLS_INT_PAR)
517 /* check data pointer */
520 SSLOGERROR(ERRCLS_INT_PAR, ESS250, ERRZERO, "SUnpkS8 : Null value");
523 #endif /* ERRCLASS & ERRCLS_INT_PAR */
525 ret = SRemPreMsg(&tmp, mBuf);
526 #if (ERRCLASS & ERRCLS_DEBUG)
528 SSLOGERROR(ERRCLS_DEBUG, ESS251, (ErrVal)ret, "SRemPreMsg() failed");
532 } /* end of SUnpkS8 */
539 * Desc: This function unpacks an unsigned 8 bit value from a message.
552 U8 *val, /* pointer to value */
553 Buffer *mBuf /* message buffer */
556 PUBLIC S16 SUnpkU8(val, mBuf)
557 U8 *val; /* pointer to value */
558 Buffer *mBuf; /* message buffer */
561 Data tmp; /* temporary value */
562 S16 ret; /* return code */
565 /* ss021.103 - Addition of data pointer check */
566 #if (ERRCLASS & ERRCLS_INT_PAR)
567 /* check data pointer */
570 SSLOGERROR(ERRCLS_INT_PAR, ESS252, ERRZERO, "SUnpkU8 : Null value");
573 #endif /* ERRCLASS & ERRCLS_INT_PAR */
575 ret = SRemPreMsg(&tmp, mBuf);
576 #if (ERRCLASS & ERRCLS_DEBUG)
578 SSLOGERROR(ERRCLS_DEBUG, ESS253, (ErrVal)ret, "SRemPreMsg() failed");
582 } /* end of SUnpkU8 */
588 * Desc: This function unpacks a signed 16 bit value from a message.
601 S16 *val, /* pointer to value */
602 Buffer *mBuf /* message buffer */
605 PUBLIC S16 SUnpkS16(val, mBuf)
606 S16 *val; /* pointer to value */
607 Buffer *mBuf; /* message buffer */
610 U16 tmp16; /* temporary value */
611 Data unpkArray[2]; /* unpacking array */
612 S16 ret; /* return code */
615 /* ss021.103 - Addition of data pointer check */
616 #if (ERRCLASS & ERRCLS_INT_PAR)
617 /* check data pointer */
620 SSLOGERROR(ERRCLS_INT_PAR, ESS254, ERRZERO, "SUnpkS16 : Null value");
623 #endif /* ERRCLASS & ERRCLS_INT_PAR */
625 ret = SRemPreMsgMult(unpkArray, (MsgLen) 2, mBuf);
626 #if (ERRCLASS & ERRCLS_DEBUG)
628 SSLOGERROR(ERRCLS_DEBUG, ESS255, (ErrVal)ret, "SRemPreMsgMult() failed");
631 #ifndef FCSPKINT /* backward compatibility, packing order */
632 tmp16 = (U16) PutHiByte(tmp16, (U8) unpkArray[1]);
633 tmp16 = (U16) PutLoByte(tmp16, (U8) unpkArray[0]);
634 #else /* forward compatibility, packing order */
635 tmp16 = (U16) PutHiByte(tmp16, (U8) unpkArray[0]);
636 tmp16 = (U16) PutLoByte(tmp16, (U8) unpkArray[1]);
640 } /* end of SUnpkS16 */
647 * Desc: This function unpacks an unsigned 16 bit value from a message.
660 U16 *val, /* pointer to value */
661 Buffer *mBuf /* message buffer */
664 PUBLIC S16 SUnpkU16(val, mBuf)
665 U16 *val; /* pointer to value */
666 Buffer *mBuf; /* message buffer */
669 U16 tmp16; /* temporary value */
670 Data unpkArray[2]; /* unpacking array */
671 S16 ret; /* return code */
674 /* ss021.103 - Addition of data pointer check */
675 #if (ERRCLASS & ERRCLS_INT_PAR)
676 /* check data pointer */
679 SSLOGERROR(ERRCLS_INT_PAR, ESS256, ERRZERO, "SUnpkU16 : Null value");
682 #endif /* ERRCLASS & ERRCLS_INT_PAR */
684 ret = SRemPreMsgMult(unpkArray, (MsgLen) 2, mBuf);
685 #if (ERRCLASS & ERRCLS_DEBUG)
687 SSLOGERROR(ERRCLS_DEBUG, ESS257, (ErrVal)ret, "SRemPreMsgMult failed");
690 #ifndef FCSPKINT /* backward compatibility, packing order */
691 tmp16 = (U16) PutHiByte(tmp16, (U8) unpkArray[1]);
692 tmp16 = (U16) PutLoByte(tmp16, (U8) unpkArray[0]);
693 #else /* forward compatibility, packing order */
694 tmp16 = (U16) PutHiByte(tmp16, (U8) unpkArray[0]);
695 tmp16 = (U16) PutLoByte(tmp16, (U8) unpkArray[1]);
699 } /* end of SUnpkU16 */
706 * Desc: This function unpacks a signed 32 bit value from a message.
719 S32 *val, /* pointer to value */
720 Buffer *mBuf /* message buffer */
723 PUBLIC S16 SUnpkS32(val, mBuf)
724 S32 *val; /* pointer to value */
725 Buffer *mBuf; /* message buffer */
728 U16 tmp16; /* temporary value */
729 U32 tmp32; /* temporary value */
730 Data unpkArray[4]; /* unpacking array */
731 S16 ret; /* return code */
734 /* ss021.103 - Addition of data pointer check */
735 #if (ERRCLASS & ERRCLS_INT_PAR)
736 /* check data pointer */
739 SSLOGERROR(ERRCLS_INT_PAR, ESS258, ERRZERO, "SUnpkS32 : Null value");
742 #endif /* ERRCLASS & ERRCLS_INT_PAR */
744 ret = SRemPreMsgMult(unpkArray, (MsgLen) 4, mBuf);
745 #if (ERRCLASS & ERRCLS_DEBUG)
747 SSLOGERROR(ERRCLS_DEBUG, ESS259, (ErrVal)ret, "SRemPreMsgMult() failed");
751 #ifndef FCSPKINT /* backward compatibility, packing order */
752 tmp16 = (U16) PutHiByte(tmp16, (U8) unpkArray[3]);
753 tmp16 = (U16) PutLoByte(tmp16, (U8) unpkArray[2]);
754 tmp32 = (U32) PutHiWord(tmp32, (U16) tmp16);
755 tmp16 = (U16) PutHiByte(tmp16, (U8) unpkArray[1]);
756 tmp16 = (U16) PutLoByte(tmp16, (U8) unpkArray[0]);
757 tmp32 = (U32) PutLoWord(tmp32, (U16) tmp16);
758 #else /* forward compatibility, packing order */
759 tmp16 = (U16) PutHiByte(tmp16, (U8) unpkArray[0]);
760 tmp16 = (U16) PutLoByte(tmp16, (U8) unpkArray[1]);
761 tmp32 = (U32) PutHiWord(tmp32, (U16) tmp16);
762 tmp16 = (U16) PutHiByte(tmp16, (U8) unpkArray[2]);
763 tmp16 = (U16) PutLoByte(tmp16, (U8) unpkArray[3]);
764 tmp32 = (U32) PutLoWord(tmp32, (U16) tmp16);
768 } /* end of SUnpkS32 */
775 * Desc: This function unpacks an unsigned 32 bit value from a message.
788 U32 *val, /* pointer to value */
789 Buffer *mBuf /* message buffer */
792 PUBLIC S16 SUnpkU32(val, mBuf)
793 U32 *val; /* pointer to value */
794 Buffer *mBuf; /* message buffer */
797 U16 tmp16; /* temporary value */
798 U32 tmp32; /* temporary value */
799 Data unpkArray[4]; /* unpacking array */
801 S16 ret; /* return code */
802 #endif /* ERRCLASS */
805 /* ss021.103 - Addition of data pointer check */
806 #if (ERRCLASS & ERRCLS_INT_PAR)
807 /* check data pointer */
810 SSLOGERROR(ERRCLS_INT_PAR, ESS260, ERRZERO, "SUnpkU32 : Null value");
813 #endif /* ERRCLASS & ERRCLS_INT_PAR */
815 ret = SRemPreMsgMult(unpkArray, (MsgLen) 4, mBuf);
816 #if (ERRCLASS & ERRCLS_DEBUG)
818 SSLOGERROR(ERRCLS_DEBUG, ESS261, (ErrVal)ret, "SRemPreMsgMult() failed");
823 #ifndef FCSPKINT /* backward compatibility, packing order */
824 tmp16 = (U16) PutHiByte(tmp16, (U8) unpkArray[3]);
825 tmp16 = (U16) PutLoByte(tmp16, (U8) unpkArray[2]);
826 tmp32 = (U32) PutHiWord(tmp32, (U16) tmp16);
827 tmp16 = (U16) PutHiByte(tmp16, (U8) unpkArray[1]);
828 tmp16 = (U16) PutLoByte(tmp16, (U8) unpkArray[0]);
829 tmp32 = (U32) PutLoWord(tmp32, (U16) tmp16);
830 #else /* forward compatibility, packing order */
831 tmp16 = (U16) PutHiByte(tmp16, (U8) unpkArray[0]);
832 tmp16 = (U16) PutLoByte(tmp16, (U8) unpkArray[1]);
833 tmp32 = (U32) PutHiWord(tmp32, (U16) tmp16);
834 tmp16 = (U16) PutHiByte(tmp16, (U8) unpkArray[2]);
835 tmp16 = (U16) PutLoByte(tmp16, (U8) unpkArray[3]);
836 tmp32 = (U32) PutLoWord(tmp32, (U16) tmp16);
840 } /* end of SUnpkU32 */
842 /*ss038.103 1. Added Floating point support*/
848 * Desc: This function unpacks an 32 bit ieee-754 format float value from a message.
861 F32 *val, /* pointer to value */
862 Buffer *mBuf /* message buffer */
865 PUBLIC S16 SUnpkF32(val, mBuf)
866 F32 *val; /* pointer to value */
867 Buffer *mBuf; /* message buffer */
870 S16 ret; /* return code */
871 S8 tmpArray[15]; /* temporary array */
872 #ifndef FCSPKINT /* backward compatibility, packing order */
873 S32 tIdx = 14; /* temparory array index */
874 S32 kIdx = 0; /* unpacking array index */
875 S8 unpkArray[15]; /* unpacking array */
876 #endif /* FCSPKINT */
880 #if (ERRCLASS & ERRCLS_INT_PAR)
881 /* check data pointer */
884 SSLOGERROR(ERRCLS_INT_PAR, ESS262, ERRZERO, "SUnpkF32 : Null value");
887 #endif /* ERRCLASS & ERRCLS_INT_PAR */
889 ret = SRemPreMsgMult((Data*)tmpArray, (MsgLen) 15, mBuf);
890 #if (ERRCLASS & ERRCLS_DEBUG)
892 SSLOGERROR(ERRCLS_DEBUG, ESS263, (ErrVal)ret, "SRemPreMsgMult() failed");
895 #ifndef FCSPKINT /* backward compatibility, packing order */
898 unpkArray[kIdx] = tmpArray[tIdx];
901 sscanf(unpkArray, "%f", val);
903 sscanf(tmpArray, "%f", val);
908 } /* end of SUnpkF32 */
914 * Desc: This function unpacks an 64 bit ieee-754 format float value from a message.
927 F64 *val, /* pointer to value */
928 Buffer *mBuf /* message buffer */
931 PUBLIC S16 SUnpkF64(val, mBuf)
932 F64 *val; /* pointer to value */
933 Buffer *mBuf; /* message buffer */
937 S16 ret; /* return code */
938 S8 tmpArray[25]; /* temporary array */
939 #ifndef FCSPKINT /* backward compatibility, packing order */
940 S32 tIdx = 24; /* temparory array index */
941 S32 kIdx = 0; /* unpacking array index */
942 S8 unpkArray[25]; /* unpacking array */
943 #endif /* FCSPKINT */
947 #if (ERRCLASS & ERRCLS_INT_PAR)
948 /* check data pointer */
951 SSLOGERROR(ERRCLS_INT_PAR, ESS264, ERRZERO, "SUnpkF64 : Null value");
954 #endif /* ERRCLASS & ERRCLS_INT_PAR */
956 ret = SRemPreMsgMult((Data*)tmpArray, (MsgLen) 25, mBuf);
957 #if (ERRCLASS & ERRCLS_DEBUG)
959 SSLOGERROR(ERRCLS_DEBUG, ESS265, (ErrVal)ret, "SRemPreMsgMult() failed");
962 #ifndef FCSPKINT /* backward compatibility, packing order */
965 unpkArray[kIdx] = tmpArray[tIdx];
968 sscanf(unpkArray, "%lf", val);
970 sscanf(tmpArray, "%lf", val);
975 } /* end of SUnpkF64 */
976 #endif /* SS_FLOAT */
978 /**********************************************************************
980 **********************************************************************/