blob: f41102e1ed35995700d7d0ca0409bd892485cc0e [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2005
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*****************************************************************************
37 *
38 * Filename:
39 * ---------
40 * kal_public_api.h
41 *
42 * Project:
43 * --------
44 * Maui_Software
45 *
46 * Description:
47 * ------------
48 * This file provides KAL public API prototypes
49 *
50 * Author:
51 * -------
52 * -------
53 *
54 *============================================================================
55 * HISTORY
56 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
57 *------------------------------------------------------------------------------
58 * removed!
59 * removed!
60 * removed!
61 *
62 * removed!
63 * removed!
64 * removed!
65 * removed!
66 *
67 * removed!
68 * removed!
69 * removed!
70 * removed!
71 *
72 * removed!
73 * removed!
74 * removed!
75 * removed!
76 *
77 * removed!
78 * removed!
79 * removed!
80 *
81 * removed!
82 * removed!
83 * removed!
84 * removed!
85 *
86 * removed!
87 * removed!
88 * removed!
89 *
90 * removed!
91 * removed!
92 * removed!
93 * removed!
94 *
95 * removed!
96 * removed!
97 * removed!
98 *
99 * removed!
100 * removed!
101 * removed!
102 *
103 * removed!
104 * removed!
105 * removed!
106 * removed!
107 *
108 * removed!
109 * removed!
110 * removed!
111 * removed!
112 *
113 * removed!
114 * removed!
115 * removed!
116 * removed!
117 *
118 * removed!
119 * removed!
120 * removed!
121 *
122 * removed!
123 * removed!
124 * removed!
125 * removed!
126 *
127 * removed!
128 * removed!
129 * removed!
130 * removed!
131 *
132 * removed!
133 * removed!
134 * removed!
135 *
136 * removed!
137 * removed!
138 * removed!
139 *
140 * removed!
141 * removed!
142 * removed!
143 *
144 * removed!
145 * removed!
146 * removed!
147 * removed!
148 * removed!
149 * removed!
150 * removed!
151 *
152 * removed!
153 * removed!
154 * removed!
155 *
156 * removed!
157 * removed!
158 * removed!
159 *
160 * removed!
161 * removed!
162 * removed!
163 *
164 * removed!
165 * removed!
166 * removed!
167 * removed!
168 *
169 * removed!
170 * removed!
171 * removed!
172 *
173 * removed!
174 * removed!
175 * removed!
176 * removed!
177 *
178 * removed!
179 * removed!
180 * removed!
181 * removed!
182 *
183 * removed!
184 * removed!
185 * removed!
186 * removed!
187 *
188 * removed!
189 * removed!
190 * removed!
191 *
192 * removed!
193 * removed!
194 * removed!
195 *
196 * removed!
197 * removed!
198 * removed!
199 *
200 * removed!
201 * removed!
202 * removed!
203 *
204 * removed!
205 * removed!
206 * removed!
207 *
208 * removed!
209 * removed!
210 * removed!
211 * removed!
212 *
213 * removed!
214 * removed!
215 * removed!
216 * removed!
217 *
218 * removed!
219 * removed!
220 * removed!
221 * removed!
222 *
223 * removed!
224 * removed!
225 * removed!
226 * removed!
227 *
228 * removed!
229 * removed!
230 * removed!
231 * removed!
232 *
233 * removed!
234 * removed!
235 * removed!
236 * removed!
237 *
238 * removed!
239 * removed!
240 * removed!
241 * removed!
242 *
243 * removed!
244 * removed!
245 * removed!
246 * removed!
247 *
248 * removed!
249 * removed!
250 * removed!
251 * removed!
252 *
253 * removed!
254 * removed!
255 * removed!
256 * removed!
257 *
258 * removed!
259 * removed!
260 * removed!
261 * removed!
262 *
263 * removed!
264 * removed!
265 * removed!
266 * removed!
267 *
268 * removed!
269 * removed!
270 * removed!
271 *
272 * removed!
273 * removed!
274 * removed!
275 *
276 * removed!
277 * removed!
278 * removed!
279 *
280 * removed!
281 * removed!
282 * removed!
283 *
284 * removed!
285 * removed!
286 *
287 * removed!
288 * removed!
289 * removed!
290 *
291 * removed!
292 * removed!
293 * removed!
294 *
295 * removed!
296 * removed!
297 * removed!
298 *
299 * removed!
300 * removed!
301 * removed!
302 *
303 * removed!
304 * removed!
305 * removed!
306 *
307 * removed!
308 * removed!
309 * removed!
310 *
311 * removed!
312 * removed!
313 * removed!
314 *
315 * removed!
316 * removed!
317 * removed!
318 *
319 * removed!
320 * removed!
321 * removed!
322 *
323 * removed!
324 * removed!
325 * removed!
326 *
327 * removed!
328 * removed!
329 * removed!
330 *
331 * removed!
332 * removed!
333 * removed!
334 *
335 * removed!
336 * removed!
337 * removed!
338 *
339 * removed!
340 * removed!
341 *
342 * removed!
343 * removed!
344 * removed!
345 *
346 * removed!
347 * removed!
348 * removed!
349 *
350 * removed!
351 * removed!
352 * removed!
353 *
354 * removed!
355 * removed!
356 * removed!
357 *
358 * removed!
359 * removed!
360 * removed!
361 *
362 * removed!
363 * removed!
364 * removed!
365 *
366 * removed!
367 * removed!
368 * removed!
369 *
370 * removed!
371 * removed!
372 * removed!
373 *
374 * removed!
375 * removed!
376 * removed!
377 *
378 * removed!
379 * removed!
380 * removed!
381 * removed!
382 * removed!
383 * removed!
384 * removed!
385 * removed!
386 * removed!
387 *
388 * removed!
389 * removed!
390 * removed!
391 *
392 * removed!
393 * removed!
394 * removed!
395 *
396 * removed!
397 * removed!
398 * removed!
399 *
400 * removed!
401 * removed!
402 * removed!
403 *
404 * removed!
405 * removed!
406 * removed!
407 *
408 * removed!
409 * removed!
410 * removed!
411 *
412 * removed!
413 * removed!
414 * removed!
415 *
416 * removed!
417 * removed!
418 * removed!
419 *
420 * removed!
421 * removed!
422 * removed!
423 *
424 * removed!
425 * removed!
426 * removed!
427 *
428 * removed!
429 * removed!
430 * removed!
431 *
432 * removed!
433 * removed!
434 * removed!
435 *
436 * removed!
437 * removed!
438 * removed!
439 * removed!
440 * removed!
441 * removed!
442 * removed!
443 * removed!
444 * removed!
445 *
446 * removed!
447 * removed!
448 * removed!
449 * removed!
450 * removed!
451 * removed!
452 * removed!
453 * removed!
454 * removed!
455 *
456 *
457 * removed!
458 * removed!
459 * removed!
460 *
461 * removed!
462 * removed!
463 * removed!
464 *
465 * removed!
466 * removed!
467 * removed!
468 *
469 * removed!
470 * removed!
471 * removed!
472 *
473 * removed!
474 * removed!
475 * removed!
476 *
477 * removed!
478 * removed!
479 * removed!
480 *
481 * removed!
482 * removed!
483 * removed!
484 *
485 * removed!
486 * removed!
487 * removed!
488 *
489 * removed!
490 * removed!
491 * removed!
492 *
493 * removed!
494 * removed!
495 * removed!
496 *
497 * removed!
498 * removed!
499 * removed!
500 *
501 * removed!
502 * removed!
503 * removed!
504 *
505 * removed!
506 * removed!
507 * removed!
508 *
509 * removed!
510 * removed!
511 *
512 * removed!
513 * removed!
514 * removed!
515 *
516 * removed!
517 * removed!
518 * removed!
519 *
520 * removed!
521 * removed!
522 * removed!
523 *
524 * removed!
525 * removed!
526 * removed!
527 *
528 * removed!
529 * removed!
530 * removed!
531 *
532 * removed!
533 * removed!
534 * removed!
535 *
536 * removed!
537 * removed!
538 * removed!
539 *
540 * removed!
541 * removed!
542 * removed!
543 *
544 * removed!
545 * removed!
546 * removed!
547 *
548 * removed!
549 * removed!
550 * removed!
551 *
552 * removed!
553 * removed!
554 * removed!
555 *
556 * removed!
557 * removed!
558 * removed!
559 *
560 * removed!
561 * removed!
562 * removed!
563 *
564 * removed!
565 * removed!
566 * removed!
567 *
568 * removed!
569 * removed!
570 * removed!
571 *
572 * removed!
573 * removed!
574 * removed!
575 *
576 * removed!
577 * removed!
578 * removed!
579 *
580 * removed!
581 * removed!
582 * removed!
583 *
584 * removed!
585 * removed!
586 * removed!
587 *
588 * removed!
589 * removed!
590 * removed!
591 *
592 * removed!
593 * removed!
594 * removed!
595 *
596 * removed!
597 * removed!
598 * removed!
599 * removed!
600 * removed!
601 * removed!
602 * removed!
603 * removed!
604 * removed!
605 * removed!
606 * removed!
607 * removed!
608 * removed!
609 * removed!
610 * removed!
611 * removed!
612 * removed!
613 * removed!
614 * removed!
615 * removed!
616 * removed!
617 * removed!
618 * removed!
619 * removed!
620 * removed!
621 * removed!
622 * removed!
623 * removed!
624 * removed!
625 * removed!
626 * removed!
627 * removed!
628 * removed!
629 * removed!
630 * removed!
631 *
632 * removed!
633 * removed!
634 * removed!
635 *
636 * removed!
637 * removed!
638 * removed!
639 *
640 * removed!
641 * removed!
642 * removed!
643 *
644 * removed!
645 * removed!
646 * removed!
647 *
648 * removed!
649 * removed!
650 * removed!
651 *
652 * removed!
653 * removed!
654 * removed!
655 *
656 * removed!
657 * removed!
658 * removed!
659 *
660 * removed!
661 * removed!
662 * removed!
663 *
664 * removed!
665 * removed!
666 * removed!
667 *
668 * removed!
669 * removed!
670 * removed!
671 *
672 * removed!
673 * removed!
674 * removed!
675 *
676 * removed!
677 * removed!
678 * removed!
679 *
680 * removed!
681 * removed!
682 * removed!
683 *
684 * removed!
685 * removed!
686 * removed!
687 *
688 * removed!
689 * removed!
690 * removed!
691 *
692 * removed!
693 * removed!
694 * removed!
695 *
696 * removed!
697 * removed!
698 * removed!
699 *
700 * removed!
701 * removed!
702 * removed!
703 *
704 * removed!
705 * removed!
706 * removed!
707 *
708 * removed!
709 * removed!
710 * removed!
711 *
712 * removed!
713 * removed!
714 * removed!
715 *
716 * removed!
717 * removed!
718 * removed!
719 *
720 * removed!
721 * removed!
722 * removed!
723 *
724 * removed!
725 * removed!
726 * removed!
727 *
728 * removed!
729 * removed!
730 * removed!
731 *
732 * removed!
733 * removed!
734 * removed!
735 *
736 * removed!
737 * removed!
738 * removed!
739 *
740 * removed!
741 * removed!
742 * removed!
743 *
744 * removed!
745 * removed!
746 * removed!
747 *
748 * removed!
749 * removed!
750 * removed!
751 *
752 * removed!
753 * removed!
754 * removed!
755 *
756 * removed!
757 * removed!
758 * removed!
759 *
760 * removed!
761 * removed!
762 * removed!
763 *
764 * removed!
765 * removed!
766 * removed!
767 *
768 * removed!
769 * removed!
770 * removed!
771 *
772 * removed!
773 * removed!
774 * removed!
775 *
776 ****************************************************************************/
777
778#ifndef _KAL_PUBLIC_API_H
779#define _KAL_PUBLIC_API_H
780
781/*******************************************************************************
782 * Common Header File Include
783 *******************************************************************************/
784#ifndef GEN_FOR_PC
785#include <stdio.h>
786#include <string.h>
787#endif
788
789#include "kal_general_types.h"
790#include "kal_public_defs.h"
791#include "kal_atomic_api.h"
792#include "mips_ia_utils_public.h"
793#include "kal_inline_api.h"
794
795#if defined(__DHL_MODULE__)
796#include "dhl_trace.h"
797#endif
798
799#ifdef __cplusplus
800extern "C" {
801#endif
802
803/* DOM-NOT_FOR_SDK-BEGIN */
804#if defined(KAL_ON_OSCAR)
805#define kal_snprintf _snprintf
806#else
807#define kal_snprintf snprintf
808#endif
809
810/*******************************************************************************
811 * <GROUP Functions>
812 *
813 * FUNCTION
814 * sprintf
815 * DESCRIPTION
816 * sprintf accepts a series of arguments, applies to each a format specifier from *format,
817 * and writes the formatted data to buffer str, and a terminating NUL is output.
818 * PARAMETERS
819 * str: [IN] destination buffer
820 * format: [IN] specify the arguments output format
821 * ...: [IN] variable-parameter, a series of arguments
822 * NOTE
823 * number of variable-parameters must be less than or equal to 20, if more paramters are checked, will assert.
824 * this limitation is also apply to all sprintf/sscanf family functions, that is sprintf/snprintf/vsprintf/vsnprintf/sscanf/vsscanf
825 * RETURN VALUES
826 * the number of bytes in the output string, except the concluding NUL is not counted.
827 ******************************************************************************/
828#define kal_sprintf sprintf
829
830extern kal_char *kal_strtok_r(kal_char *string, const kal_char *seperators,
831 kal_char **ppLast);
832
833#define kal_toWCHAR(asciiString) L##asciiString
834
835/*************************************************************************
836* FUNCTION
837* kal_itoa
838*
839* DESCRIPTION
840* converts integers to string in various radixes
841*
842* PARAMETERS
843* value - integer need to convert
844* str - buffer to save convert result
845* radix - the base of the integer, like 2,10,16
846* RETURNS
847* return the str buffer address
848*
849*************************************************************************/
850extern char *kal_itoa(int value, char *str, int radix);
851
852/*
853 * 16bits string operations
854 */
855extern int kal_wstrlen(const WCHAR *wstr);
856extern WCHAR *kal_wstrcpy(WCHAR *to, const WCHAR *from);
857extern WCHAR *kal_wstrncpy(WCHAR *to, const WCHAR *from, int n);
858extern int kal_wstrcmp(const WCHAR *s1, const WCHAR *s2);
859extern int kal_wstrncmp(const WCHAR *s1, const WCHAR *s2, int n);
860extern WCHAR *kal_wstrcat(WCHAR *s1, const WCHAR *s2);
861extern WCHAR *kal_wstrncat(WCHAR *s1, const WCHAR *s2, int n);
862extern WCHAR *kal_wstrchr(const WCHAR *s, int c);
863extern WCHAR *kal_wstrrchr(const WCHAR *str, int ch);
864
865/*
866 * dual 8bits string operations
867 */
868extern int kal_dchar_strlen(const char *wstr);
869extern char *kal_dchar_strcpy(char *to, const char *from);
870extern char *kal_dchar_strncpy(char *to, const char *from, int n);
871extern int kal_dchar_strcmp(const char *s1, const char *s2);
872extern int kal_dchar_strncmp(const char *s1, const char *s2, int n);
873extern char *kal_dchar_strcat(char *s1, const char *s2);
874extern char *kal_dchar_strncat(char *s1, const char *s2, int n);
875extern char *kal_dchar_strchr(const char *s, int c);
876extern char *kal_dchar_strrchr(const char *str, int ch);
877extern void kal_dchar2char(WCHAR *outstr, char *tostr);
878extern void kal_wsprintf(WCHAR *outstr, char *fmt, ...);
879
880
881#if !defined(GEN_FOR_PC)
882
883/*************************************************************************
884* FUNCTION
885* time
886*
887* DESCRIPTION
888* time() return current calendar time as a value of type time_t .It stores the same value at
889* parameter t unless the argument is NULL. The value represents the number of seconds
890* since 00:00 hours, Jan 1, 1970 UTC (i.e., the current unix timestamp).
891*
892* PARAMETERS
893* t - pointer to an object of type time_t to store the current time.
894* You can just input NULL, the function still return a value of type time_t with the result.
895*
896* RETURNS
897* The current calendar time as a value of type time_t .
898*
899* NOTE
900* Only be supported in limited projects. If it is not supported, build fail is happened.
901*
902*************************************************************************/
903extern time_t time(time_t *t);
904
905/*************************************************************************
906* FUNCTION
907* time_ms_us
908*
909* DESCRIPTION
910* time_ms_us() return current calendar time as a value of type wall_clock .It stores the same value at
911* parameter t unless the argument is NULL. The value represents the number of milli-seconds and micro-seconds
912* since 00:00 hours, Jan 1, 1970 UTC (i.e., the current unix timestamp).
913*
914* PARAMETERS
915* t - pointer to an object of type wall_clock to store the current time.
916* You can just input NULL, the function still return a value of type wall_clock with the result.
917*
918* RETURNS
919* The current calendar time as a value of type wall_clock .
920*
921* NOTE
922* Only be supported in limited projects. If it is not supported, build fail is happened.
923*
924*************************************************************************/
925extern wall_clock time_ms_us(wall_clock *t);
926
927/*************************************************************************
928* FUNCTION
929* gmtime_r
930*
931* DESCRIPTION
932* Uses the value pointed by tim_p to fill the tm structure pointed by res with the values
933* that represent the corresponding time, expressed as UTC time (i.e., the time at the
934* GMT timezone). If tim_p or res is NULL, NULL will be returned and the content of res
935* will not be changed.
936*
937* PARAMETERS
938* tim_p - pointer to an object of type time_t that contains a time value.
939* res - pointer to an object of type tm to store the result converted by gmtime_r
940*
941* RETURNS
942* A pointer to inputted tm structure res with its members filled with the values that
943* correspond to the UTC time representation of tim_p.
944* Return NULL if tim_p or res is NULL.
945*
946* NOTE
947* Only be supported in limited projects. If it is not supported, build fail is happened.
948*
949* SEE ALSO
950* time, localtime_r
951*
952*************************************************************************/
953extern struct tm *gmtime_r(const time_t *tim_p, struct tm *res);
954
955
956/*************************************************************************
957* FUNCTION
958* localtime_r
959*
960* DESCRIPTION
961* Uses the value pointed by tim_p to fill the tm structure pointed by res with the values that
962* represent the corresponding time, expressed for the local timezone.
963* Note that localtime() may not available due to timezone is not updated within bootup 10
964* seconds. If it is happened, the result of localtime_r() is equal to gmtime_r(). (i.e. the returned
965* tm structure represents the corresponding UTC time.
966*
967* PARAMETERS
968* tim_p - pointer to an object of type time_t that contains a time value.
969* res - pointer to an object of type tm to store the result converted by localtime_r()
970*
971* RETURNS
972* A pointer to inputted tm structure res with its members filled with the values that
973* correspond to the local time representation of tim_p if localtime_r() is available. If localtime_r()
974* is not available, the tm structure represents the corresponding UTC time.
975* Return NULL if tim_p or res is NULL.
976*
977* NOTE
978* Only be supported in limited projects. If it is not supported, build fail is happened.
979*
980* SEE ALSO
981* time, gmtime_r
982*
983*************************************************************************/
984struct tm *localtime_r(const time_t *tim_p, struct tm *res);
985
986
987/*************************************************************************
988* FUNCTION
989* asctime_r
990*
991* DESCRIPTION
992* Interprets the contents of the tm structure pointed by tim_p as a calendar time and
993* converts it to a C-string containing a human-readable version of the corresponding
994* date and time. The returned string has the following format:
995* Www Mmm dd hh:mm:ss yyyy
996* Where Www is the weekday, Mmm the month (in letters), dd the day of the month,
997* hh:mm:ss the time, and yyyy the year. The string is followed by a new-line character
998* ('\n') and terminated with a null-character.
999* If tim_p or res is NULL, NULL will be returned and the content of res will not be changed.
1000*
1001* PARAMETERS
1002* tim_p - pointer to a tm structure that contains a calendar time broken down into its
1003* components (see struct tm).
1004* res - a pointer to the string for containing result converted by asctime_r.
1005* The length of the string should larger than 26.
1006*
1007* RETURNS
1008* A pointer to inputted string res containing the date and time information in a
1009* human-readable format.
1010* Return NULL if tim_p or res is NULL.
1011*
1012* NOTE
1013* Only be supported in limited projects. If it is not supported, build fail is happened.
1014*
1015* SEE ALSO
1016* time, gmtime_r, localtime_r, ctime_r
1017*
1018*************************************************************************/
1019char *asctime_r(const struct tm *tim_p, char *res);
1020
1021
1022/*************************************************************************
1023* FUNCTION
1024* ctime_r
1025*
1026* DESCRIPTION
1027* Interprets the contents of the tm structure pointed by tim_p as a calendar time and
1028* converts it to a C-string containing a human-readable version of the corresponding
1029* date and time, in terms of local time. The returned string has the following format:
1030* Www Mmm dd hh:mm:ss yyyy
1031* Where Www is the weekday, Mmm the month (in letters), dd the day of the month,
1032* hh:mm:ss the time, and yyyy the year. The string is followed by a new-line character
1033* ('\n') and terminated with a null-character.
1034* Note that ctime_r() may not available due to timezone is not updated within bootup 10
1035* seconds. If it is happened, the result of ctime_r(), asctime_r(localtime_r()), is equal to
1036* asctime_r(gmtime_r()).
1037*
1038* PARAMETERS
1039* tim_p - pointer to a tm structure that contains a calendar time broken down into its
1040* components (see struct tm).
1041* res - a pointer to the string for containing result converted by ctime_r.
1042* The length of the string should larger than 26.
1043*
1044* RETURNS
1045* A pointer to inputted string res containing the date and time information in a
1046* human-readable format.
1047* Return NULL if tim_p or res is NULL.
1048*
1049* NOTE
1050* Only be supported in limited projects. If it is not supported, build fail is happened.
1051*
1052* SEE ALSO
1053* time, gmtime_r, localtime_r, asctime_r
1054*
1055*************************************************************************/
1056char *ctime_r(const time_t *tim_p, char *res);
1057
1058#endif /* !defined(GEN_FOR_PC) */
1059#if defined(__MTK_TARGET__)
1060/*KAL_CC_SPINLOCK*/
1061extern void *kal_cc_md1_dsp_spinlock;
1062
1063kal_status MD1_DSP_kal_cc_take_spinlock(void * cc_spinlock_p,
1064 kal_wait_mode wait_mode);
1065void MD1_DSP_kal_cc_give_spinlock(void *cc_spinlock_p);
1066#endif
1067/*******************************************************************************
1068 * Category 2 : Query Functions for Initialize and States
1069 *******************************************************************************/
1070
1071/*******************************************************************************
1072 * <GROUP Functions>
1073 *
1074 * FUNCTION
1075 * kal_query_systemInit
1076 * DESCRIPTION
1077 * query whether the system is in initialization phase.
1078 * PARAMETERS
1079 * N/A
1080 * RETURN VALUES
1081 * KAL_TRUE: system is in initialization phase.
1082 * KAL_FALSE: system is not in initialization phase.
1083 ******************************************************************************/
1084extern kal_bool kal_query_systemInit(void);
1085
1086/*******************************************************************************
1087 * <GROUP Functions>
1088 *
1089 * FUNCTION
1090 * kal_get_curent_domain
1091 * DESCRIPTION
1092 * return current domain
1093 * RETURNS
1094 * enum kal_domain: KAL_DOMAIN_NORMAL/KAL_DOMAIN_HRT/KAL_DOMAIN_CHRT
1095 ******************************************************************************/
1096#if defined(__MTK_TARGET__)
1097#if !defined(__kal_get_current_domain__)
1098#define __kal_get_current_domain__
1099#if defined(__MIPS_I7200__)
1100#define kal_get_current_domain() (miu_mfc0(MIU_C0_KSCRATCH4) & 0x3)
1101#endif /* defined(__MIPS_I7200__) */
1102#endif /* __kal_get_current_domain__ */
1103#else /* __MTK_TARGET__ */
1104#define kal_get_current_domain() 0
1105#endif /* __MTK_TARGET__ */
1106
1107/*******************************************************************************
1108 * <GROUP Functions>
1109 *
1110 * FUNCTION
1111 * kal_if_hrt_domain
1112 * DESCRIPTION
1113 * Identify if current VPE is HRT domain
1114 * PARAMETERS
1115 * VPE ID
1116 * RETURNS
1117 * KAL_TRUE if current VPE is HRT domain
1118 ******************************************************************************/
1119#if !defined(__MTK_TARGET__)
1120#define kal_get_domain(vpe_id) 0
1121#define kal_if_hrt_domain(vpe_id) 0
1122#endif /* __MTK_TARGET__ */
1123
1124/*************************************************************************
1125* FUNCTION
1126* kal_runtime_affinity_set
1127* DESCRIPTION
1128* set current task's or current hisr's affinity attribute
1129* PARAMETERS
1130* affinity[IN]: VPE0_Group, VPE2_Group, SMP_NORMAL_Group
1131* RETURNS
1132* KAL_TRUE or KAL_FALSE
1133*************************************************************************/
1134kal_bool kal_runtime_affinity_set(kal_affinity_group affinity);
1135
1136/*************************************************************************
1137* FUNCTION
1138* kal_runtime_affinity_resume
1139* DESCRIPTION
1140* resume current task's or current hisr's affinity attribute to original config value
1141* PARAMETERS
1142* NONE
1143* RETURNS
1144* KAL_TRUE or KAL_FALSE
1145*************************************************************************/
1146kal_bool kal_runtime_affinity_resume(void);
1147
1148/*************************************************************************
1149* FUNCTION
1150* kal_runtime_affinity_to_current_vpe
1151* DESCRIPTION
1152* Affines the calling task to current VPE.
1153* PARAMETERS
1154* NONE
1155* RETURNS
1156* KAL_TRUE
1157*************************************************************************/
1158kal_bool kal_runtime_affinity_to_current_vpe(void);
1159
1160/*************************************************************************
1161* FUNCTION
1162* kal_runtime_group_affinity_set
1163* DESCRIPTION
1164* Sets the affinity of all tasks in given group. All tasks must be in some
1165* of KAL_SUSPEND states or the whole operation will fail.
1166* PARAMETERS
1167* group_id[IN]: Group ID
1168* affinity[IN]: affinity mask
1169* RETURNS
1170* KAL_TRUE if affinity set was successful
1171* KAL_FALSE if affinity set failed (e.g. because one or more tasks were �n
1172* non-suspended state
1173*************************************************************************/
1174
1175kal_bool kal_runtime_group_affinity_set(kal_task_group_id group_id,
1176 kal_affinity_group affinity);
1177
1178/* DOM-NOT_FOR_SDK-END */
1179
1180/*******************************************************************************
1181 * Category 3 : LISR, HISR and TASK functions
1182 *******************************************************************************/
1183
1184/*******************************************************************************
1185 * <GROUP Functions>
1186 *
1187 * FUNCTION
1188 * kal_get_current_thread_ID
1189 * DESCRIPTION
1190 * get current thread identity, which is a unique pointer for each thread.
1191 * PARAMETERS
1192 * N/A
1193 * RETURNS
1194 * current thread identity.
1195 * NOTE
1196 * thread is defined as task or HISR.
1197 ******************************************************************************/
1198void *kal_get_current_thread_ID(void);
1199/*******************************************************************************
1200 * <GROUP Functions>
1201 *
1202 * FUNCTION
1203 * kal_get_current_lisr_ID
1204 * DESCRIPTION
1205 * get current lisr identity.
1206 * PARAMETERS
1207 * N/A
1208 * RETURNS
1209 * current lisr identity.
1210 ******************************************************************************/
1211kal_uint32 kal_get_current_lisr_ID(void);
1212/*******************************************************************************
1213 * <GROUP Functions>
1214 *
1215 * FUNCTION
1216 * kal_sleep_task
1217 * DESCRIPTION
1218 * put the task into sleep for a specified duration which is expressed in terms
1219 * of system tick.
1220 * PARAMETERS
1221 * time_in_ticks: [IN] how many system ticks to sleep.
1222 * RETURNS
1223 * N/A
1224 * NOTE
1225 * N/A
1226 * SEE ALSO
1227 * KAL_MILLISECS_PER_TICK
1228 ******************************************************************************/
1229void kal_sleep_task(kal_uint32 time_in_ticks);
1230/*******************************************************************************
1231 * <GROUP Functions>
1232 *
1233 * FUNCTION
1234 * kal_get_current_task
1235 * DESCRIPTION
1236 * get current task identity.
1237 * PARAMETERS
1238 * N/A
1239 * RETURNS
1240 * current task identity.
1241 * SEE ALSO
1242 * kal_get_current_task_index
1243 ******************************************************************************/
1244kal_taskid kal_get_current_task(void);
1245/*******************************************************************************
1246 * <GROUP Functions>
1247 *
1248 * FUNCTION
1249 * kal_get_current_hisr
1250 * DESCRIPTION
1251 * get current hisr identity.
1252 * PARAMETERS
1253 * N/A
1254 * RETURNS
1255 * current hisr identity.
1256 * SEE ALSO
1257 * kal_get_current_hisr_index
1258 ******************************************************************************/
1259kal_hisrid kal_get_current_hisr(void);
1260/*******************************************************************************
1261 * <GROUP Functions>
1262 *
1263 * FUNCTION
1264 * kal_get_current_task_priority
1265 * DESCRIPTION
1266 * get current task priority.
1267 * PARAMETERS
1268 * N/A
1269 * RETURNS
1270 * current task priority.
1271 ******************************************************************************/
1272kal_uint32 kal_get_current_task_priority(void);
1273
1274/*************************************************************************
1275 * FUNCTION
1276 * kal_get_task_status
1277 *
1278 * DESCRIPTION
1279 * This routine is to get the task's status.
1280 *
1281 * PARAMETERS
1282 * taskid : task id(pointer points to task control block
1283 *
1284 * RETURNS
1285 * task's current status
1286 *
1287 * GLOBALS AFFECTED
1288 *
1289 *************************************************************************/
1290kal_task_status kal_get_task_status(kal_taskid taskid);
1291
1292/*******************************************************************************
1293 * <GROUP Functions>
1294 *
1295 * FUNCTION
1296 * kal_set_active_module_id
1297 * DESCRIPTION
1298 * set active module in current task.
1299 * PARAMETERS
1300 * module_id: [IN] active module in current task.
1301 * RETURNS
1302 * N/A
1303 * NOTE
1304 * (1)This API must be called before kal_get_active_module_id(). So, the recommended place to call it
1305 * is in task main function, immediately after get a ILM message.
1306 * SEE ALSO
1307 * kal_get_active_module_id
1308 ******************************************************************************/
1309extern void kal_set_active_module_id(module_type module_id);
1310
1311/*******************************************************************************
1312 * <GROUP Functions>
1313 *
1314 * FUNCTION
1315 * kal_get_active_module_id
1316 * DESCRIPTION
1317 * get active module in current task.
1318 * PARAMETERS
1319 * N/A
1320 * RETURNS
1321 * active module in current task.
1322 * NOTE
1323 * (1)This API return the last value set by kal_set_active_module_id().
1324 * SEE ALSO
1325 * kal_set_active_module_id
1326 ******************************************************************************/
1327extern module_type kal_get_active_module_id(void);
1328
1329/*******************************************************************************
1330 * <GROUP Functions>
1331 *
1332 * FUNCTION
1333 * kal_get_lisr_module_id
1334 * DESCRIPTION
1335 * This routine is to get the irq's module id.
1336 * PARAMETERS
1337 * irq_id: [IN] IRQ Code ID.
1338 * RETURNS
1339 * irq's module id.
1340 * SEE ALSO
1341 *
1342 ******************************************************************************/
1343extern module_type kal_get_lisr_module_id(kal_uint32 irq_id);
1344
1345/*******************************************************************************
1346 * <GROUP Functions>
1347 *
1348 * FUNCTION
1349 * kal_get_task_by_moduleID
1350 * DESCRIPTION
1351 * get taskid from task index.
1352 * PARAMETERS
1353 * index: [IN] target task index.
1354 * RETURNS
1355 * Return corresponding taskid. If the target task doesn't exist, return NULL.
1356 * SEE ALSO
1357 * kal_get_task_index
1358 ******************************************************************************/
1359extern kal_taskid kal_get_task_by_moduleID(module_type modele_id);
1360
1361/*************************************************************************
1362* <GROUP Functions>
1363*
1364* FUNCTION
1365* kal_task_mod_remap (Only for NL1 Build Load)
1366* DESCRIPTION
1367* This function will remap module to new task.
1368* PARAMETERS
1369* module_type: [IN] destination module Id
1370* module_type: [IN] source module Id
1371* RETURNS
1372* None
1373* GLOBALS AFFECTED
1374* mod_task_g
1375* NOTE
1376* This Function is Only for NL1 Build Load.
1377* SEE ALSO
1378* kal_update_task_mod
1379*************************************************************************/
1380extern void kal_task_mod_remap(module_type dst_mod_id, module_type src_mod_id);
1381
1382/* DOM-NOT_FOR_SDK-BEGIN */
1383/*******************************************************************************
1384 * <GROUP Functions>
1385 *
1386 * FUNCTION
1387 * kal_get_task_total_number
1388 * DESCRIPTION
1389 * query total task index number.
1390 * PARAMETERS
1391 * NA.
1392 * RETURNS
1393 * Return total task index number.
1394 ******************************************************************************/
1395extern kal_uint32 kal_get_task_total_number(void);
1396
1397/*******************************************************************************
1398 * <GROUP Functions>
1399 *
1400 * FUNCTION
1401 * kal_get_send_msg_module_id_total_number
1402 * DESCRIPTION
1403 * query total module id number that can send message.
1404 * PARAMETERS
1405 * NA.
1406 * RETURNS
1407 * Return total module id number that can send message.
1408 ******************************************************************************/
1409extern kal_uint32 kal_get_send_msg_module_id_total_number(void);
1410/* DOM-NOT_FOR_SDK-END */
1411
1412/* DOM-NOT_FOR_SDK-BEGIN */
1413
1414
1415/*******************************************************************************
1416 * <GROUP Functions>
1417 *
1418 * FUNCTION
1419 * kal_get_current_hisr_index
1420 * DESCRIPTION
1421 * get current HISR index.
1422 * PARAMETERS
1423 * N/A
1424 * RETURNS
1425 * current HISR index.
1426 * NOTE
1427 * (1)This API must be called from HISR.
1428 ******************************************************************************/
1429extern kal_uint32 kal_get_current_hisr_index(void);
1430
1431/*************************************************************************
1432* <GROUP Functions>
1433*
1434* FUNCTION
1435* kal_check_stack
1436*
1437* DESCRIPTION
1438* This routine is to check whether the start of current thread stack is corrupted.
1439* If so, the system enter fatal error handling.
1440*
1441* PARAMETERS
1442* N/A
1443* RETURNS
1444*
1445* GLOBALS AFFECTED
1446*
1447*************************************************************************/
1448extern void kal_check_stack(void);
1449
1450 /*******************************************************************************
1451 * <GROUP Functions>
1452 *
1453 * FUNCTION
1454 * kal_activate_hisr_index
1455 * DESCRIPTION
1456 * activate specified HISR.
1457 * PARAMETERS
1458 * ext_hisr: [IN] HISR index.
1459 * RETURNS
1460 * N/A
1461 ******************************************************************************/
1462extern void kal_activate_hisr_index(kal_hisr ext_hisr);
1463
1464/*******************************************************************************
1465 * <GROUP Functions>
1466 *
1467 * FUNCTION
1468 * kal_if_hisr
1469 * DESCRIPTION
1470 * Identify if the current execution unit is a HISR.
1471 * PARAMETERS
1472 * N/A
1473 * RETURNS
1474 * KAL_FALSE if the current execution unit is a task, and KAL_TRUE if the current execution unit is a HISR.
1475 * SEE ALSO
1476 * kal_if_lisr
1477 ******************************************************************************/
1478extern kal_bool kal_if_hisr(void);
1479/*******************************************************************************
1480 * <GROUP Functions>
1481 *
1482 * FUNCTION
1483 * kal_if_lisr
1484 * DESCRIPTION
1485 * Identify if the current execution unit is a LISR.
1486 * PARAMETERS
1487 * N/A
1488 * RETURNS
1489 * KAL_FALSE if the current execution unit is a task or HISR, and KAL_TRUE if the current execution unit is a LISR.
1490 * SEE ALSO
1491 * kal_if_hisr
1492 ******************************************************************************/
1493#if defined(__MTK_TARGET__)
1494#if !defined(__kal_if_lisr__)
1495#define __kal_if_lisr__
1496#define kal_if_lisr() (miu_mfc0(MIU_C0_USERLOCAL) > 0)
1497#endif
1498#else
1499extern kal_bool kal_if_lisr(void);
1500#endif
1501/*******************************************************************************
1502 * <GROUP Functions>
1503 *
1504 * FUNCTION
1505 * kal_get_task_affinity_by_moduleID
1506 * DESCRIPTION
1507 * Query the hard affinity attribute of a certain task by its MOD ID.
1508 * PARAMETERS
1509 * mod: [IN] the module id of the task wanting to query its affinity
1510 * returnAffinity: [IN] the pointer to store the affinity query result
1511 * the content will be kal_affinity_group enum
1512 * RETURNS
1513 * KAL_ERROR if the MOD ID is invalid or the task is not created. KAL_SUCCESS if the query is succeed.
1514 * SEE ALSO
1515 *
1516 ******************************************************************************/
1517kal_status kal_get_task_affinity_by_moduleID(module_type mod,
1518 kal_affinity_group *returnAffinity);
1519
1520
1521/*************************************************************************
1522 * <GROUP Functions>
1523 *
1524 * FUNCTION
1525* kal_get_current_context
1526* DESCRIPTION
1527* This function return current context we are running.
1528* PARAMETERS
1529* N/A
1530* RETURNS
1531* kal_sw_context_type
1532*
1533*************************************************************************/
1534kal_sw_context_type kal_get_current_context(void);
1535
1536/* DOM_NOT_FOR_SDK-END */
1537
1538/*******************************************************************************
1539 * Category 4 : Message Passing and Queue
1540 *******************************************************************************/
1541/* DOM-NOT_FOR_SDK-BEGIN */
1542
1543extern void *construct_int_local_para(kal_uint16 local_para_size,
1544 kal_uint32 auto_reset,
1545 const kal_char *file_ptr, kal_uint32 line);
1546extern kal_bool free_int_local_para(local_para_struct *local_para_ptr,
1547 const kal_char *file, kal_uint32 line);
1548#define free_int_local_para_r free_int_local_para
1549extern void *construct_int_peer_buff(kal_uint16 pdu_len, kal_uint16 header_len,
1550 kal_uint16 tail_len,
1551 const kal_char *file_name_ptr, kal_uint32 line);
1552extern kal_bool free_int_peer_buff(peer_buff_struct *pdu_ptr, const kal_char *file,
1553 kal_uint32 line);
1554#define free_int_peer_buff_r free_int_peer_buff
1555extern void destroy_int_ilm(ilm_struct *ilm_ptr, const kal_char *file_name,
1556 kal_uint32 line);
1557
1558#if defined(DEBUG_KAL) && defined(DEBUG_BUF2)
1559#define __construct_local_para(local_para_size, direction) \
1560 construct_int_local_para( \
1561 local_para_size, ((kal_uint32)(direction) & (kal_uint32)TD_RESET) ? 1 : 0, \
1562 __FILE__, __LINE__)
1563#define __free_local_para(local_para) \
1564 free_int_local_para(local_para, __FILE__, __LINE__)
1565#define __construct_peer_buff(pdu_len, header_len, tail_len, direction) \
1566 construct_int_peer_buff(pdu_len, header_len, tail_len, __FILE__, __LINE__)
1567#define __free_peer_buff(peer_buff) free_int_peer_buff(peer_buff, __FILE__, __LINE__)
1568#else /* !DEBUG_KAL || !DEBUG_BUF2 */
1569#define __construct_local_para(local_para_size, direction) \
1570 construct_int_local_para( \
1571 local_para_size, ((kal_uint32)(direction) & (kal_uint32)TD_RESET) ? 1 : 0, \
1572 NULL, 0)
1573#define __free_local_para(local_para) free_int_local_para(local_para, NULL, 0)
1574#define __construct_peer_buff(pdu_len, header_len, tail_len, direction) \
1575 construct_int_peer_buff(pdu_len, header_len, tail_len, NULL, 0)
1576#define __free_peer_buff(peer_buff) free_int_peer_buff(peer_buff, NULL, 0)
1577#endif
1578/* DOM-NOT_FOR_SDK-END */
1579/* DOM-NOT_FOR_SDK-BEGIN */
1580/*******************************************************************************
1581 * <GROUP Functions>
1582 *
1583 * FUNCTION
1584 * construct_local_para
1585 * DESCRIPTION
1586 * allocate a local_para structure which has local_para_size bytes including LOCAL_PARA_HDR.
1587 * PARAMETERS
1588 * local_para_size: [IN] local_para structure size, this size includes LOCAL_PARA_HDR header,
1589 * so the minimum size is sizeof(LOCAL_PARA_HDR) which imply the pdu part is 0 byte.
1590 * direction: [IN] a bitmask, each bit is defined as following values:
1591 * 0 - nothing.
1592 * TD_RESET - to zero-initialize the pdu in this local_para structure.
1593 * RETURNS
1594 * a local_para structure pointer. System enter fatal error handling if no enough memory.
1595 * NOTE
1596 * (1) the prototype of this API is:
1597 * void* construct_local_para(kal_uint16 local_para_size, transfer_direction direction);
1598 * (2) local_para structure is a user-defined structure has a predefined header LOCAL_PARA_HDR
1599 * embedded in front of it:
1600 * struct bt_connected_info {
1601 * LOCAL_PARA_HDR; // this field must be the first elements in structure
1602 * // user-defined fields follows, pdu of this local_para structure
1603 * };
1604 * LOCAL_PARA_HDR is defined as:
1605 * #define LOCAL_PARA_HDR kal_uint8 ref_count; kal_uint8 lp_reserved; kal_uint16 msg_len;
1606 * where msg_len is used to record the length of total structure including LOCAL_PARA_HDR,
1607 * ref_count is used to record how many pointers reference to this structure, you must
1608 * hold it on saving a private copy and free it after clear the private copy.
1609 * (3) The initial reference count in local_para structure is 1. It is a common error to
1610 * memset the whole structure to 0, if you want to zero-initialize pdu, pass TD_RESET
1611 * in direction to do that.
1612 * SEE ALSO
1613 * free_local_para, hold_local_para, destroy_ilm, get_local_para_ptr
1614 ******************************************************************************/
1615#define construct_local_para(local_para_size, direction) \
1616 __construct_local_para(local_para_size, direction)
1617/*******************************************************************************
1618 * <GROUP Functions>
1619 *
1620 * FUNCTION
1621 * free_local_para
1622 * DESCRIPTION
1623 * decrease the local_para structure reference count, free the local_para if it reach 0.
1624 * PARAMETERS
1625 * local_para : [IN] local_para structure pointer.
1626 * RETURN VALUES
1627 * N/A
1628 * NOTE
1629 * (1)The prototype of this API is:
1630 * void free_local_para(local_para_struct *local_para_ptr);
1631 * (2)To pass user-defined local_para structure pointer to it, you need an explicit type-cast:
1632 * free_local_para((local_para_struct *)ptr_to_bt_connected_info);
1633 * SEE ALSO
1634 * construct_local_para, hold_local_para, destroy_ilm
1635 ******************************************************************************/
1636#define free_local_para(local_para) __free_local_para(local_para)
1637#define free_local_para_set_null(local_para) \
1638 do { \
1639 if (__free_local_para((local_para_struct *)local_para) == KAL_TRUE) \
1640 local_para = NULL; \
1641 } while (0)
1642#define free_local_para_r free_local_para
1643#define free_local_para_r_set_null free_local_para_set_null
1644/*******************************************************************************
1645 * <GROUP Functions>
1646 *
1647 * FUNCTION
1648 * construct_peer_buff
1649 * DESCRIPTION
1650 * allocate a peer_buff structure which has specified size in each part.
1651 * PARAMETERS
1652 * pdu_len: [IN] pdu size.
1653 * header_len: [IN] reserve size in header.
1654 * tail_len: [IN] reserve size in tail.
1655 * direction: [IN] ignored, use 0.
1656 * RETURNS
1657 * a peer_buff structure pointer. System enter fatal error handling if no enough memory.
1658 * NOTE
1659 * (1) the prototype of this API is:
1660 * void* construct_peer_buff(kal_uint16 pdu_len, kal_uint16 header_len, kal_uint16 tail_len,
1661 * transfer_direction direction);
1662 * (2) peer_buff is a opaque type which has reference count. Please use related API to manipulate it.
1663 * (3) The initial reference count in peer_buff structure is 1.
1664 * (4) It will use the size (pdu_len + header_len + tail_len + 8) to allocate buffer from control buffer pool.
1665 * SEE ALSO
1666 * free_peer_buff, hold_peer_buff, destroy_ilm, get_peer_buff_pdu, append_to_peer_buff,
1667 * prepend_to_peer_buff, remove_head_of_peer_buff, remove_tail_of_peer_buff, update_peer_buff_header
1668 ******************************************************************************/
1669#define construct_peer_buff(pdu_len, header_len, tail_len, direction) \
1670 __construct_peer_buff(pdu_len, header_len, tail_len, direction)
1671/*******************************************************************************
1672 * <GROUP Functions>
1673 *
1674 * FUNCTION
1675 * free_peer_buff
1676 * DESCRIPTION
1677 * decrease the peer_buff structure reference count, free the peer_buff if it reach 0.
1678 * PARAMETERS
1679 * peer_buff : [IN] peer_buff structure pointer.
1680 * RETURN VALUES
1681 * N/A
1682 * NOTE
1683 * (1)The prototype of this API is:
1684 * void free_peer_buff(peer_buff_struct *peer_buff_ptr);
1685 * SEE ALSO
1686 * construct_peer_buff, hold_peer_buff, destroy_ilm, get_peer_buff_pdu, append_to_peer_buff,
1687 * prepend_to_peer_buff, remove_head_of_peer_buff, remove_tail_of_peer_buff, update_peer_buff_header
1688 ******************************************************************************/
1689#define free_peer_buff(peer_buff) __free_peer_buff(peer_buff)
1690#define free_peer_buff_set_null(peer_buff) \
1691 do { \
1692 if (__free_peer_buff(peer_buff) == KAL_TRUE) \
1693 peer_buff = NULL; \
1694 } while (0)
1695#define free_peer_buff_r free_peer_buff
1696#define free_peer_buff_r_set_null free_peer_buff_set_null
1697
1698/*******************************************************************************
1699 * <GROUP Functions>
1700 *
1701 * FUNCTION
1702 * hold_local_para
1703 * DESCRIPTION
1704 * If local_para_ptr is not NULL, increment its reference counter by 1.
1705 * PARAMETERS
1706 * local_para_ptr : [IN] local_para structure pointer.
1707 * RETURN VALUES
1708 * KAL_TRUE if local_para_ptr is not NULL pointer, otherwise, KAL_FALSE.
1709 * NOTE
1710 * (1) To pass user-defined local_para structure pointer to it, you need an explicit type-cast:
1711 * hold_local_para((local_para_struct *)ptr_to_bt_connected_info);
1712 * SEE ALSO
1713 * construct_local_para, free_local_para, destroy_ilm
1714 ******************************************************************************/
1715extern kal_bool hold_local_para(local_para_struct *local_para_ptr);
1716#define hold_local_para_r hold_local_para
1717/*******************************************************************************
1718 * <GROUP Functions>
1719 *
1720 * FUNCTION
1721 * get_local_para_ptr
1722 * DESCRIPTION
1723 * retrieving start address & length of user-defined local_para structure.
1724 * PARAMETERS
1725 * local_para_ptr : [IN] local_para structure pointer.
1726 * local_para_len_ptr : [OUT] to store length. If it is NULL, the length is not stored.
1727 * RETURN VALUES
1728 * start address of user-defined local_para structure, It's equal to local_para_ptr.
1729 * NOTE
1730 * (1)To pass user-defined local_para structure pointer to it, you need an explicit type-cast:
1731 * get_local_para_ptr((local_para_struct *)ptr_to_bt_connected_info, &len);
1732 * SEE ALSO
1733 * construct_local_para
1734 ******************************************************************************/
1735void *get_local_para_ptr(local_para_struct *local_para_ptr,
1736 kal_uint16 * local_para_len_ptr);
1737/*******************************************************************************
1738 * <GROUP Functions>
1739 *
1740 * FUNCTION
1741 * hold_peer_buff
1742 * DESCRIPTION
1743 * If peer_buff_ptr is not NULL, increment its reference counter by 1.
1744 * PARAMETERS
1745 * peer_buff_ptr : [IN] peer_buff structure pointer.
1746 * RETURN VALUES
1747 * KAL_TRUE if peer_buff_ptr is not NULL pointer, otherwise, KAL_FALSE.
1748 * NOTE
1749 * N/A
1750 * SEE ALSO
1751 * construct_peer_buff, free_peer_buff, destroy_ilm
1752 ******************************************************************************/
1753extern kal_bool hold_peer_buff(peer_buff_struct *peer_buff_ptr);
1754#define hold_peer_buff_r hold_peer_buff
1755/*******************************************************************************
1756 * <GROUP Functions>
1757 *
1758 * FUNCTION
1759 * get_peer_buff_pdu
1760 * DESCRIPTION
1761 * retrieving start address & length of pdu in peer buffer.
1762 * PARAMETERS
1763 * peer_buff_ptr : [IN] peer_buff structure pointer.
1764 * length_ptr : [OUT] to store pdu's length. If it is NULL, the length is not stored.
1765 * RETURN VALUES
1766 * start address of pdu in peer buffer.
1767 * SEE ALSO
1768 * construct_peer_buff, free_peer_buff, hold_peer_buff, destroy_ilm, append_to_peer_buff,
1769 * prepend_to_peer_buff, remove_head_of_peer_buff, remove_tail_of_peer_buff, update_peer_buff_header
1770 ******************************************************************************/
1771void *get_peer_buff_pdu(peer_buff_struct *peer_buff_ptr, kal_uint16 *length_ptr);
1772/*******************************************************************************
1773 * <GROUP Functions>
1774 *
1775 * FUNCTION
1776 * prepend_to_peer_buff
1777 * DESCRIPTION
1778 * prepend data to head of peer_buff. On success, pdu length increases header_len bytes,
1779 * and free space at head decreases header_len bytes.
1780 * PARAMETERS
1781 * peer_buff_ptr : [IN] peer_buff structure pointer.
1782 * header_data_ptr : [IN] data appended.
1783 * header_len : [IN] length of data appended.
1784 * RETURN VALUES
1785 * N/A
1786 * NOTE
1787 * If the free head room is smaller than header_len, system enter fatal error handling.
1788 * SEE ALSO
1789 * construct_peer_buff, free_peer_buff, hold_peer_buff, destroy_ilm, get_peer_buff_pdu,
1790 * append_to_peer_buff, remove_head_of_peer_buff, remove_tail_of_peer_buff, update_peer_buff_header
1791 ******************************************************************************/
1792extern void prepend_to_peer_buff(peer_buff_struct *peer_buff_ptr,
1793 void *header_data_ptr, kal_uint16 header_len);
1794/*******************************************************************************
1795 * <GROUP Functions>
1796 *
1797 * FUNCTION
1798 * append_to_peer_buff
1799 * DESCRIPTION
1800 * append data to tail of peer_buff, On success, pdu length increases tail_len bytes,
1801 * and free space at tail decreases tail_len bytes.
1802 * PARAMETERS
1803 * peer_buff_ptr : [IN] peer_buff structure pointer.
1804 * tail_data_ptr : [IN] data appended.
1805 * tail_len : [IN] length of data appended.
1806 * RETURN VALUES
1807 * N/A
1808 * NOTE
1809 * If the free tail room is smaller than tail_len, system enter fatal error handling.
1810 * SEE ALSO
1811 * construct_peer_buff, free_peer_buff, hold_peer_buff, destroy_ilm, get_peer_buff_pdu,
1812 * prepend_to_peer_buff, remove_head_of_peer_buff, remove_tail_of_peer_buff, update_peer_buff_header
1813 ******************************************************************************/
1814extern void append_to_peer_buff(peer_buff_struct *peer_buff_ptr, void *tail_data_ptr,
1815 kal_uint16 tail_len);
1816/*******************************************************************************
1817 * <GROUP Functions>
1818 *
1819 * FUNCTION
1820 * remove_head_of_peer_buff
1821 * DESCRIPTION
1822 * remove data at head of peer_buff. On success, pdu length decreases head_len bytes,
1823 * and free space at head increases head_len bytes.
1824 * PARAMETERS
1825 * peer_buff_ptr : [IN] peer_buff structure pointer.
1826 * head_len : [IN] length of data to remove.
1827 * RETURN VALUES
1828 * N/A
1829 * NOTE
1830 * (1)If the pdu size is smaller than head_len, system enter fatal error handling.
1831 * (2)This API replaces remove_hdr_of_peer_buff(). And remove_hdr_of_peer_buff() is deprecated,
1832 * it will be removed from next release.
1833 * SEE ALSO
1834 * construct_peer_buff, free_peer_buff, hold_peer_buff, destroy_ilm, get_peer_buff_pdu,
1835 * prepend_to_peer_buff, append_to_peer_buff, remove_tail_of_peer_buff, update_peer_buff_header
1836 ******************************************************************************/
1837extern void remove_head_of_peer_buff(peer_buff_struct *peer_buff_ptr,
1838 kal_uint16 head_len);
1839/*******************************************************************************
1840 * <GROUP Functions>
1841 *
1842 * FUNCTION
1843 * remove_tail_of_peer_buff
1844 * DESCRIPTION
1845 * remove data at tail of peer_buff. On success, pdu length decreases tail_len bytes,
1846 * and free space at tail increases tail_len bytes.
1847 * PARAMETERS
1848 * peer_buff_ptr : [IN] peer_buff structure pointer.
1849 * tail_len : [IN] length of data to remove.
1850 * RETURN VALUES
1851 * N/A
1852 * NOTE
1853 * If the pdu size is smaller than tail_len, system enter fatal error handling.
1854 * SEE ALSO
1855 * construct_peer_buff, free_peer_buff, hold_peer_buff, destroy_ilm, get_peer_buff_pdu,
1856 * prepend_to_peer_buff, append_to_peer_buff, remove_head_of_peer_buff, update_peer_buff_header
1857 ******************************************************************************/
1858extern void remove_tail_of_peer_buff(peer_buff_struct *peer_buff_ptr,
1859 kal_uint16 tail_len);
1860/*******************************************************************************
1861 * <GROUP Functions>
1862 *
1863 * FUNCTION
1864 * update_peer_buff_header
1865 * DESCRIPTION
1866 * Reinitialize peer buffer, reset size of free header space, pdu, free tail space to new values.
1867 * PARAMETERS
1868 * peer_buff_ptr : [IN] peer_buff structure pointer.
1869 * new_head_len : [IN] new head size after update.
1870 * new_pdu_len : [IN] new pdu size after update.
1871 * new_tail_len : [IN] new tail size after update.
1872 * RETURN VALUES
1873 * N/A
1874 * NOTE
1875 * (1)If total size is bigger than original size, system enter fatal error handling.
1876 * SEE ALSO
1877 * construct_peer_buff, free_peer_buff, hold_peer_buff, destroy_ilm, get_peer_buff_pdu,
1878 * prepend_to_peer_buff, append_to_peer_buff, remove_head_of_peer_buff, remove_tail_of_peer_buff
1879 ******************************************************************************/
1880extern void update_peer_buff_header(peer_buff_struct *peer_buff_ptr,
1881 kal_uint16 new_head_len, kal_uint16 new_pdu_len,
1882 kal_uint16 new_tail_len);
1883
1884/*******************************************************************************
1885 * <GROUP Functions>
1886 *
1887 * FUNCTION
1888 * msg_send_ext_queue
1889 * DESCRIPTION
1890 * send a ILM message to tail of destination task's ext queue.
1891 * PARAMETERS
1892 * ilm_ptr : [IN] the ILM message to be sent.
1893 * RETURN VALUES
1894 * N/A
1895 * NOTE
1896 * (1) The ILM messages is appended to tail of the queue.
1897 * (2) If the destination queue is full, system enter fatal error handling.
1898 * (3) The use of allocate_ilm()/cancel_ilm() is deprecated,
1899 * (4) Recommend use msg_send() , msg_send6() series, use this function as
1900 * last choice for special condition
1901 * SEE ALSO
1902 * msg_send_to_head, msg_send6, msg_send_to_head6
1903 ******************************************************************************/
1904kal_bool msg_send_ext_queue(ilm_struct *ilm_ptr);
1905
1906/*******************************************************************************
1907 * <GROUP Functions>
1908 *
1909 * FUNCTION
1910 * msg_send
1911 * DESCRIPTION
1912 * send a ILM message to tail of destination task's queue.
1913 * Refer to NOTE about which queue (extq or intq) the message sent to.
1914 * PARAMETERS
1915 * ilm_ptr : [IN] the ILM message to be sent.
1916 * RETURN VALUES
1917 * N/A
1918 * NOTE
1919 * (1) This API select queue based on following criteria:
1920 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
1921 * internal queue of the task is not NULL, the message is sent to internal queue.
1922 * b. Otherwise, the message is sent to external queue.
1923 * (2) The ILM messages is appended to tail of the queue.
1924 * (3) If the destination queue is full, system enter fatal error handling.
1925 * (4) The use of allocate_ilm()/cancel_ilm() is deprecated,
1926 * SEE ALSO
1927 * msg_send_to_head, msg_send6, msg_send_to_head6
1928 ******************************************************************************/
1929kal_bool msg_send(ilm_struct *ilm_ptr);
1930
1931/*******************************************************************************
1932 * <GROUP Functions>
1933 *
1934 * FUNCTION
1935 * msg_send_custom
1936 * DESCRIPTION
1937 * send a ILM message to tail of destination task's queue.
1938 * Refer to NOTE about which queue (extq or intq) the message sent to.
1939 * Selectable custom DHL logging option.
1940 * PARAMETERS
1941 * ilm_ptr : [IN] the ILM message to be sent.
1942 * log_option : [IN] the custom logging to be used.
1943 * RETURN VALUES
1944 * N/A
1945 * NOTE
1946 * (1) This API select queue based on following criteria:
1947 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
1948 * internal queue of the task is not NULL, the message is sent to internal queue.
1949 * b. Otherwise, the message is sent to external queue.
1950 * (2) The ILM messages is appended to tail of the queue.
1951 * (3) If the destination queue is full, system enter fatal error handling.
1952 * (4) The use of allocate_ilm()/cancel_ilm() is deprecated,
1953 * (5) Only use this if custom DHL logging is needed for the ILM. Normally use msg_send
1954 * SEE ALSO
1955 * msg_send_to_head, msg_send6, msg_send_to_head6
1956 ******************************************************************************/
1957#if defined(__DHL_MODULE__)
1958kal_bool msg_send_custom(ilm_struct *ilm_ptr, e_custom_ilm_trace_option log_option);
1959#else
1960#define msg_send_custom(ip, lo) msg_send((ip))
1961#endif
1962
1963/*******************************************************************************
1964 * <GROUP Functions>
1965 *
1966 * FUNCTION
1967 * msg_send_adt
1968 * DESCRIPTION
1969 * send a ILM message to tail of destination task's queue.
1970 * sender provide translator callback to translate user defined structure
1971 * in ILM local/peer parameter to ADT for logging.
1972 * sender provide free callback to free user defined structure in ILM
1973 * local/peer parameter when the ILM is trapped during UT.
1974 * Refer to NOTE about which queue (extq or intq) the message sent to.
1975 * PARAMETERS
1976 * ilm_ptr : [IN] the ILM message to be sent.
1977 * translator_cb : [IN] translator callback to translate user defined structure to ADT
1978 * free_cb : [IN] free callback to free user defined structure
1979 * RETURN VALUES
1980 * N/A
1981 * NOTE
1982 * (1) This API select queue based on following criteria:
1983 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
1984 * internal queue of the task is not NULL, the message is sent to internal queue.
1985 * b. Otherwise, the message is sent to external queue.
1986 * (2) The ILM messages is appended to tail of the queue.
1987 * (3) If the destination queue is full, system enter fatal error handling.
1988 * (4) This API replaces msg_send_ext_queue/msg_send_int_queue().
1989 * They will be removed from next release.
1990 * (5) The use of allocate_ilm()/cancel_ilm() is deprecated,
1991 * They will be removed from next release.
1992 * (6) If using the msg_send_adt has error, replace msg_send_adt with msg_send
1993 * and test again. If the msg_send is OK but msg_send_adt is not, please
1994 * contact the adt provider(TST/DHL module owner)
1995 * SEE ALSO
1996 * msg_send_to_head, msg_send6, msg_send_to_head6
1997 ******************************************************************************/
1998#ifdef __TST_MODULE__
1999kal_bool msg_send_adt(ilm_struct * ilm_ptr,
2000 translator_adt_enc_callback_t translator_cb,
2001 ilm_free_callback_t free_cb);
2002#else /* else of __TST_MODULE__ */
2003#define msg_send_adt(ilm_ptr, translator_cb, free_cb) msg_send(ilm_ptr)
2004#endif /* end of "else of __TST_MODULE__" */
2005
2006/*******************************************************************************
2007 * <GROUP Functions>
2008 *
2009 * FUNCTION
2010 * msg_send_to_int_head
2011 * DESCRIPTION
2012 * send a ILM message to head of destination task's internal queue.
2013 * PARAMETERS
2014 * ilm_ptr : [IN] the ILM message to be sent.
2015 * RETURN VALUES
2016 * N/A
2017 * NOTE
2018 * (1) If the ILM is sent to external queue, system enter fatal error handling.
2019 * It uses similar logic as msg_send to select queue based on following criteria:
2020 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to different tasks,
2021 * then enter error handling.
2022 * b. Otherwise, the message is sent to head of internal queue.
2023 * (2) If the destination queue is full, system enter fatal error handling.
2024 * SEE ALSO
2025 * msg_send_to_int_head6
2026 ******************************************************************************/
2027kal_bool msg_send_to_int_head(ilm_struct *ilm_ptr);
2028
2029/*******************************************************************************
2030 * <GROUP Functions>
2031 *
2032 * FUNCTION
2033 * msg_send_to_head
2034 * DESCRIPTION
2035 * send a ILM message to head of destination task's external queue.
2036 * PARAMETERS
2037 * ilm_ptr : [IN] the ILM message to be sent.
2038 * RETURN VALUES
2039 * N/A
2040 * NOTE
2041 * (1) If the ILM is sent to internal queue, system enter fatal error handling.
2042 * It uses similar logic as msg_send to select queue based on following criteria:
2043 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
2044 * internal queue of the task is not NULL, then enter error handling.
2045 * b. Otherwise, the message is sent to head of external queue.
2046 * (2) If the destination queue is full, system enter fatal error handling.
2047 * SEE ALSO
2048 * msg_send, msg_send6, msg_send_to_head6
2049 ******************************************************************************/
2050kal_bool msg_send_to_head(ilm_struct *ilm_ptr);
2051
2052/*******************************************************************************
2053 * <GROUP Functions>
2054 *
2055 * FUNCTION
2056 * msg_send_to_int_head6
2057 * DESCRIPTION
2058 * send a ILM message to head of destination task's internal queue.
2059 * this function is the same as msg_send_to_int_head except assigning content of ilm directly.
2060 * PARAMETERS
2061 * src_mod_id : [IN] source module id.
2062 * dest_mod_id : [IN] destination module id.
2063 * sap_id : [IN] service access point id.
2064 * msg_id : [IN] message id.
2065 * local_para_ptr : [IN] local_para structure pointer.
2066 * peer_buff_ptr : [IN] peer_buff structure pointer.
2067 * RETURN VALUES
2068 * N/A
2069 * NOTE
2070 * SEE ALSO
2071 * msg_send_to_int_head
2072 ******************************************************************************/
2073kal_bool msg_send_to_int_head6(module_type _src_mod_id, module_type _dest_mod_id,
2074 sap_type _sap_id, msg_type _msg_id,
2075 local_para_struct *_local_para_ptr,
2076 peer_buff_struct * _peer_buff_ptr);
2077
2078/*******************************************************************************
2079 * <GROUP Functions>
2080 *
2081 * FUNCTION
2082 * msg_send6
2083 * DESCRIPTION
2084 * send a ILM message to tail of destination task's queue.
2085 * Refer to NOTE about which queue (extq or intq) the message sent to.
2086 * PARAMETERS
2087 * src_mod_id : [IN] source module id.
2088 * dest_mod_id : [IN] destination module id.
2089 * sap_id : [IN] service access point id.
2090 * msg_id : [IN] message id.
2091 * local_para_ptr : [IN] local_para structure pointer.
2092 * peer_buff_ptr : [IN] peer_buff structure pointer.
2093 * RETURN VALUES
2094 * N/A
2095 * NOTE
2096 * (1) This API select queue based on following criteria:
2097 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
2098 * internal queue of the task is not NULL, the message is sent to internal queue.
2099 * b. Otherwise, the message is sent to external queue.
2100 * (2) The ILM messages is appended to tail of the queue.
2101 * (3) If the destination queue is full, system enter fatal error handling.
2102 * (4) This API replaces msg_send_ext_queue/msg_send_int_queue().
2103 * (5) The use of allocate_ilm()/cancel_ilm() is deprecated,
2104 * SEE ALSO
2105 * msg_send, msg_send4, msg_send5, msg_send_to_head, msg_send_to_head6
2106 ******************************************************************************/
2107kal_bool msg_send6(module_type _src_mod_id, module_type _dest_mod_id,
2108 sap_type _sap_id, msg_type _msg_id,
2109 local_para_struct *_local_para_ptr,
2110 peer_buff_struct * _peer_buff_ptr);
2111
2112/*******************************************************************************
2113 * <GROUP Functions>
2114 *
2115 * FUNCTION
2116 * msg_send6_custom
2117 * DESCRIPTION
2118 * send a ILM message to tail of destination task's queue.
2119 * Refer to NOTE about which queue (extq or intq) the message sent to.
2120 * Selectable custom DHL logging option.
2121 * PARAMETERS
2122 * src_mod_id : [IN] source module id.
2123 * dest_mod_id : [IN] destination module id.
2124 * sap_id : [IN] service access point id.
2125 * msg_id : [IN] message id.
2126 * local_para_ptr : [IN] local_para structure pointer.
2127 * peer_buff_ptr : [IN] peer_buff structure pointer.
2128 * log_option : [IN] the custom logging to be used.
2129 * RETURN VALUES
2130 * N/A
2131 * NOTE
2132 * (1) This API select queue based on following criteria:
2133 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
2134 * internal queue of the task is not NULL, the message is sent to internal queue.
2135 * b. Otherwise, the message is sent to external queue.
2136 * (2) The ILM messages is appended to tail of the queue.
2137 * (3) If the destination queue is full, system enter fatal error handling.
2138 * (4) This API replaces msg_send_ext_queue/msg_send_int_queue().
2139 * (5) The use of allocate_ilm()/cancel_ilm() is deprecated,
2140 * (6) Only use this if custom DHL logging is needed for the ILM. Normally use msg_send
2141 * SEE ALSO
2142 * msg_send, msg_send4, msg_send5, msg_send_to_head, msg_send_to_head6
2143 ******************************************************************************/
2144#if defined(__DHL_MODULE__)
2145kal_bool msg_send6_custom(module_type _src_mod_id, module_type _dest_mod_id,
2146 sap_type _sap_id, msg_type _msg_id,
2147 local_para_struct * _local_para_ptr,
2148 peer_buff_struct * _peer_buff_ptr,
2149 e_custom_ilm_trace_option log_option);
2150#else
2151#define msg_send6_custom(sm, dm, si, mi, lp, pb, lo) \
2152 msg_send6((sm), (dm), (si), (mi), (lp), (pb))
2153#endif
2154
2155/*******************************************************************************
2156 * <GROUP Functions>
2157 *
2158 * FUNCTION
2159 * msg_send5
2160 * DESCRIPTION
2161 * same with msg_send6 with _peer_buff_ptr = NULL.
2162 * NOTE
2163 * SEE ALSO
2164 * msg_send, msg_send4, msg_send6
2165 ******************************************************************************/
2166kal_bool msg_send5(module_type _src_mod_id, module_type _dest_mod_id,
2167 sap_type _sap_id, msg_type _msg_id,
2168 local_para_struct *_local_para_ptr);
2169/*******************************************************************************
2170 * <GROUP Functions>
2171 *
2172 * FUNCTION
2173 * msg_send4
2174 * DESCRIPTION
2175 * same with msg_send6 with _local_para_ptr = NULL & _peer_buff_ptr = NULL.
2176 * SEE ALSO
2177 * msg_send, msg_send5, msg_send6
2178 ******************************************************************************/
2179kal_bool msg_send4(module_type _src_mod_id, module_type _dest_mod_id,
2180 sap_type _sap_id, msg_type _msg_id);
2181/*******************************************************************************
2182 * <GROUP Functions>
2183 *
2184 * FUNCTION
2185 * msg_send_to_head6
2186 * DESCRIPTION
2187 * send a ILM message to head of destination task's queue.
2188 * PARAMETERS
2189 * src_mod_id : [IN] source module id.
2190 * dest_mod_id : [IN] destination module id.
2191 * sap_id : [IN] service access point id.
2192 * msg_id : [IN] message id.
2193 * local_para_ptr : [IN] local_para structure pointer.
2194 * peer_buff_ptr : [IN] peer_buff structure pointer.
2195 * RETURN VALUES
2196 * N/A
2197 * NOTE
2198 * (1) If the ILM is sent to internal queue, system enter fatal error handling.
2199 * It uses same logic as msg_send to select queue based on following criteria:
2200 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
2201 * internal queue of the task is not NULL, the message is sent to internal queue.
2202 * b. Otherwise, the message is sent to external queue.
2203 * (2) If the destination queue is full, system enter fatal error handling.
2204 * (3) This API replaces msg_send_ext_queue_to_head().
2205 * (4) The use of allocate_ilm()/cancel_ilm() is deprecated,
2206 * SEE ALSO
2207 * msg_send, msg_send6, msg_send_to_head
2208 ******************************************************************************/
2209kal_bool msg_send_to_head6(module_type _src_mod_id, module_type _dest_mod_id,
2210 sap_type _sap_id, msg_type _msg_id,
2211 local_para_struct *_local_para_ptr,
2212 peer_buff_struct * _peer_buff_ptr);
2213/*******************************************************************************
2214 * <GROUP Functions>
2215 *
2216 * FUNCTION
2217 * msg_send_to_head5
2218 * DESCRIPTION
2219 * same with msg_send_to_head6 with _peer_buff_ptr = NULL.
2220 * NOTE
2221 * SEE ALSO
2222 * msg_send_to_head, msg_send_to_head4, msg_send_to_head6
2223 ******************************************************************************/
2224kal_bool msg_send_to_head5(module_type _src_mod_id, module_type _dest_mod_id,
2225 sap_type _sap_id, msg_type _msg_id,
2226 local_para_struct *_local_para_ptr);
2227/*******************************************************************************
2228 * <GROUP Functions>
2229 *
2230 * FUNCTION
2231 * msg_send_to_head4
2232 * DESCRIPTION
2233 * same with msg_send_to_head6 with _local_para_ptr = NULL & _peer_buff_ptr = NULL.
2234 * NOTE
2235 * SEE ALSO
2236 * msg_send_to_head, msg_send_to_head5, msg_send_to_head6
2237 ******************************************************************************/
2238kal_bool msg_send_to_head4(module_type _src_mod_id, module_type _dest_mod_id,
2239 sap_type _sap_id, msg_type _msg_id);
2240
2241/******************************************************************************
2242*
2243 * <GROUP Functions>
2244 *
2245 * FUNCTION
2246 * msg_send_inline6
2247 * DESCRIPTION
2248 * send a inline-ILM message to tail of destination task's queue.
2249 * Refer to NOTE about which queue (extq or intq) the message sent to.
2250 * PARAMETERS
2251 * src_mod_id : [IN] source module id.
2252 * dest_mod_id : [IN] destination module id.
2253 * sap_id : [IN] service access point id.
2254 * msg_id : [IN] message id.
2255 * data : [IN] data to be copy in inline-ILM.
2256 * datalen : [IN] data length, it's maximum value is MSG_INLINE_ILM_MAX_PAYLOAD.
2257 * RETURN VALUES
2258 * N/A
2259 * NOTE
2260 * (1) This API select queue based on following criteria:
2261 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
2262 * internal queue of the task is not NULL, the message is sent to internal queue.
2263 * b. Otherwise, the message is sent to external queue.
2264 * (2) The ILM messages is appended to tail of the queue.
2265 * (3) If the destination queue is full, system enter fatal error handling.
2266 * (4) The inline data length specified by datalen is not recorded in destination ILM messages.
2267 * Its user's responsibility to know what the inline data is.
2268 * (5) The use of allocate_ilm()/cancel_ilm() is deprecated,
2269 * SEE ALSO
2270 * msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5,
2271 * msg_is_inline, msg_get_inline_data
2272 * msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
2273 * msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
2274
2275******************************************************************************/
2276kal_bool msg_send_inline6(module_type src_mod, module_type dest_mod, sap_type sap_id,
2277 msg_type msg_id, void *data, kal_uint32 datalen);
2278
2279/******************************************************************************
2280*
2281 * <GROUP Functions>
2282 *
2283 * FUNCTION
2284 * msg_send_inline_to_head6
2285 * DESCRIPTION
2286 * send a ILM message to head of destination task's queue.
2287 * PARAMETERS
2288 * src_mod_id : [IN] source module id.
2289 * dest_mod_id : [IN] destination module id.
2290 * sap_id : [IN] service access point id.
2291 * msg_id : [IN] message id.
2292 * data : [IN] data to be copy in inline-ILM.
2293 * datalen : [IN] data length, it's maximum value is MSG_INLINE_ILM_MAX_PAYLOAD.
2294 * RETURN VALUES
2295 * N/A
2296 * NOTE
2297 * (1) If the ILM is sent to internal queue, system enter fatal error handling.
2298 * It uses same logic as msg_send to select queue based on following criteria:
2299 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
2300 * internal queue of the task is not NULL, the message is sent to internal queue.
2301 * b. Otherwise, the message is sent to external queue.
2302 * (2) If the destination queue is full, system enter fatal error handling.
2303 * (3) The inline data length specified by datalen is not recorded in destination ILM messages.
2304 * Its user's responsibility to know what the inline data is.
2305 * (4) The use of allocate_ilm()/cancel_ilm() is deprecated,
2306 * SEE ALSO
2307 * msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5,
2308 * msg_is_inline, msg_get_inline_data
2309 * msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6,msg_send_8bytes_inline_to_head6
2310 * msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
2311
2312******************************************************************************/
2313kal_bool msg_send_inline_to_head6(module_type src_mod, module_type dest_mod,
2314 sap_type sap_id, msg_type msg_id, void *data,
2315 kal_uint32 datalen);
2316
2317
2318/*******************************************************************************
2319 * <GROUP Functions>
2320 *
2321 * FUNCTION
2322 * msg_send_inline5
2323 * DESCRIPTION
2324 * send a inline-ILM message to tail of destination task's queue.
2325 * Refer to NOTE about which queue (extq or intq) the message sent to.
2326 * PARAMETERS
2327 * src_mod_id : [IN] source module id.
2328 * dest_mod_id : [IN] destination module id.
2329 * msg_id : [IN] message id.
2330 * data : [IN] data to be copy in inline-ILM.
2331 * datalen : [IN] data length, it's maximum value is MSG_INLINE_ILM_MAX_PAYLOAD.
2332 * RETURN VALUES
2333 * N/A
2334 * NOTE
2335 * (1) This API select queue based on following criteria:
2336 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
2337 * internal queue of the task is not NULL, the message is sent to internal queue.
2338 * b. Otherwise, the message is sent to external queue.
2339 * (2) The ILM messages is appended to tail of the queue.
2340 * (3) If the destination queue is full, system enter fatal error handling.
2341 * (4) The inline data length specified by datalen is not recorded in destination ILM messages.
2342 * Its user's responsibility to know what the inline data is.
2343 * (5) The use of allocate_ilm()/cancel_ilm() is deprecated,
2344 * SEE ALSO
2345 * msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5,
2346 * msg_is_inline, msg_get_inline_data
2347 * msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
2348 * msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
2349
2350******************************************************************************/
2351#define msg_send_inline5(src_mod, dest_mod, msg_id, data, datalen) \
2352 msg_send_inline6(src_mod, dest_mod, INLINE_ILM_SAP, msg_id, data, datalen)
2353
2354/*******************************************************************************
2355 * <GROUP Functions>
2356 *
2357 * FUNCTION
2358 * msg_send_inline_to_head5
2359 * DESCRIPTION
2360 * send a ILM message to head of destination task's queue.
2361 * PARAMETERS
2362 * src_mod_id : [IN] source module id.
2363 * dest_mod_id : [IN] destination module id.
2364 * msg_id : [IN] message id.
2365 * data : [IN] data to be copy in inline-ILM.
2366 * datalen : [IN] data length, it's maximum value is MSG_INLINE_ILM_MAX_PAYLOAD.
2367 * RETURN VALUES
2368 * N/A
2369 * NOTE
2370 * (1) If the ILM is sent to internal queue, system enter fatal error handling.
2371 * It uses same logic as msg_send to select queue based on following criteria:
2372 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
2373 * internal queue of the task is not NULL, the message is sent to internal queue.
2374 * b. Otherwise, the message is sent to external queue.
2375 * (2) If the destination queue is full, system enter fatal error handling.
2376 * (3) The inline data length specified by datalen is not recorded in destination ILM messages.
2377 * Its user's responsibility to know what the inline data is.
2378 * (4) The use of allocate_ilm()/cancel_ilm() is deprecated,
2379 * SEE ALSO
2380 * msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5,
2381 * msg_is_inline, msg_get_inline_data
2382 * msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
2383 * msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
2384
2385******************************************************************************/
2386#define msg_send_inline_to_head5(src_mod, dest_mod, sap_id, msg_id, data, datalen) \
2387 msg_send_inline_to_head6(src_mod, dest_mod, INLINE_ILM_SAP, msg_id, data, \
2388 datalen)
2389
2390/******************************************************************************
2391*
2392 * <GROUP Functions>
2393 *
2394 * FUNCTION
2395 * msg_send_8bytes_inline6
2396 * DESCRIPTION
2397 * send a inline-ILM message to tail of destination task's queue.
2398 * Refer to NOTE about which queue (extq or intq) the message sent to.
2399 * PARAMETERS
2400 * src_mod_id : [IN] source module id.
2401 * dest_mod_id : [IN] destination module id.
2402 * sap_id : [IN] service access point id.
2403 * msg_id : [IN] message id.
2404 * data1 : [IN] first 4-byte data to be copy in inline-ILM.
2405 * data2 : [IN] second 4-byte data to be copy in inline-ILM.
2406 * RETURN VALUES
2407 * N/A
2408 * NOTE
2409 * (1) This API select queue based on following criteria:
2410 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
2411 * internal queue of the task is not NULL, the message is sent to internal queue.
2412 * b. Otherwise, the message is sent to external queue.
2413 * (2) The ILM messages is appended to tail of the queue.
2414 * (3) If the destination queue is full, system enter fatal error handling.
2415 * (4) The use of allocate_ilm()/cancel_ilm() is deprecated,
2416 * (5) The inline data length is not recorded in destination ILM messages.
2417 * Its user's responsibility to know what the inline data is.
2418 * SEE ALSO
2419 * msg_send, msg_send6, msg_send_to_head6, msg_send_inline5,msg_send_inline_tp_head5,
2420 * msg_is_inline, msg_get_inline_data
2421 * msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
2422 * msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
2423
2424******************************************************************************/
2425kal_bool msg_send_8bytes_inline6(module_type src_mod, module_type dest_mod,
2426 sap_type sap_id, msg_type msg_id, kal_uint32 data1,
2427 kal_uint32 data2);
2428
2429/******************************************************************************
2430*
2431 * <GROUP Functions>
2432 *
2433 * FUNCTION
2434 * msg_send_8bytes_inline6_custom
2435 * DESCRIPTION
2436 * send a inline-ILM message to tail of destination task's queue.
2437 * Refer to NOTE about which queue (extq or intq) the message sent to.
2438 * Uses custom logging based on the logging option.
2439 * PARAMETERS
2440 * src_mod_id : [IN] source module id.
2441 * dest_mod_id : [IN] destination module id.
2442 * sap_id : [IN] service access point id.
2443 * msg_id : [IN] message id.
2444 * data1 : [IN] first 4-byte data to be copy in inline-ILM.
2445 * data2 : [IN] second 4-byte data to be copy in inline-ILM.
2446 * log_option : [IN] custom logging option
2447 * RETURN VALUES
2448 * N/A
2449 * NOTE
2450 * (1) This API select queue based on following criteria:
2451 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
2452 * internal queue of the task is not NULL, the message is sent to internal queue.
2453 * b. Otherwise, the message is sent to external queue.
2454 * (2) The ILM messages is appended to tail of the queue.
2455 * (3) If the destination queue is full, system enter fatal error handling.
2456 * (4) The use of allocate_ilm()/cancel_ilm() is deprecated,
2457 * (5) The inline data length is not recorded in destination ILM messages.
2458 * Its user's responsibility to know what the inline data is.
2459 * SEE ALSO
2460 * msg_send, msg_send6, msg_send_to_head6, msg_send_inline5,msg_send_inline_tp_head5,
2461 * msg_is_inline, msg_get_inline_data
2462 * msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
2463 * msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
2464
2465******************************************************************************/
2466#if defined(__DHL_MODULE__)
2467kal_bool msg_send_8bytes_inline6_custom(module_type src_mod, module_type dest_mod,
2468 sap_type sap_id, msg_type msg_id,
2469 kal_uint32 data1, kal_uint32 data2,
2470 e_custom_ilm_trace_option log_option);
2471#else
2472#define msg_send_8bytes_inline6_custom(sm, dm, si, mi, d1, d2, lo) \
2473 msg_send_8bytes_inline6((sm), (dm), (si), (mi), (d1), (d2))
2474#endif
2475
2476
2477/******************************************************************************
2478*
2479 * <GROUP Functions>
2480 *
2481 * FUNCTION
2482 * msg_send_8bytes_inline_to_head6
2483 * DESCRIPTION
2484 * send a ILM message to head of destination task's queue.
2485 * PARAMETERS
2486 * src_mod_id : [IN] source module id.
2487 * dest_mod_id : [IN] destination module id.
2488 * sap_id : [IN] service access point id.
2489 * msg_id : [IN] message id.
2490 * data1 : [IN] first 4-byte data to be copy in inline-ILM.
2491 * data2 : [IN] second 4-byte data to be copy in inline-ILM.
2492 * RETURN VALUES
2493 * N/A
2494 * NOTE
2495 * (1) If the ILM is sent to internal queue, system enter fatal error handling.
2496 * It uses same logic as msg_send to select queue based on following criteria:
2497 * a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task,and the
2498 * internal queue of the task is not NULL, the message is sent to internal queue.
2499 * b. Otherwise, the message is sent to external queue.
2500 * (2) If the destination queue is full, system enter fatal error handling.
2501 * (3) The use of allocate_ilm()/cancel_ilm() is deprecated,
2502 * (4) The inline data length is not recorded in destination ILM messages.
2503 * Its user's responsibility to know what the inline data is.
2504 * SEE ALSO
2505 * msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5,
2506 * msg_is_inline, msg_get_inline_data
2507 * msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
2508 * msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
2509
2510******************************************************************************/
2511kal_bool msg_send_8bytes_inline_to_head6(module_type src_mod, module_type dest_mod,
2512 sap_type sap_id, msg_type msg_id,
2513 kal_uint32 data1, kal_uint32 data2);
2514
2515/******************************************************************************
2516*
2517 * <GROUP Functions>
2518 *
2519 * FUNCTION
2520 * msg_get_inline_4bytes_data1
2521 * DESCRIPTION
2522 * Get the inline first 4-byte data value in ILM message.
2523 * PARAMETERS
2524 * ilm_ptr : [IN] ILM message pointer.
2525 * RETURN VALUES
2526 * First 4-byte data value. If it's not an inline-ILM, system enter fatal error handling.
2527 * NOTE
2528 * (1) Users must pass a inline-ILM to this function.
2529 * (2) The inline data length is not recorded in ILM messages.
2530 * Its user's responsibility to know what the inline data is.
2531 *
2532 * SEE ALSO
2533 * msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5,
2534 * msg_is_inline, msg_get_inline_data
2535 * msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6,msg_send_8bytes_inline_to_head6
2536 * msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
2537
2538******************************************************************************/
2539kal_uint32 msg_get_inline_4bytes_data1(ilm_struct *ilm_ptr);
2540
2541/******************************************************************************
2542*
2543 * <GROUP Functions>
2544 *
2545 * FUNCTION
2546 * msg_get_inline_4bytes_data2
2547 * DESCRIPTION
2548 * Get the inline second 4-byte data value in ILM message.
2549 * PARAMETERS
2550 * ilm_ptr : [IN] ILM message pointer.
2551 * RETURN VALUES
2552 * Second 4-byte data value. If it's not an inline-ILM, system enter fatal error handling.
2553 * NOTE
2554 * (1) Users must pass a inline-ILM to this function.
2555 * (2) The inline data length is not recorded in ILM messages.
2556 * Its user's responsibility to know what the inline data is.
2557 *
2558 * SEE ALSO
2559 * msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5,
2560 * msg_is_inline, msg_get_inline_data
2561 * msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
2562 * msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
2563
2564******************************************************************************/
2565kal_uint32 msg_get_inline_4bytes_data2(ilm_struct *ilm_ptr);
2566
2567/*******************************************************************************
2568 * <GROUP Functions>
2569 *
2570 * FUNCTION
2571 * msg_is_inline
2572 * DESCRIPTION
2573 * judge whether is a inline-ILM or not.
2574 * PARAMETERS
2575 * ilm_ptr : [IN] ILM message pointer.
2576 * RETURN VALUES
2577 * KAL_TRUE : this is a inline-ILM.
2578 * KAL_FALSE : this isn't a inline-ILM.
2579 * NOTE
2580 * (1) The prototype of this API is:
2581 * kal_bool msg_is_inline(ilm_struct *ilm_ptr);
2582 * (2) inline-ILM is identified by sap_id, always use this API to do this, never use
2583 * sap_id comparison directly since this will change in future.
2584 * SEE ALSO
2585 * msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5,
2586 * msg_is_inline, msg_get_inline_data
2587 * msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
2588 * msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
2589
2590******************************************************************************/
2591#define msg_is_inline(ilm_ptr) \
2592 (((ilm_ptr)->sap_id & (INLINE_ILM_FLAG_SAP | INLINE_CUSTOM_ILM_FLAG_SAP)) \
2593 ? KAL_TRUE \
2594 : KAL_FALSE)
2595
2596/*******************************************************************************
2597 * <GROUP Functions>
2598 *
2599 * FUNCTION
2600 * msg_get_inline_data
2601 * DESCRIPTION
2602 * Get the inline data pointer in ILM message.
2603 * PARAMETERS
2604 * ilm_ptr : [IN] ILM message pointer.
2605 * RETURN VALUES
2606 * inline data pointer. If it's not an inline-ILM, system enter fatal error handling.
2607 * NOTE
2608 * (1) Users must pass a inline-ILM to this function.
2609 * (2) The inline data length is not recorded in ILM messages.
2610 * Its user's responsibility to know what the inline data is.
2611 *
2612 * SEE ALSO
2613 * msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5,
2614 * msg_is_inline, msg_get_inline_data
2615 * msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
2616 * msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
2617 ******************************************************************************/
2618void *msg_get_inline_data(ilm_struct *ilm_ptr);
2619
2620
2621#if defined(DEBUG_KAL) && defined(DEBUG_ITC)
2622#define __destroy_ilm(ilm_ptr) \
2623 destroy_int_ilm((ilm_ptr), (kal_char *)__FILE__, __LINE__);
2624#else
2625#define __destroy_ilm(ilm_ptr) destroy_int_ilm((ilm_ptr), NULL, 0);
2626#endif
2627
2628/*******************************************************************************
2629 * <GROUP Functions>
2630 *
2631 * FUNCTION
2632 * destroy_ilm
2633 * DESCRIPTION
2634 * destroy an ILM. ref_count would minus 1 if buffer pointer is not NULL, buffer
2635 * instance peer_buff_ptr or local_para_ptr will truly be released only if
2636 * ref_count is zero.
2637 * PARAMETERS
2638 * ilm_ptr : [IN] ILM message pointer.
2639 * RETURN VALUES
2640 * N/A
2641 * NOTE
2642 * (1) The content pointed by ilm_ptr is not free.
2643 * (2) It will return immediately without destroy the ILM if
2644 * (2-A) the ILM is sent from timer (i.e. ilm_ptr->src_mod_id == MOD_TIMER)
2645 * (2-B) the ILM is an inline ILM (i.e. (ilm_ptr->sap_id & INLINE_ILM_FLAG_SAP) != 0)
2646 * If you want to replace this API by free_local_para[_r] or free_peer_buff[_r],
2647 * please remember to skip timer ILM or inline ILM
2648 * SEE ALSO
2649 * msg_send, msg_receive_extq, msg_receive_intq, free_local_para, free_local_para_r
2650 * free_peer_buff, free_peer_buff_r
2651 ******************************************************************************/
2652#define destroy_ilm(ilm_ptr) __destroy_ilm(ilm_ptr)
2653
2654#define destroy_shared_ilm_r destroy_ilm
2655#define free_shared_peer_buff_r free_peer_buff
2656#define free_shared_local_para_r free_local_para
2657
2658
2659/*******************************************************************************
2660 * <GROUP Functions>
2661 *
2662 * FUNCTION
2663 * msg_receive_extq
2664 * DESCRIPTION
2665 * receive a ILM message from current task's external queue.
2666 * PARAMETERS
2667 * ilm_ptr : [OUT] ILM message pointer.
2668 * RETURN VALUES
2669 * KAL_TRUE: to indicate this operation finish successfully.
2670 * NOTE
2671 * (1) If the external queue is not empty, this API return immediately.
2672 * Otherwise, it will suspend to wait for the arrival of ILM message.
2673 * (2) This API replaces receive_msg_ext_q(). And receive_msg_ext_q() is deprecated,
2674 * it will be removed from next release.
2675 * SEE ALSO
2676 * msg_send, msg_receive_intq, destroy_ilm
2677 ******************************************************************************/
2678kal_bool msg_receive_extq(ilm_struct *ilm_ptr);
2679/*******************************************************************************
2680 * <GROUP Functions>
2681 *
2682 * FUNCTION
2683 * msg_receive_extq_for_stack
2684 * DESCRIPTION
2685 * receive a ILM message from current task's external queue used for stack sharing.
2686 * PARAMETERS
2687 * ilm_ptr : [OUT] ILM message pointer.
2688 * RETURN VALUES
2689 * KAL_TRUE: to indicate this operation finish successfully.
2690 * NOTE
2691 * (1) If the external queue is not empty, this API return immediately.
2692 * Otherwise, it will suspend to wait for the arrival of ILM message.
2693 * (2) This API replaces receive_msg_ext_q(). And receive_msg_ext_q() is deprecated,
2694 * it will be removed from next release.
2695 * SEE ALSO
2696 * msg_send, msg_receive_intq, destroy_ilm
2697 ******************************************************************************/
2698kal_bool msg_receive_extq_for_stack(ilm_struct *ilm_ptr);
2699/*******************************************************************************
2700 * <GROUP Functions>
2701 *
2702 * FUNCTION
2703 * msg_receive_intq
2704 * DESCRIPTION
2705 * receive a ILM message from current task's internal queue.
2706 * PARAMETERS
2707 * ilm_ptr : [OUT] ILM message pointer.
2708 * RETURN VALUES
2709 * KAL_TRUE: ILM fetched.
2710 * KAL_FALSE: internal queue is empty and no ILM is fetched.
2711 * NOTE
2712 * This API replaces receive_msg_int_q(). And receive_msg_int_q() is deprecated,
2713 * it will be removed from next release.
2714 * SEE ALSO
2715 * msg_send, msg_receive_extq, destroy_ilm
2716 ******************************************************************************/
2717kal_bool msg_receive_intq(ilm_struct *ilm_ptr);
2718/*******************************************************************************
2719 * <GROUP Functions>
2720 *
2721 * FUNCTION
2722 * msg_receive_isrq
2723 * DESCRIPTION
2724 * receive a ILM message from current ISR's queue.
2725 * PARAMETERS
2726 * ilm_ptr : [OUT] ILM message pointer.
2727 * RETURN VALUES
2728 * KAL_TRUE: ILM fetched.
2729 * KAL_FALSE: internal queue is empty and no ILM is fetched.
2730 * NOTE
2731 *
2732 * SEE ALSO
2733 * msg_send, msg_receive_intq, destroy_ilm
2734 ******************************************************************************/
2735kal_bool msg_receive_isrq(ilm_struct *ilm_ptr);
2736/*******************************************************************************
2737 * <GROUP Functions>
2738 *
2739 * FUNCTION
2740 * msg_get_task_extq_messages
2741 * DESCRIPTION
2742 * get messages count in external queue of specified task by task index.
2743 * PARAMETERS
2744 * tindex : [IN] task index.
2745 * RETURN VALUES
2746 * messages count, -1 if error happens.
2747 * NOTE
2748 * (1)This API replaces msg_get_ext_queue_info(). And msg_get_ext_queue_info() is deprecated,
2749 * it will be removed from next release.
2750 * SEE ALSO
2751 * msg_get_extq_messages, msg_get_task_extq_capacity, msg_get_extq_capacity
2752 ******************************************************************************/
2753kal_int32 msg_get_task_extq_messages(module_type module_id);
2754/*******************************************************************************
2755 * <GROUP Functions>
2756 *
2757 * FUNCTION
2758 * msg_get_extq_messages
2759 * DESCRIPTION
2760 * get messages count in external queue of current task.
2761 * PARAMETERS
2762 * N/A
2763 * RETURN VALUES
2764 * messages count, -1 if error happens.
2765 * SEE ALSO
2766 * msg_get_task_extq_messages, msg_get_task_extq_capacity, msg_get_extq_capacity
2767 ******************************************************************************/
2768kal_int32 msg_get_extq_messages(void);
2769/*******************************************************************************
2770 * <GROUP Functions>
2771 *
2772 * FUNCTION
2773 * msg_get_task_extq_capacity
2774 * DESCRIPTION
2775 * get capacity of external queue of specified task by task index.
2776 * PARAMETERS
2777 * tindex : [IN] task index.
2778 * RETURN VALUES
2779 * capacity of target external queue, -1 if error happens.
2780 * NOTE
2781 * (1)This API replaces msg_get_ext_queue_length(). And msg_get_ext_queue_length() is deprecated,
2782 * it will be removed from next release.
2783 * SEE ALSO
2784 * msg_get_task_extq_messages, msg_get_extq_messages, msg_get_extq_capacity
2785 ******************************************************************************/
2786kal_int32 msg_get_task_extq_capacity(module_type tmod);
2787/*******************************************************************************
2788 * <GROUP Functions>
2789 *
2790 * FUNCTION
2791 * msg_get_extq_capacity
2792 * DESCRIPTION
2793 * get capacity of external queue of current task.
2794 * PARAMETERS
2795 * N/A
2796 * RETURN VALUES
2797 * capacity of current task external queue, -1 if error happens.
2798 * SEE ALSO
2799 * msg_get_task_extq_messages, msg_get_extq_messages, msg_get_task_extq_capacity
2800 ******************************************************************************/
2801kal_int32 msg_get_extq_capacity(void);
2802#if 0
2803/* under construction !*/
2804/* under construction !*/
2805/* under construction !*/
2806/* under construction !*/
2807/* under construction !*/
2808/* under construction !*/
2809/* under construction !*/
2810/* under construction !*/
2811/* under construction !*/
2812/* under construction !*/
2813/* under construction !*/
2814/* under construction !*/
2815/* under construction !*/
2816/* under construction !*/
2817/* under construction !*/
2818/* under construction !*/
2819/* under construction !*/
2820/* under construction !*/
2821/* under construction !*/
2822/* under construction !*/
2823/* under construction !*/
2824/* under construction !*/
2825/* under construction !*/
2826/* under construction !*/
2827/* under construction !*/
2828/* under construction !*/
2829/* under construction !*/
2830/* under construction !*/
2831/* under construction !*/
2832#endif
2833
2834/*******************************************************************************
2835 * Category 4.5 : Cross Core Message Passing and Queue
2836 *******************************************************************************/
2837#define construct_int_cc_cached_peer_buff construct_int_peer_buff
2838#define construct_int_cc_non_cached_peer_buff construct_int_peer_buff
2839#define construct_int_cc_cached_local_para construct_int_local_para
2840#define construct_int_cc_non_cached_local_para construct_int_local_para
2841
2842#if defined(DEBUG_KAL) && defined(DEBUG_BUF2)
2843#define __construct_int_cc_cached_local_para(local_para_size, direction) \
2844 construct_int_cc_cached_local_para( \
2845 local_para_size, ((kal_uint32)(direction) & (kal_uint32)TD_RESET) ? 1 : 0, \
2846 __FILE__, __LINE__)
2847#define __construct_int_cc_non_cached_local_para(local_para_size, direction) \
2848 construct_int_cc_non_cached_local_para( \
2849 local_para_size, ((kal_uint32)(direction) & (kal_uint32)TD_RESET) ? 1 : 0, \
2850 __FILE__, __LINE__)
2851
2852#define __construct_int_cc_cached_peer_buff(pdu_len, header_len, tail_len, \
2853 direction) \
2854 construct_int_cc_cached_peer_buff(pdu_len, header_len, tail_len, __FILE__, \
2855 __LINE__)
2856#define __construct_int_cc_non_cached_peer_buff(pdu_len, header_len, tail_len, \
2857 direction) \
2858 construct_int_cc_non_cached_peer_buff(pdu_len, header_len, tail_len, __FILE__, \
2859 __LINE__)
2860
2861#else /* !DEBUG_KAL || !DEBUG_BUF2 */
2862#define __construct_int_cc_cached_local_para(local_para_size, direction) \
2863 construct_int_cc_cached_local_para( \
2864 local_para_size, ((kal_uint32)(direction) & (kal_uint32)TD_RESET) ? 1 : 0, \
2865 NULL, 0)
2866#define __construct_int_cc_non_cached_local_para(local_para_size, direction) \
2867 construct_int_cc_non_cached_local_para( \
2868 local_para_size, ((kal_uint32)(direction) & (kal_uint32)TD_RESET) ? 1 : 0, \
2869 NULL, 0)
2870
2871#define __construct_int_cc_cached_peer_buff(pdu_len, header_len, tail_len, \
2872 direction) \
2873 construct_int_cc_cached_peer_buff(pdu_len, header_len, tail_len, NULL, 0)
2874#define __construct_int_cc_non_cached_peer_buff(pdu_len, header_len, tail_len, \
2875 direction) \
2876 construct_int_cc_non_cached_peer_buff(pdu_len, header_len, tail_len, NULL, 0)
2877
2878#endif
2879
2880
2881#define construct_cc_cached_local_para(local_para_size, direction) \
2882 __construct_int_cc_cached_local_para(local_para_size, direction)
2883#define construct_cc_non_cached_local_para(local_para_size, direction) \
2884 __construct_int_cc_non_cached_local_para(local_para_size, direction)
2885
2886#define construct_cc_cached_peer_buff(pdu_len, header_len, tail_len, direction) \
2887 __construct_int_cc_cached_peer_buff(pdu_len, header_len, tail_len, direction)
2888#define construct_cc_non_cached_peer_buff(pdu_len, header_len, tail_len, direction) \
2889 __construct_int_cc_non_cached_peer_buff(pdu_len, header_len, tail_len, direction)
2890
2891#define msg_send_cc msg_send
2892#define msg_send6_cc msg_send6
2893#define msg_send5_cc msg_send5
2894#define msg_send4_cc msg_send4
2895#define msg_send_to_head_cc msg_send_to_head
2896#define msg_send_to_head6_cc msg_send_to_head6
2897#define msg_send_to_head5_cc msg_send_to_head5
2898#define msg_send_to_head4_cc msg_send_to_head4
2899
2900
2901#define msg_send_inline6_cc msg_send_inline6
2902#define msg_send_inline_to_head6_cc msg_send_inline_to_head6
2903
2904#define msg_send_inline5_cc(src_mod, dest_mod, msg_id, data, datalen) \
2905 msg_send_inline6_cc(src_mod, dest_mod, INLINE_ILM_SAP, msg_id, data, datalen)
2906
2907
2908#define msg_send_inline_to_head5_cc(src_mod, dest_mod, sap_id, msg_id, data, \
2909 datalen) \
2910 msg_send_inline_to_head6_cc(src_mod, dest_mod, INLINE_ILM_SAP, msg_id, data, \
2911 datalen)
2912
2913#define msg_send_8bytes_inline6_cc msg_send_8bytes_inline6
2914
2915#define msg_send_8bytes_inline_to_head6_cc msg_send_8bytes_inline_to_head6
2916
2917/* DOM-NOT_FOR_SDK-END */
2918
2919/*******************************************************************************
2920 * Category 5 : Synchronous Mechanism : Mutex , Enhance Mutex , Semaphore,
2921 * Event Group, Spinlock, HW ITC and atomic increment/decrement
2922 *******************************************************************************/
2923
2924
2925/*******************************************************************************
2926 * <GROUP Synchronous>
2927 *
2928 * FUNCTION
2929 * kal_create_mutex
2930 * DESCRIPTION
2931 * create a mutex.
2932 * PARAMETERS
2933 * mutex_name : [IN] mutex name. it's used for debug only, and only the
2934 * first 8 characters retain.
2935 * RETURNS
2936 * Success: mutex pointer.
2937 * Error: system enter fatal error handling.
2938 * NOTE
2939 * It is strongly suggested to call this function only in system initialization
2940 * time, and the related data allocated for the mutex could not be freed
2941 * once it is created.
2942 * SEE ALSO
2943 * kal_take_mutex kal_give_mutex
2944 ******************************************************************************/
2945kal_mutexid kal_create_mutex(kal_char *mutex_name);
2946/*******************************************************************************
2947 * <GROUP Synchronous>
2948 *
2949 * FUNCTION
2950 * kal_take_mutex
2951 * DESCRIPTION
2952 * Obtains an instance of the specified mutex. If the mutex is taken already
2953 * before this call, the function cannot be immediately satisfied, and caller
2954 * task will be suspended until other task give the ownership to caller task.
2955 * After the function returns, caller task is the only task held this mutex.
2956 * PARAMETERS
2957 * mutex_ptr : [IN] mutex pointer.
2958 * RETURNS
2959 * N/A
2960 * NOTE
2961 * (1)Mutex is not a recursive lock. If caller task already held this mutex,
2962 * then caller task will suspend forever because any task won^t and can^t
2963 * give up mutex^s ownership.
2964 * (2)Mutex is a FIFO queue. If multiple tasks are waiting on a mutex, the
2965 * first waiting task is selected to be the next owner.
2966 * SEE ALSO
2967 * kal_create_mutex kal_give_mutex
2968 ******************************************************************************/
2969void kal_take_mutex(kal_mutexid mutex_ptr);
2970/*******************************************************************************
2971 * <GROUP Synchronous>
2972 *
2973 * FUNCTION
2974 * kal_give_mutex
2975 * DESCRIPTION
2976 * Give up mutex ownership. If any task is waiting on this mutex, the first
2977 * waiting task is selected to be the next owner.
2978 * PARAMETERS
2979 * mutex_ptr : [IN] mutex pointer.
2980 * RETURNS
2981 * N/A
2982 * NOTE
2983 * Mutex ownership is private to task. That means, give can be done at the same
2984 * task of take, otherwise fatal error handling takes place.
2985 * SEE ALSO
2986 * kal_create_mutex kal_take_mutex
2987 ******************************************************************************/
2988void kal_give_mutex(kal_mutexid mutex_ptr);
2989/*******************************************************************************
2990 * <GROUP Synchronous>
2991 *
2992 * FUNCTION
2993 * kal_mutex_waiting_count
2994 * DESCRIPTION
2995 * This routine returns the numbers of task waiting on the mutex.
2996 * PARAMETERS
2997 * mutex_ptr : [IN] mutex pointer.
2998 * waiting_count : [OUT] waiting count.
2999 * RETURNS
3000 * N/A
3001 * NOTE
3002 * This function is not in any critical section, e.g disable/enable interrupt, user should guarantee the atomic.
3003 * SEE ALSO
3004 * kal_create_mutex kal_take_mutex
3005 ******************************************************************************/
3006void kal_mutex_waiting_count(kal_mutexid mutex_ptr, kal_uint32 *waiting_count);
3007/*******************************************************************************
3008 * <GROUP Synchronous>
3009 *
3010 * FUNCTION
3011 * kal_create_enh_mutex
3012 * DESCRIPTION
3013 * create an enhmutex which implements Priority Inheritance Protocol(PIP) to
3014 * avoid priority inversion.
3015 * PARAMETERS
3016 * mutex_name : [IN] enhmutex name. it's used for debug only, and only the
3017 * first 8 characters retain.
3018 * RETURNS
3019 * Success: enhmutex pointer.
3020 * Error: system enter fatal error handling.
3021 * NOTE
3022 * It is strongly suggested to call this function only in system initialization
3023 * time, and the related data allocated for the enhmutex could not be freed
3024 * once it is created.
3025 * SEE ALSO
3026 * kal_take_enh_mutex kal_give_enh_mutex
3027 ******************************************************************************/
3028kal_enhmutexid kal_create_enh_mutex(kal_char *mutex_name);
3029/*******************************************************************************
3030 * <GROUP Synchronous>
3031 *
3032 * FUNCTION
3033 * kal_take_enh_mutex
3034 * DESCRIPTION
3035 * Obtain an instance of the specified enhmutex. If the enhmutex is taken
3036 * already before this call, the function cannot be immediately satisfied,
3037 * caller task propogates its priority to the owner task if caller task has
3038 * higher priority than owner task, and caller task will be suspended until
3039 * other task give the ownership to caller task. After the function returns,
3040 * caller task is the only task held this enhmutex.
3041 * PARAMETERS
3042 * mutex_ptr : [IN] enhmutex pointer.
3043 * RETURNS
3044 * N/A
3045 * NOTE
3046 * (1)Enhmutex is not a recursive lock. If caller task already held this
3047 * enhmutex, then caller task will suspend forever because any task will not
3048 * give up ehnmutex's ownership.
3049 * (2)No promise of enhmutex's queue type. If multiple tasks is waiting on a
3050 * mutex, no promise made which task will selected to run first.
3051 * SEE ALSO
3052 * kal_create_enh_mutex kal_give_enh_mutex
3053 ******************************************************************************/
3054void kal_take_enh_mutex(kal_enhmutexid mutex_ptr);
3055/*******************************************************************************
3056 * <GROUP Synchronous>
3057 *
3058 * FUNCTION
3059 * kal_give_enh_mutex
3060 * DESCRIPTION
3061 * Give up enhmutex ownership. If any task is waiting on this mutex, give the
3062 * ownership to any task based on its judge.
3063 * PARAMETERS
3064 * mutex_ptr : [IN] mutex pointer.
3065 * RETURNS
3066 * N/A
3067 * NOTE
3068 * Enhmutex ownership is private to task. That means, give can be done at the
3069 * same task of take, otherwise fatal error handling takes place.
3070 * SEE ALSO
3071 * kal_create_enh_mutex kal_take_enh_mutex
3072 ******************************************************************************/
3073void kal_give_enh_mutex(kal_enhmutexid mutex_ptr);
3074/*******************************************************************************
3075 * <GROUP Synchronous>
3076 *
3077 * FUNCTION
3078 * kal_create_sem
3079 * DESCRIPTION
3080 * create a couting semaphore.
3081 * PARAMETERS
3082 * sem_name : [IN] semaphore name. it's used for debug only, and only the
3083 * first 8 characters retain.
3084 * initial_count : [IN] semaphore initial count.
3085 * RETURNS
3086 * Success: semaphore pointer.
3087 * Error: system enter fatal error handling.
3088 * NOTE
3089 * (1)It is strongly suggested to call this function only in system initialization
3090 * time, and the related data allocated for the semaphore could not be freed
3091 * once it is created.
3092 * (2)Semaphore values can range from 0 through 4,294,967,294 (2^32 - 2).
3093 * SEE ALSO
3094 * kal_take_sem kal_give_sem
3095 ******************************************************************************/
3096kal_semid kal_create_sem(kal_char *sem_name, kal_uint32 initial_count);
3097/*******************************************************************************
3098 * <GROUP Synchronous>
3099 *
3100 * FUNCTION
3101 * kal_take_sem
3102 * DESCRIPTION
3103 * Obtains an instance of the specified semaphore.
3104 * PARAMETERS
3105 * sem_ptr : [IN] semaphore pointer.
3106 * wait_mode : [IN] wait mode, specify the behavior when the semaphore is
3107 * not ready immediately, it can be one the the following values:
3108 * KAL_NO_WAIT - don't wait for other task gives ownership to it
3109 * KAL_INFINITE_WAIT - wait until ownership can be satisfied
3110 * RETURN VALUES
3111 * KAL_SUCCESS : the operation is done successfully
3112 * KAL_SEM_NOT_AVAILABLE : the semaphore is unavailable immediately
3113 * NOTE
3114 * (1)Semaphore is a FIFO queue. If multiple tasks is waiting on a semaphore,
3115 * the first waiting task is selected to be the next owner.
3116 * SEE ALSO
3117 * kal_create_sem kal_give_sem
3118 ******************************************************************************/
3119kal_status kal_take_sem(kal_semid sem_ptr, kal_wait_mode wait_mode);
3120/*******************************************************************************
3121 * <GROUP Synchronous>
3122 *
3123 * FUNCTION
3124 * kal_give_sem
3125 * DESCRIPTION
3126 * Give up 1 semaphore ownership. If any task is waiting on this semaphore,
3127 * give the ownership to first waiting task.
3128 * PARAMETERS
3129 * sem_ptr : [IN] semaphore pointer.
3130 * RETURNS
3131 * N/A
3132 * NOTE
3133 * N/A
3134 * SEE ALSO
3135 * kal_create_sem kal_take_sem
3136 ******************************************************************************/
3137void kal_give_sem(kal_semid sem_ptr);
3138/*******************************************************************************
3139 * <GROUP Synchronous>
3140 *
3141 * FUNCTION
3142 * kal_create_spinlock
3143 * DESCRIPTION
3144 * creates a spinlock.
3145 * PARAMETERS
3146 * spinlock_name : [IN] spinlock name. it's used for debug only, and only the
3147 * first 7 characters retain.
3148 * RETURNS
3149 * Success: spinlock pointer.
3150 * Error: system enter fatal error handling.
3151 * SEE ALSO
3152 * kal_delete_spinlock
3153 ******************************************************************************/
3154kal_spinlockid kal_create_spinlock(kal_char *spinlock_name);
3155/*******************************************************************************
3156 * <GROUP Synchronous>
3157 *
3158 * FUNCTION
3159 * kal_take_spinlock
3160 * DESCRIPTION
3161 * Obtains an instance of the specified spinlock.
3162 * PARAMETERS
3163 * ext_spinlock_id_ptr : [IN] spinlock pointer.
3164 * wait_mode : [IN] wait mode, specify the behavior when the semaphore is
3165 * not ready immediately, it can be one the the following values:
3166 * KAL_NO_WAIT - don't wait for other task gives ownership to it
3167 * KAL_INFINITE_WAIT - wait until ownership can be satisfied
3168 * RETURN VALUES
3169 * KAL_SUCCESS : the operation is done successfully
3170 * KAL_SPINLOCK_NOT_AVAILABLE : the spinlock is unavailable immediately
3171 * SEE ALSO
3172 * kal_give_spinlock
3173 ******************************************************************************/
3174kal_status kal_take_spinlock(kal_spinlockid ext_spinlock_id_ptr,
3175 kal_wait_mode wait_mode);
3176/*******************************************************************************
3177 * <GROUP Synchronous>
3178 *
3179 * FUNCTION
3180 * kal_give_spinlock
3181 * DESCRIPTION
3182 * Give up 1 spinlock ownership.
3183 * PARAMETERS
3184 * ext_spinlock_id_ptr : [IN] spinlock pointer.
3185 * RETURNS
3186 * -
3187 * SEE ALSO
3188 * kal_take_spinlock
3189 ******************************************************************************/
3190void kal_give_spinlock(kal_spinlockid ext_spinlock_id_ptr);
3191/*******************************************************************************
3192 * <GROUP Communication>
3193 *
3194 * FUNCTION
3195 * kal_create_event_group
3196 * DESCRIPTION
3197 * create an event group.
3198 * PARAMETERS
3199 * eventgrp_name : [IN] event group name. it's used for debug only, and only
3200 * the first 8 characters retain.
3201 * RETURNS
3202 * Success: event group pointer.
3203 * Error: system enter fatal error handling.
3204 * NOTE
3205 * (1)It is strongly suggested to call this function only in system initialization
3206 * time, and the related data allocated for the event group could not be freed
3207 * once it is created.
3208 * (2)Each event group contains 32 event flags, all event flags are initially
3209 * set to 0.
3210 * SEE ALSO
3211 * kal_set_eg_events kal_retrieve_eg_events kal_retrieve_eg_events_timeout
3212 ******************************************************************************/
3213kal_eventgrpid kal_create_event_group(kal_char *eventgrp_name);
3214/*******************************************************************************
3215 * <GROUP Communication>
3216 *
3217 * FUNCTION
3218 * kal_set_eg_events
3219 * DESCRIPTION
3220 * sets the specified event flags in the specified event group. Any task waiting
3221 * on the event group whose event flag request is satisfied by this service is resumed.
3222 * PARAMETERS
3223 * eg_ptr : [IN] event group pointer.
3224 * events : [IN] event flags to be set.
3225 * operation : [IN] specify the operation, which can be one of following values:
3226 * KAL_AND - events in event group is AND with events argument,
3227 * that is, mask out bits not set in events argument
3228 * KAL_OR - events in event group is OR with events argument
3229 * RETURNS
3230 * Success: return KAL_SUCCESS
3231 * Error: system enter fatal error handling.
3232 * NOTE
3233 * N/A
3234 * SEE ALSO
3235 * kal_create_event_group kal_retrieve_eg_events kal_retrieve_eg_events_timeout
3236 ******************************************************************************/
3237kal_status kal_set_eg_events(kal_eventgrpid eg_ptr, kal_uint32 events,
3238 kal_uint8 operation);
3239/*******************************************************************************
3240 * <GROUP Communication>
3241 *
3242 * FUNCTION
3243 * kal_retrieve_eg_events
3244 * DESCRIPTION
3245 * retrieves the specified event-flag combination from the specified event-flag group.
3246 * PARAMETERS
3247 * eg_ptr : [IN] event group pointer.
3248 * requested_events : [IN] requested event flags
3249 * operation : [IN] specify the operation, which can be one of following values:
3250 * KAL_AND - all of the requested event flags are required
3251 * KAL_AND_CONSUME - all of requested event flags are required, and
3252 * automatically clears the event flags present on a successful request
3253 * KAL_OR - one or more of the requested event flags is sufficient
3254 * KAL_OR_CONSUME - one or more of the requested event flags is sufficient, and
3255 * automatically clears the event flags present on a successful request
3256 * retrieved_events: [OUT] actual events present in event group.
3257 * suspend: [IN] whether to wait for the event flags set when they can be satisfied immediately,
3258 * it can be one of following values:
3259 * 0: don't wait and return KAL_NOT_PRESENT
3260 * KAL_SUSPEND: wait until they can be satisfied
3261 * RETURN VALUES
3262 * KAL_SUCCESS: the operation is done successfully
3263 * KAL_NOT_PRESENT: the request event flags are not present immediately
3264 * Error: system enter fatal error handling.
3265 * NOTE
3266 * N/A
3267 * SEE ALSO
3268 * kal_create_event_group kal_set_eg_events kal_retrieve_eg_events_timeout
3269 ******************************************************************************/
3270kal_status kal_retrieve_eg_events(kal_eventgrpid eg_ptr, kal_uint32 requested_events,
3271 kal_uint8 operation, kal_uint32 *retrieved_events,
3272 kal_uint32 suspend);
3273/*******************************************************************************
3274 * <GROUP Communication>
3275 *
3276 * FUNCTION
3277 * kal_retrieve_eg_events_timeout
3278 * DESCRIPTION
3279 * retrieves the specified event-flag combination from the specified event-flag group.
3280 * PARAMETERS
3281 * eg_ptr : [IN] event group pointer.
3282 * requested_events : [IN] requested event flags
3283 * operation : [IN] specify the operation, which can be one of following values:
3284 * KAL_AND - all of the requested event flags are required
3285 * KAL_AND_CONSUME - all of requested event flags are required, and
3286 * automatically clears the event flags present on a successful request
3287 * KAL_OR - one or more of the requested event flags is sufficient
3288 * KAL_OR_CONSUME - one or more of the requested event flags is sufficient, and
3289 * automatically clears the event flags present on a successful request
3290 * retrieved_events: [OUT] actual events present in event group.
3291 * timeout: [IN] how long to wait for the event flags set when they can be satisfied immediately,
3292 * it can be one of following values:
3293 * 0 - don't wait and return KAL_NOT_PRESENT
3294 * KAL_SUSPEND - wait until they can be satisfied
3295 * other values - wait at most timeout ticks, return KAL_NOT_PRESENT if timeout happens
3296 * RETURN VALUES
3297 * KAL_SUCCESS: the operation is done successfully
3298 * KAL_NOT_PRESENT: the request event flags are not present immediately
3299 * Error: system enter fatal error handling.
3300 * NOTE
3301 * This API's availability is dependent on a macro HAS_KAL_RETRIEVE_EG_EVENTS_TIMEOUT.
3302 * If it's not defined, then this API is not available.
3303 * SEE ALSO
3304 * kal_create_event_group kal_set_eg_events kal_retrieve_eg_events
3305 ******************************************************************************/
3306kal_status kal_retrieve_eg_events_timeout(kal_eventgrpid eg_ptr,
3307 kal_uint32 requested_events,
3308 kal_uint8 operation,
3309 kal_uint32 * retrieved_events,
3310 kal_uint32 timeout);
3311#define HAS_KAL_RETRIEVE_EG_EVENTS_TIMEOUT 1
3312
3313/*******************************************************************************
3314 * Category 5.5 : Cross Core Event Group and RCU
3315 *******************************************************************************/
3316
3317/*******************************************************************************
3318 * <GROUP Communication>
3319 *
3320 * FUNCTION
3321 * kalcc_create_event_group
3322 * DESCRIPTION
3323 * create a cross core event group.
3324 * PARAMETERS
3325 * eg_id : [IN] event group pointer, the memory should be allocated from
3326 * shared memory
3327 * eventgrp_name : [IN] event group name. it's used for debug only, and only
3328 * the first 7 characters retain.
3329 * RETURNS
3330 * KAL_SUCCESS: create successfully
3331 * KAL_INIT_BEFORE: the event group has been init before
3332 * NOTE
3333 * (1)It is strongly suggested to call this function only in system initialization
3334 * time, and the related data allocated for the event group could not be freed
3335 * once it's created.
3336 * (2)Each event group contains 32 event flags, all event flags are initially
3337 * set to 0.
3338 * SEE ALSO
3339 * kalcc_set_eg_events kalcc_retrieve_eg_events
3340 ******************************************************************************/
3341kal_status kalcc_create_event_group(cc_eventgrpid *eg_id, kal_char *eventgrp_name);
3342/*******************************************************************************
3343 * <GROUP Communication>
3344 *
3345 * FUNCTION
3346 * kalcc_set_eg_events
3347 * DESCRIPTION
3348 * sets the specified event flags in the specified event group. Any task waiting
3349 * on the event group whose event flag request is satisfied by this service is resumed.
3350 * PARAMETERS
3351 * cc_eventgrpid : [IN] event group pointer.
3352 * events : [IN] event flags to be set.
3353 * operation : [IN] specify the operation, which can be one of following values:
3354 * KAL_AND - events in event group is AND with events argument,
3355 * that is, mask out bits not set in events argument
3356 * KAL_OR - events in event group is OR with events argument
3357 * RETURNS
3358 * KAL_SUCCESS: the operation is done successfully
3359 * Error: system enter fatal error handling.
3360 * NOTE
3361 * This function can not be called from hisr or system initialization; otherwise, assertion
3362 * SEE ALSO
3363 * kalcc_create_event_group kalcc_retrieve_eg_events
3364 ******************************************************************************/
3365kal_status kalcc_set_eg_events(cc_eventgrpid *eg_id, kal_uint32 events,
3366 kal_uint8 operation);
3367/*******************************************************************************
3368 * <GROUP Communication>
3369 *
3370 * FUNCTION
3371 * kalcc_retrieve_eg_events
3372 * DESCRIPTION
3373 * retrieves the specified event-flag combination from the specified event-flag group.
3374 * PARAMETERS
3375 * eg_id : [IN] event group pointer.
3376 * requested_events : [IN] requested event flags
3377 * operation : [IN] specify the operation, which can be one of following values:
3378 * KAL_AND - all of the requested event flags are required
3379 * KAL_AND_CONSUME - all of requested event flags are required, and
3380 * automatically clears the event flags present on a successful request
3381 * KAL_OR - one or more of the requested event flags is sufficient
3382 * KAL_OR_CONSUME - one or more of the requested event flags is sufficient, and
3383 * automatically clears the event flags present on a successful request
3384 * retrieved_events: [OUT] actual events present in event group.
3385 * suspend: [IN] whether to wait for the event flags set when they can be satisfied immediately,
3386 * it can be one of following values:
3387 * 0: don't wait and return CC_NOT_PRESENT
3388 * KAL_SUSPEND: wait until they can be satisfied
3389 * otherwise: system enter fatal error handling.
3390 * RETURN VALUES
3391 * KAL_SUCCESS: the operation is done successfully
3392 * KAL_NOT_PRESENT: the request event flags are not present immediately
3393 * Error: system enter fatal error handling.
3394 * NOTE
3395 * N/A
3396 * SEE ALSO
3397 * kalcc_create_event_group cc_set_eg_events
3398 ******************************************************************************/
3399kal_status kalcc_retrieve_eg_events(cc_eventgrpid *eg_id,
3400 kal_uint32 requested_events, kal_uint8 operation,
3401 kal_uint32 *retrieved_events,
3402 kal_uint32 suspend);
3403
3404
3405/* 1. creator*/
3406kalcc_rcuid rcu_create(void *buff_addr, kal_uint32 allocated_buff_size,
3407 kal_uint32 buff_size, kal_uint32 reserved);
3408/* 2. writer */
3409void *rcu_get_free_buff(kalcc_rcuid id);
3410kal_status rcu_commit_data(void *data);
3411/* 3. reader */
3412void *rcu_get_read_lock(kalcc_rcuid id);
3413kal_status rcu_free_read_lock(void *data);
3414
3415
3416/*******************************************************************************
3417 * Category 6 : Application Memory Management ADM , AFM
3418 *******************************************************************************/
3419
3420extern KAL_ADM_ID(kal_adm_create)(void *mem_addr, kal_uint32 size,
3421 kal_uint32 *subpool_size, kal_bool islogging);
3422extern KAL_ADM_ID(kal_adm_create_and_profile)(void *mem_addr, kal_uint32 size,
3423 kal_uint32 *subpool_size,
3424 kal_bool islogging);
3425
3426/*******************************************************************************
3427 * <GROUP Functions>
3428 *
3429 * FUNCTION
3430 * kal_adm_create2
3431 * DESCRIPTION
3432 * Create a ADM pool.
3433 * PARAMETERS
3434 * mem_addr: [IN] starting address of the memory pool. It should be 4-byte alignment, or it will be aligned to next 4-aligned address.
3435 * size: [IN] total size in byte of the memory pool.
3436 * subpool_size: [IN] is an array, which describe size of each sub-pool.
3437 * flags: [IN] new ADM pool extra flags, which is a combination of following values
3438 * KAL_ADM_GUARDIAN_FLAG - RECOMMENDED! put a guard word before and after each user buffer to detect memory corruption
3439 * it also enable some other error detections on this ADM pool.
3440 * KAL_ADM_EXTHEADER_FLAG - has an extensible header immediate before each user buffer,
3441 * whose size is specified by extheader_size_in_word
3442 * KAL_ADM_CLEANDELETE_FLAG - on kal_adm_delete(), if any user buffer is not free yet,
3443 * system enter fatal error handling
3444 * KAL_ADM_REALLOCFAIL_FATAL_FLAG - if kal_adm_realloc() failed, system enter fatal error handling
3445 * KAL_ADM_REALLOCFAIL_FREE_FLAG - if kal_adm_realloc() failed, free old user buffer before return NULL
3446 * extheader_size_in_word: [IN] specified the extensible header size, only takes effect when KAL_ADM_EXTHEADER_FLAG is specified.
3447 * this argument specified in unit of word, you can use KAL_ADM_EXTHEADER_WORDS(sizeof(struct A)) if you want
3448 * to put a struct A in extensible header.
3449 * RETURNS
3450 * ADM id. If memory is too small to create a ADM, return NULL.
3451 * NOTE
3452 * (1)This API replaces kal_adm_create(). And kal_adm_create() is deprecated,
3453 * it will be removed from next release.
3454 * (2)subpool_size must be monotonic increasing and ends with {0xffffffff, 0}.
3455 * If it's NULL, the default subpool size setting is used: { 16, 32, 64, 128, 256, 512, 0xffffffff, 0 }.
3456 * Default subpool size has 7 subpools.
3457 * (3)The ADM overhead for control block is divided into 2 parts:
3458 * Static - that is (16*3+16*subpool_count}. subpool_count is element count in subpool_size except last element 0.
3459 * Dynamic - Each user block has an extra: (8+extheader_size_in_word*4)
3460 * SEE ALSO
3461 * kal_adm_delete KAL_ADM_EXTHEADER_WORDS
3462 ******************************************************************************/
3463extern KAL_ADM_ID kal_adm_create2(void *mem_addr, kal_uint32 size,
3464 kal_uint32 *subpool_size, kal_uint32 flags,
3465 kal_int8 extheader_size_in_word);
3466/*******************************************************************************
3467 * <GROUP Functions>
3468 *
3469 * FUNCTION
3470 * kal_adm_delete
3471 * DESCRIPTION
3472 * delete a ADM pool.
3473 * PARAMETERS
3474 * adm_id: [IN] ADM pool identity.
3475 * RETURN VALUES
3476 * KAL_SUCCESS: the operation succeeded.
3477 * KAL_MEMORY_NOT_RELEASE: some user buffer is not free yet.
3478 * NOTE
3479 * if KAL_ADM_CLEANDELETE_FLAG is specified on creation and any user buffer is not free yet,
3480 * system enter fatal error handling
3481 * SEE ALSO
3482 * kal_adm_create2
3483 ******************************************************************************/
3484extern kal_status kal_adm_delete(KAL_ADM_ID adm_id);
3485
3486extern void *__kal_adm_alloc(KAL_ADM_ID adm_id, kal_uint32 size,
3487 kal_uint32 *actual_size, kal_uint32 opt, char *filename,
3488 kal_uint32 line);
3489extern void *__kal_adm_alloc_nc(KAL_ADM_ID adm_id, kal_uint32 size,
3490 kal_uint32 *actual_size, kal_uint32 option,
3491 char *filename, kal_uint32 line);
3492extern void *__kal_adm_alloc_c(KAL_ADM_ID adm_id, kal_uint32 size,
3493 kal_uint32 *actual_size, kal_uint32 option,
3494 char *filename, kal_uint32 line);
3495
3496extern void *__kal_adm_realloc(KAL_ADM_ID adm_id, void *ptr, kal_uint32 size,
3497 kal_uint32 *actual_size, kal_uint32 opt,
3498 char *filename, kal_uint32 line);
3499extern void *__kal_adm_realloc_nc(KAL_ADM_ID adm_id, void *ptr, kal_uint32 size,
3500 kal_uint32 *actual_size, kal_uint32 opt,
3501 char *filename, kal_uint32 line);
3502extern void *__kal_adm_realloc_c(KAL_ADM_ID adm_id, void *ptr, kal_uint32 size,
3503 kal_uint32 *actual_size, kal_uint32 opt,
3504 char *filename, kal_uint32 line);
3505
3506
3507/*******************************************************************************
3508 * <GROUP Functions>
3509 *
3510 * FUNCTION
3511 * kal_adm_alloc
3512 * DESCRIPTION
3513 * allocate a memory buffer from ADM.
3514 * PARAMETERS
3515 * adm_id: [IN] ADM pool identity.
3516 * size: [IN] request memory size.
3517 * RETURNS
3518 * allocated memory buffer pointer. return NULL if no memory available.
3519 * NOTE
3520 * the prototype of this API is:
3521 * void *kal_adm_alloc(KAL_ADM_ID adm_id, kal_uint32 size);
3522 * SEE ALSO
3523 * kal_adm_create2 kal_adm_alloc_with_info kal_adm_free
3524 ******************************************************************************/
3525#define kal_adm_alloc(adm_id, size) \
3526 __kal_adm_alloc((adm_id), (size), NULL, 0, __FILE__, __LINE__)
3527#define kal_adm_alloc_dbg(adm_id, size, f, l) \
3528 __kal_adm_alloc((adm_id), (size), NULL, 0, (f), (l))
3529/*******************************************************************************
3530 * <GROUP Functions>
3531 *
3532 * FUNCTION
3533 * kal_adm_alloc_with_info
3534 * DESCRIPTION
3535 * allocate a memory buffer from ADM, return the actually size (including any ADM overhead) of this memory block also.
3536 * PARAMETERS
3537 * adm_id: [IN] ADM pool identity.
3538 * size: [IN] request memory size.
3539 * actual_size: [OUT] return the actually size in it.
3540 * RETURNS
3541 * allocated memory buffer pointer. return NULL if no memory available.
3542 * NOTE
3543 * the prototype of this API is:
3544 * void *kal_adm_alloc_with_info(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 *actual_size);
3545 * SEE ALSO
3546 * kal_adm_create2 kal_adm_alloc kal_adm_free
3547 ******************************************************************************/
3548#define kal_adm_alloc_with_info(adm_id, size, actual_size) \
3549 __kal_adm_alloc((adm_id), (size), (actual_size), 0x0, __FILE__, __LINE__)
3550/*******************************************************************************
3551 * <GROUP Functions>
3552 *
3553 * FUNCTION
3554 * kal_adm_alloc_align
3555 * DESCRIPTION
3556 * allocate a memory buffer which satisfy the alignment requirement from ADM.
3557 * PARAMETERS
3558 * adm_id: [IN] ADM pool identity.
3559 * size: [IN] request memory size.
3560 * align: [IN] alignment requirement, which must be a multiple of 4.
3561 * RETURNS
3562 * allocated memory buffer pointer. return NULL if no memory available.
3563 * NOTE
3564 * the prototype of this API is:
3565 * void *kal_adm_alloc_align(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 alignment);
3566 * SEE ALSO
3567 * kal_adm_create2 kal_adm_free
3568 ******************************************************************************/
3569#define kal_adm_alloc_align(adm_id, size, alignment) \
3570 __kal_adm_alloc((adm_id), (size), NULL, (alignment) & ~ADM_OPT_MASK, __FILE__, \
3571 __LINE__)
3572#define kal_adm_alloc_align_dbg(adm_id, size, alignment, f, l) \
3573 __kal_adm_alloc((adm_id), (size), NULL, (alignment) & ~ADM_OPT_MASK, (f), (l))
3574
3575
3576#if defined(__MTK_TARGET__) && \
3577 (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
3578#define __kal_adm_alloc_cacheable(adm_id, size, option) \
3579 __kal_adm_alloc_c((adm_id), (size), NULL, 0, __FILE__, __LINE__)
3580#define __kal_adm_alloc_cacheable_with_info(adm_id, size, option, actual_size) \
3581 __kal_adm_alloc_c((adm_id), (size), (actual_size), 0x0, __FILE__, __LINE__)
3582#define __kal_adm_alloc_cacheable_dbg(adm_id, size, option, f, l) \
3583 __kal_adm_alloc_c((adm_id), (size), NULL, 0, (f), (l))
3584#else
3585#define __kal_adm_alloc_cacheable(adm_id, size, option) \
3586 __kal_adm_alloc((adm_id), (size), NULL, 0, __FILE__, __LINE__)
3587#define __kal_adm_alloc_cacheable_with_info(adm_id, size, option, actual_size) \
3588 __kal_adm_alloc((adm_id), (size), (actual_size), 0x0, __FILE__, __LINE__)
3589#define __kal_adm_alloc_cacheable_dbg(adm_id, size, option, f, l) \
3590 __kal_adm_alloc((adm_id), (size), NULL, 0, (f), (l))
3591#endif
3592/*******************************************************************************
3593 * <GROUP Functions>
3594 *
3595 * FUNCTION
3596 * kal_adm_alloc_cacheable
3597 * DESCRIPTION
3598 * allocate a memory buffer which is cacheable from ADM.
3599 * PARAMETERS
3600 * adm_id: [IN] ADM pool identity.
3601 * size: [IN] request memory size.
3602 * option_notused: [IN] useless, ignored.
3603 * RETURNS
3604 * allocated memory buffer pointer. return NULL if no memory available.
3605 * NOTE
3606 * (1)the prototype of this API is:
3607 * void *kal_adm_alloc_cacheable(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 option_notused);
3608 * (2)The pointer is cacheable only on platform that has ARM MMU (such as ARM9/ARM11 platform).
3609 * If not, the pointer is still noncacheable.
3610 * SEE ALSO
3611 * kal_adm_create2 kal_adm_alloc_cacheable_with_info kal_adm_alloc_noncacheable kal_adm_free
3612 ******************************************************************************/
3613#define kal_adm_alloc_cacheable(adm_id, size, option_notused) \
3614 __kal_adm_alloc_cacheable(adm_id, size, option_notused)
3615/*******************************************************************************
3616 * <GROUP Functions>
3617 *
3618 * FUNCTION
3619 * kal_adm_alloc_cacheable_with_info
3620 * DESCRIPTION
3621 * allocate a memory buffer which is cacheable from ADM, return the actually size (including any ADM overhead) of this memory block also.
3622 * PARAMETERS
3623 * adm_id: [IN] ADM pool identity.
3624 * size: [IN] request memory size.
3625 * option_notused: [IN] useless, ignored.
3626 * actual_size: [OUT] return the actually size in it.
3627 * RETURNS
3628 * allocated memory buffer pointer. return NULL if no memory available.
3629 * NOTE
3630 * (1)the prototype of this API is:
3631 * void *kal_adm_alloc_cacheable_with_info(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 option_notused, kal_uint32 *actual_size);
3632 * (2)The pointer is cacheable only on platform that has ARM MMU (such as ARM9/ARM11 platform).
3633 * If not, the pointer is still noncacheable.
3634 * SEE ALSO
3635 * kal_adm_create2 kal_adm_alloc_cacheable kal_adm_alloc_noncacheable kal_adm_free
3636 ******************************************************************************/
3637#define kal_adm_alloc_cacheable_with_info(adm_id, size, option_notused, \
3638 actual_size) \
3639 __kal_adm_alloc_cacheable_with_info(adm_id, size, option_notused, actual_size)
3640#define kal_adm_alloc_cacheable_dbg(adm_id, size, option_notused, f, l) \
3641 __kal_adm_alloc_cacheable_dbg(adm_id, size, option_notused, f, l)
3642
3643#if defined(__MTK_TARGET__) && \
3644 (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
3645#define __kal_adm_alloc_noncacheable(adm_id, size, option) \
3646 __kal_adm_alloc_nc((adm_id), (size), NULL, 0, __FILE__, __LINE__)
3647#define __kal_adm_alloc_noncacheable_with_info(adm_id, size, option, actual_size) \
3648 __kal_adm_alloc_nc((adm_id), (size), (actual_size), 0x0, __FILE__, __LINE__)
3649#define __kal_adm_alloc_noncacheable_dbg(adm_id, size, option, f, l) \
3650 __kal_adm_alloc_nc((adm_id), (size), NULL, 0, (f), (l))
3651#else
3652#define __kal_adm_alloc_noncacheable(adm_id, size, option) \
3653 __kal_adm_alloc((adm_id), (size), NULL, 0, __FILE__, __LINE__)
3654#define __kal_adm_alloc_noncacheable_with_info(adm_id, size, option, actual_size) \
3655 __kal_adm_alloc((adm_id), (size), (actual_size), 0x0, __FILE__, __LINE__)
3656#define __kal_adm_alloc_noncacheable_dbg(adm_id, size, option, f, l) \
3657 __kal_adm_alloc((adm_id), (size), NULL, 0, (f), (l))
3658#endif
3659/*******************************************************************************
3660 * <GROUP Functions>
3661 *
3662 * FUNCTION
3663 * kal_adm_alloc_noncacheable
3664 * DESCRIPTION
3665 * allocate a memory buffer which is noncacheable from ADM.
3666 * PARAMETERS
3667 * adm_id: [IN] ADM pool identity.
3668 * size: [IN] request memory size.
3669 * option_notused: [IN] useless, ignored.
3670 * RETURNS
3671 * allocated memory buffer pointer. return NULL if no memory available.
3672 * NOTE
3673 * (1)the prototype of this API is:
3674 * void *kal_adm_alloc_noncacheable(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 option_notused);
3675 * SEE ALSO
3676 * kal_adm_create2 kal_adm_alloc_noncacheable_with_info kal_adm_alloc_cacheable kal_adm_free
3677 ******************************************************************************/
3678#define kal_adm_alloc_noncacheable(adm_id, size, option_notused) \
3679 __kal_adm_alloc_noncacheable(adm_id, size, option_notused)
3680/*******************************************************************************
3681 * <GROUP Functions>
3682 *
3683 * FUNCTION
3684 * kal_adm_alloc_noncacheable_with_info
3685 * DESCRIPTION
3686 * allocate a memory buffer which is noncacheable from ADM, return the actually size (including any ADM overhead) of this memory block also.
3687 * PARAMETERS
3688 * adm_id: [IN] ADM pool identity.
3689 * size: [IN] request memory size.
3690 * option_notused: [IN] useless, ignored.
3691 * actual_size: [OUT] return the actually size in it.
3692 * RETURNS
3693 * allocated memory buffer pointer. return NULL if no memory available.
3694 * NOTE
3695 * (1)the prototype of this API is:
3696 * void *kal_adm_alloc_noncacheable_with_info(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 option_notused, kal_uint32 *actual_size);
3697 * SEE ALSO
3698 * kal_adm_create2 kal_adm_alloc_noncacheable kal_adm_alloc_cacheable kal_adm_free
3699 ******************************************************************************/
3700#define kal_adm_alloc_noncacheable_with_info(adm_id, size, option_notused, \
3701 actual_size) \
3702 __kal_adm_alloc_noncacheable_with_info(adm_id, size, option_notused, actual_size)
3703#define kal_adm_alloc_noncacheable_dbg(adm_id, size, option_notused, f, l) \
3704 __kal_adm_alloc_noncacheable_dbg(adm_id, size, option_notused, f, l)
3705
3706
3707/*******************************************************************************
3708 * <GROUP Functions>
3709 *
3710 * FUNCTION
3711 * kal_adm_realloc
3712 * DESCRIPTION
3713 * re-allocate a memory buffer from ADM.
3714 * PARAMETERS
3715 * adm_id: [IN] ADM pool identity.
3716 * ptr: [IN] old memory buffer pointer.
3717 * size: [IN] request memory size.
3718 * RETURNS
3719 * re-allocated memory buffer pointer. return NULL if no memory available.
3720 * SEE ALSO
3721 * kal_adm_create2 kal_adm_free kal_adm_alloc KAL_ADM_REALLOCFAIL_FATAL_FLAG KAL_ADM_REALLOCFAIL_FREE_FLAG
3722 ******************************************************************************/
3723#define kal_adm_realloc(adm_id, ptr, size) \
3724 __kal_adm_realloc((adm_id), (ptr), (size), NULL, 0, __FILE__, __LINE__)
3725#define kal_adm_realloc_dbg(adm_id, ptr, size, f, l) \
3726 __kal_adm_realloc((adm_id), (ptr), (size), NULL, 0, (f), (l))
3727#if defined(__MTK_TARGET__) && defined(__DYNAMIC_SWITCH_CACHEABILITY__)
3728#define __kal_adm_realloc_noncacheable(adm_id, ptr, size) \
3729 __kal_adm_realloc_nc((adm_id), (ptr), (size), NULL, 0, __FILE__, __LINE__)
3730#define __kal_adm_realloc_cacheable(adm_id, ptr, size) \
3731 __kal_adm_realloc_c((adm_id), (ptr), (size), NULL, 0, __FILE__, __LINE__)
3732#else
3733#define __kal_adm_realloc_noncacheable(adm_id, ptr, size) \
3734 kal_adm_realloc(adm_id, ptr, size)
3735#define __kal_adm_realloc_cacheable(adm_id, ptr, size) \
3736 kal_adm_realloc(adm_id, ptr, size)
3737#endif
3738
3739#define kal_adm_realloc_cacheable(adm_id, ptr, size) \
3740 __kal_adm_realloc_cacheable(adm_id, ptr, size)
3741#define kal_adm_realloc_noncacheable(adm_id, ptr, size) \
3742 __kal_adm_realloc_noncacheable(adm_id, ptr, size)
3743
3744/*******************************************************************************
3745 * <GROUP Functions>
3746 *
3747 * FUNCTION
3748 * kal_adm_free
3749 * DESCRIPTION
3750 * free a memory buffer to dedicated ADM.
3751 * PARAMETERS
3752 * adm_id: [IN] ADM pool identity.
3753 * ptr: [IN] memory buffer pointer to be free. This pointer must be allocated from adm_id.
3754 * RETURNS
3755 * N/A
3756 * SEE ALSO
3757 * kal_adm_create2 kal_adm_alloc kal_adm_realloc
3758 ******************************************************************************/
3759extern void kal_adm_free(KAL_ADM_ID adm_id, void *ptr);
3760/*******************************************************************************
3761 * <GROUP Functions>
3762 *
3763 * FUNCTION
3764 * kal_adm_get_extheader
3765 * DESCRIPTION
3766 * get the extensible header associated with ptr, which is immediate before ptr.
3767 * PARAMETERS
3768 * adm_id: [IN] ADM pool identity.
3769 * ptr: [IN] memory buffer pointer to query. This pointer must be returned from kal_adm_alloc*() functions.
3770 * RETURNS
3771 * associated extensible header pointer.
3772 * NOTE
3773 * (1)This ADM pool must has KAL_ADM_EXTHEADER_FLAG on creation.
3774 * (2)The size of this extensible header is (extheader_size_in_word*4)
3775 * SEE ALSO
3776 * kal_adm_create2 KAL_ADM_EXTHEADER_FLAG
3777 ******************************************************************************/
3778extern void *kal_adm_get_extheader(KAL_ADM_ID adm_id, void *ptr);
3779/*******************************************************************************
3780 * <GROUP Functions>
3781 *
3782 * FUNCTION
3783 * kal_adm_get_alloc_size
3784 * DESCRIPTION
3785 * get the allocated memory size.
3786 * PARAMETERS
3787 * adm_id: [IN] ADM pool identity.
3788 * ptr: [IN] memory buffer pointer to query. This pointer must be returned from kal_adm_alloc*() functions.
3789 * RETURNS
3790 * get the allocated memory size.
3791 * NOTE
3792 * N/A
3793 * SEE ALSO
3794 *
3795 ******************************************************************************/
3796extern kal_uint32 kal_adm_get_alloc_size(KAL_ADM_ID adm_id, void *ptr);
3797/*******************************************************************************
3798 * <GROUP Functions>
3799 *
3800 * FUNCTION
3801 * kal_adm_get_max_alloc_size
3802 * DESCRIPTION
3803 * get maximal available memory size to be allocated in a single kal_adm_alloc*().
3804 * PARAMETERS
3805 * adm_id: [IN] ADM pool identity.
3806 * RETURNS
3807 * maximal available memory size to be allocated.
3808 * NOTE
3809 * (1)This size is guaranteed to allocated without considering any other requirement.
3810 * For example, kal_adm_alloc(adm_id, kal_adm_get_max_alloc_size(adm_id)) can succeed.
3811 * But kal_adm_alloc_align() is not guaranteed to succeed.
3812 * SEE ALSO
3813 * kal_adm_get_total_left_size
3814 ******************************************************************************/
3815extern kal_uint32 kal_adm_get_max_alloc_size(KAL_ADM_ID adm_id);
3816/*******************************************************************************
3817 * <GROUP Functions>
3818 *
3819 * FUNCTION
3820 * kal_adm_get_total_left_size
3821 * DESCRIPTION
3822 * get total un-allocated memory size.
3823 * PARAMETERS
3824 * adm_id: [IN] ADM pool identity.
3825 * RETURNS
3826 * get total un-allocated memory size.
3827 * NOTE
3828 * (1)Total un-allocated memory size may be splitted in many blocks(fragmentation).
3829 * SEE ALSO
3830 * kal_adm_get_max_alloc_size
3831 ******************************************************************************/
3832extern kal_uint32 kal_adm_get_total_left_size(KAL_ADM_ID adm_id);
3833/*******************************************************************************
3834 * <GROUP Functions>
3835 *
3836 * FUNCTION
3837 * kal_adm_check_integrity
3838 * DESCRIPTION
3839 * Check the healthy of ADM pool.
3840 * PARAMETERS
3841 * adm_id: [IN] ADM pool identity.
3842 * RETURNS
3843 * return bad memory block first found. If the ADM pool is healthy, return NULL to indicate
3844 * nothing wrong.
3845 ******************************************************************************/
3846extern void *kal_adm_check_integrity(KAL_ADM_ID adm_id);
3847
3848/* DOM-NOT_FOR_SDK-BEGIN */
3849extern void kal_adm_print_log(KAL_ADM_ID adm_id);
3850extern kal_uint32 kal_adm_calc_worst_alloc_size(KAL_ADM_ID adm_id, kal_uint32 size,
3851 kal_uint32 option);
3852extern void *kal_adm_get_prev_block_ptr(KAL_ADM_ID adm_id, void *mem_addr);
3853extern void *kal_adm_get_next_block_ptr(KAL_ADM_ID adm_id, void *mem_addr);
3854extern void *kal_adm_get_trans_ptr(KAL_ADM_ID adm_id, void *mem_addr);
3855
3856
3857/*
3858 * Function prototype: void *kal_adm_alloc_mtkL1_cacheable(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 option)
3859 * Note: Allocate a MTKL1-cacheable memory block.
3860 */
3861#if defined(__MTK_TARGET__) && defined(__MTK_L1CACHEABLE__)
3862#define kal_adm_alloc_mtkL1_cacheable(adm_id, size, option) \
3863 __kal_adm_alloc_c((adm_id), (size), NULL, (option), __FILE__, __LINE__)
3864#else /* __MTK_TARGET__ && __MTK_L1CACHEABLE__ */
3865#define kal_adm_alloc_mtkL1_cacheable(adm_id, size, option) \
3866 __kal_adm_alloc((adm_id), (size), NULL, 0, __FILE__, __LINE__)
3867#endif /* __MTK_TARGET__ && __MTK_L1CACHEABLE__ */
3868
3869/*
3870 * Function prototype: void *kal_adm_alloc_mtkL1_noncacheable(KAL_ADM_ID adm_id, kal_uint32 option)
3871 * Note: Allocate a memory block. This is for RFU only.
3872 */
3873#define kal_adm_alloc_mtkL1_noncacheable(adm_id, size, option) \
3874 __kal_adm_alloc((adm_id), (size), NULL, 0, __FILE__, __LINE__)
3875
3876/*
3877 * Function prototype: void *kal_adm_alloc_nc_align(KAL_ADM_ID adm_id, kal_uint32 align_size)
3878 * Note: Allocate a non-cacheable and aligned memory block.
3879 */
3880#if defined(__MTK_TARGET__) && \
3881 (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
3882#define kal_adm_alloc_nc_align(adm_id, size, a) \
3883 __kal_adm_alloc_nc((adm_id), (size), NULL, (a) & ~ADM_OPT_MASK, __FILE__, \
3884 __LINE__)
3885#define kal_adm_alloc_nc_align_dbg(adm_id, size, a, f, l) \
3886 __kal_adm_alloc_nc((adm_id), (size), NULL, (a) & ~ADM_OPT_MASK, (f), (l))
3887#else /* __MTK_TARGET__ && (__ARM9_MMU__ || __DYNAMIC_SWITCH_CACHEABILITY__) */
3888#define kal_adm_alloc_nc_align(adm_id, size, a) \
3889 __kal_adm_alloc((adm_id), (size), NULL, (a) & ~ADM_OPT_MASK, __FILE__, __LINE__)
3890#define kal_adm_alloc_nc_align_dbg(adm_id, size, a, f, l) \
3891 __kal_adm_alloc((adm_id), (size), NULL, (a) & ~ADM_OPT_MASK, (f), (l))
3892#endif /* __MTK_TARGET__ && (__ARM9_MMU__ || __DYNAMIC_SWITCH_CACHEABILITY__) */
3893
3894/*
3895 * Function prototype: void *kal_adm_alloc_topmost(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 align_size)
3896 * void *kal_adm_alloc_topmost_dbg(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 align_size, kal_char *filename, kal_uint32 linenumber)
3897 * Note: Allocate a memory block from the topmost address of the pool.
3898 * The start address of the allocated memory will be aligned to the input parameter align_size.
3899 * kal_adm_alloc_topmost_dbg() is the debug verion.
3900 * The input parameters filename and line will be used for logging if logging is enabled.
3901 */
3902#define kal_adm_alloc_topmost(adm_id, size, a) \
3903 __kal_adm_alloc((adm_id), (size), NULL, \
3904 ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, __FILE__, \
3905 __LINE__)
3906#define kal_adm_alloc_topmost_dbg(adm_id, size, a, f, l) \
3907 __kal_adm_alloc((adm_id), (size), NULL, \
3908 ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, (f), (l))
3909
3910/*
3911 * Function prototype: void *kal_adm_alloc_c_topmost(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 align_size)
3912 * void *kal_adm_alloc_c_topmost_dbg(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 align_size, kal_char *filename, kal_uint32 line)
3913 * Note: Allocate a cacheable memory block from the topmost address of the pool.
3914 * The start address of the allocated memory will be aligned to the input parameter align_size.
3915 */
3916#if defined(__MTK_TARGET__) && \
3917 (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
3918#define kal_adm_alloc_c_topmost(adm_id, size, a) \
3919 __kal_adm_alloc_c((adm_id), (size), NULL, \
3920 ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, __FILE__, \
3921 __LINE__)
3922#define kal_adm_alloc_c_topmost_dbg(adm_id, size, a, f, l) \
3923 __kal_adm_alloc_c((adm_id), (size), NULL, \
3924 ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, (f), (l))
3925#else /* __MTK_TARGET__ && (__ARM9_MMU__ || __DYNAMIC_SWITCH_CACHEABILITY__)*/
3926#define kal_adm_alloc_c_topmost(adm_id, size, a) \
3927 __kal_adm_alloc((adm_id), (size), NULL, \
3928 ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, __FILE__, \
3929 __LINE__)
3930#define kal_adm_alloc_c_topmost_dbg(adm_id, size, a, f, l) \
3931 __kal_adm_alloc((adm_id), (size), NULL, \
3932 ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, (f), (l))
3933#endif /* __MTK_TARGET__ && (__ARM9_MMU__ || __DYNAMIC_SWITCH_CACHEABILITY__)*/
3934
3935/*
3936 * Function prototype: void *kal_adm_alloc_nc_topmost(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 align_size)
3937 * void *kal_adm_alloc_nc_topmost_dbg(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 align_size, kal_char *filename, kal_uint32 line)
3938 * Note: Allocate a non-cacheable memory block from the topmost address of the pool.
3939 * The start address of the allocated memory will be aligned to the input parameter align_size.
3940 * kal_adm_alloc_nc_topmost_dbg() is the debug version.
3941 */
3942#if defined(__MTK_TARGET__) && \
3943 (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
3944#define kal_adm_alloc_nc_topmost(adm_id, size, a) \
3945 __kal_adm_alloc_nc((adm_id), (size), NULL, \
3946 ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, __FILE__, \
3947 __LINE__)
3948#define kal_adm_alloc_nc_topmost_dbg(adm_id, size, a, f, l) \
3949 __kal_adm_alloc_nc((adm_id), (size), NULL, \
3950 ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, (f), (l))
3951#else /* __MTK_TARGET__ && (__ARM9_MMU__ || __DYNAMIC_SWITCH_CACHEABILITY__)*/
3952#define kal_adm_alloc_nc_topmost(adm_id, size, a) \
3953 __kal_adm_alloc((adm_id), (size), NULL, \
3954 ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, __FILE__, \
3955 __LINE__)
3956#define kal_adm_alloc_nc_topmost_dbg(adm_id, size, a, f, l) \
3957 __kal_adm_alloc((adm_id), (size), NULL, \
3958 ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, (f), (l))
3959#endif /* __MTK_TARGET__ && (__ARM9_MMU__ || __DYNAMIC_SWITCH_CACHEABILITY__)*/
3960/* DOM-NOT_FOR_SDK-END */
3961
3962
3963/*
3964 * AFM Section
3965 */
3966
3967/*******************************************************************************
3968 * <GROUP Functions>
3969 *
3970 * FUNCTION
3971 * kal_afm_create
3972 * DESCRIPTION
3973 * Create a AFM pool.
3974 * PARAMETERS
3975 * mem_addr: [IN] starting address of the memory pool. It should be 4-byte alignment, or it will be aligned to next 4-aligned address.
3976 * size: [IN] total size in byte of the memory pool.
3977 * subpool_size: [IN] is an array, which describe size of each sub-pool.
3978 * subpool_nr: [IN] is an array, which describe element count of each sub-pool.
3979 * flags: [IN] new AFM pool extra flags, which is a combination of following values
3980 * AFM_OPT_ALIGN_ALLOC - user buffers in this AFM is aligned to CPU cache line (32 bytes)
3981 * only available on platform which has a ARM MMU (ARM9+ chips).
3982 * AFM_OPT_NOFALLBACK_ALLOC - when search avaiable user buffer, don't try to search subpools bigger than fittest subpool.
3983 * left_mem: [OUT] get how many memory is not used by this AFM pool and can be used by app freely.
3984 * RETURNS
3985 * AFM id. If memory is too small to create a AFM, system enters fatal error handling.
3986 * NOTE
3987 * subpool_size must be monotonic increasing and ends with {0xffffffff, 0}.
3988 * subpool_nr must has same elements as subpool_size.
3989 * SEE ALSO
3990 * kal_afm_delete
3991 ******************************************************************************/
3992extern KAL_AFM_ID kal_afm_create(void *mem_addr, kal_uint32 size,
3993 kal_uint32 *subpool_size, kal_uint32 *subpool_nr,
3994 kal_uint32 flags, kal_uint32 *left_mem);
3995/*******************************************************************************
3996 * <GROUP Functions>
3997 *
3998 * FUNCTION
3999 * kal_afm_delete
4000 * DESCRIPTION
4001 * delete a AFM pool.
4002 * PARAMETERS
4003 * afm_id: [IN] AFM pool identity.
4004 * RETURN VALUES
4005 * KAL_SUCCESS: the operation succeeded.
4006 * KAL_MEMORY_NOT_RELEASE: some user buffer is not freed yet.
4007 * SEE ALSO
4008 * kal_afm_create
4009 ******************************************************************************/
4010extern kal_status kal_afm_delete(KAL_AFM_ID afm_id);
4011
4012extern void *kal_afm_internal_alloc(KAL_AFM_ID afm_id, kal_uint32 size,
4013 kal_uint32 * actual_size,
4014 const kal_char *filename, kal_uint32 line);
4015/*******************************************************************************
4016 * <GROUP Functions>
4017 *
4018 * FUNCTION
4019 * kal_afm_alloc
4020 * DESCRIPTION
4021 * allocate a memory buffer from AFM.
4022 * PARAMETERS
4023 * afm_id: [IN] AFM pool identity.
4024 * size: [IN] request memory size.
4025 * RETURNS
4026 * allocated memory buffer pointer. return NULL if no memory available.
4027 * NOTE
4028 * the prototype of this API is:
4029 * void *kal_afm_alloc(KAL_AFM_ID afm_id, kal_uint32 size);
4030 * SEE ALSO
4031 * kal_afm_create kal_afm_free
4032 ******************************************************************************/
4033#define kal_afm_alloc(afm_id, size) \
4034 kal_afm_internal_alloc(afm_id, size, NULL, __FILE__, __LINE__)
4035#define kal_afm_alloc_dbg(afm_id, size, actual_size, filename, line) \
4036 kal_afm_internal_alloc(afm_id, size, actual_size, filename, line)
4037/*******************************************************************************
4038 * <GROUP Functions>
4039 *
4040 * FUNCTION
4041 * kal_afm_free
4042 * DESCRIPTION
4043 * free a memory buffer to dedicated AFM.
4044 * PARAMETERS
4045 * afm_id: [IN] AFM pool identity.
4046 * ptr: [IN] memory buffer pointer to be freed. This pointer must be allocated from afm_id.
4047 * RETURNS
4048 * N/A
4049 * SEE ALSO
4050 * kal_afm_create kal_afm_alloc
4051 ******************************************************************************/
4052extern void kal_afm_free(KAL_AFM_ID afm_id, void *ptr);
4053/*******************************************************************************
4054 * <GROUP Functions>
4055 *
4056 * FUNCTION
4057 * kal_afm_check_integrity
4058 * DESCRIPTION
4059 * Check the healthy of AFM pool.
4060 * PARAMETERS
4061 * afm_id: [IN] AFM pool identity.
4062 * RETURNS
4063 * return bad memory block first found. If the AFM pool is healthy, return NULL to indicate
4064 * nothing wrong found.
4065 ******************************************************************************/
4066extern kal_int32 kal_afm_check_integrity(KAL_AFM_ID afm_id);
4067
4068extern void *kal_afm_internal_alloc_cacheable(KAL_AFM_ID adm_id, kal_uint32 size,
4069 kal_uint32 * actual_size,
4070 const kal_char *filename,
4071 kal_uint32 line);
4072#if defined(__MTK_TARGET__) && \
4073 (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
4074#define __kal_afm_alloc_cacheable(afm_id, size, option_notused) \
4075 kal_afm_internal_alloc_cacheable(afm_id, size, NULL, __FILE__, __LINE__)
4076#define __kal_afm_alloc_cacheable_dbg(afm_id, size, option_notused, actual_size, \
4077 filename, line) \
4078 kal_afm_internal_alloc_cacheable(afm_id, size, actual_size, filename, line)
4079#else
4080#define __kal_afm_alloc_cacheable(afm_id, size, option_notused) \
4081 kal_afm_internal_alloc(afm_id, size, NULL, __FILE__, __LINE__)
4082#define __kal_afm_alloc_cacheable_dbg(afm_id, size, option_notused, actual_size, \
4083 filename, line) \
4084 kal_afm_internal_alloc(afm_id, size, actual_size, filename, line)
4085#endif
4086/*******************************************************************************
4087 * <GROUP Functions>
4088 *
4089 * FUNCTION
4090 * kal_afm_alloc_cacheable
4091 * DESCRIPTION
4092 * allocate a memory buffer which is cacheable from AFM.
4093 * PARAMETERS
4094 * afm_id: [IN] AFM pool identity.
4095 * size: [IN] request memory size.
4096 * option_notused: [IN] useless, ignored.
4097 * RETURNS
4098 * allocated memory buffer pointer. return NULL if no memory available.
4099 * NOTE
4100 * (1)the prototype of this API is:
4101 * void *kal_afm_alloc_cacheable(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 option_notused);
4102 * (2)This AFM must be created using AFM_OPT_ALIGN_ALLOC in kal_afm_create.
4103 * (3)The pointer is cacheable only on platform that has ARM MMU (such as ARM9/ARM11 platform).
4104 * If not, the pointer is still noncacheable.
4105 * SEE ALSO
4106 * kal_afm_create kal_afm_alloc_noncacheable kal_afm_free
4107 ******************************************************************************/
4108#define kal_afm_alloc_cacheable(afm_id, size, option_notused) \
4109 __kal_afm_alloc_cacheable(afm_id, size, option_notused)
4110#define kal_afm_alloc_cacheable_dbg(afm_id, size, option_notused, actual_size, \
4111 filename, line) \
4112 __kal_afm_alloc_cacheable_dbg(afm_id, size, option_notused, actual_size, \
4113 filename, line)
4114
4115extern void *kal_afm_internal_alloc_noncacheable(KAL_AFM_ID afm_id, kal_uint32 size,
4116 kal_uint32 *actual_size,
4117 char *filename, kal_uint32 line);
4118#if defined(__MTK_TARGET__) && \
4119 (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
4120#define __kal_afm_alloc_noncacheable(afm_id, size, option_notused) \
4121 kal_afm_internal_alloc_noncacheable(afm_id, size, NULL, __FILE__, __LINE__)
4122#define __kal_afm_alloc_noncacheable_dbg(afm_id, size, option_notused, actual_size, \
4123 filename, line) \
4124 kal_afm_internal_alloc_noncacheable(afm_id, size, actual_size, filename, line)
4125#else
4126#define __kal_afm_alloc_noncacheable(afm_id, size, option_notused) \
4127 kal_afm_internal_alloc(afm_id, size, NULL, __FILE__, __LINE__)
4128#define __kal_afm_alloc_noncacheable_dbg(afm_id, size, option_notused, actual_size, \
4129 filename, line) \
4130 kal_afm_internal_alloc(afm_id, size, actual_size, filename, line)
4131#endif
4132/*******************************************************************************
4133 * <GROUP Functions>
4134 *
4135 * FUNCTION
4136 * kal_afm_alloc_noncacheable
4137 * DESCRIPTION
4138 * allocate a memory buffer which is noncacheable from AFM.
4139 * PARAMETERS
4140 * adm_id: [IN] ADM pool identity.
4141 * size: [IN] request memory size.
4142 * option_notused: [IN] useless, ignored.
4143 * RETURNS
4144 * allocated memory buffer pointer. return NULL if no memory available.
4145 * NOTE
4146 * (1)the prototype of this API is:
4147 * void *kal_afm_alloc_noncacheable(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 option_notused);
4148 * (2)This AFM must be created using AFM_OPT_ALIGN_ALLOC in kal_afm_create.
4149 * SEE ALSO
4150 * kal_afm_create kal_afm_alloc_cacheable kal_afm_free
4151 ******************************************************************************/
4152#define kal_afm_alloc_noncacheable(afm_id, size, option_notused) \
4153 __kal_afm_alloc_noncacheable(afm_id, size, option_notused)
4154#define kal_afm_alloc_noncacheable_dbg(afm_id, size, option_notused, actual_size, \
4155 filename, line) \
4156 __kal_afm_alloc_noncacheable_dbg(afm_id, size, option_notused, actual_size, \
4157 filename, line)
4158
4159/* DOM-NOT_FOR_SDK-BEGIN */
4160extern kal_int32 kal_afm_print_log(KAL_AFM_ID afm_id);
4161extern kal_int32 kal_afm_get_subpool_num(KAL_AFM_ID afm_id);
4162extern kal_int32 kal_afm_info_get(KAL_AFM_ID afm_id, kal_uint32 *option,
4163 kal_uint32 *buff_size, kal_uint32 *buff_nr,
4164 kal_uint32 *left_buf_nr,
4165 kal_uint32 *total_left_mem_sz);
4166extern kal_int32 kal_afm_custom_performance_info_get(
4167 KAL_AFM_ID afm_id, kal_uint32 *option, kal_uint32 *buff_size,
4168 kal_uint32 *buff_nr, kal_uint32 *alloc_cnt, kal_uint32 *min_left_buf_nr);
4169extern kal_int32 kal_afm_set_cuslogging(KAL_AFM_ID afm_id, kal_uint32 cus_log_opt);
4170extern kal_int32 kal_afm_get_cuslogging(KAL_AFM_ID afm_id, kal_uint32 *cus_log_opt);
4171extern kal_int32 kal_afm_get_left_subpool_num(KAL_AFM_ID afm_id, kal_uint32 size);
4172extern kal_uint32 kal_afm_get_buff_size(KAL_AFM_ID afm_id, void *user_addr);
4173/* DOM-NOT_FOR_SDK-END */
4174
4175
4176/* DOM-NOT_FOR_SDK-BEGIN */
4177/*******************************************************************************
4178 * Category 7 : System and Modem Memory Management
4179 *******************************************************************************/
4180extern void *get_ctrl_buffer_ext(kal_uint32 size, const kal_char *file_name,
4181 kal_uint32 line);
4182extern void free_ctrl_buffer_ext(void *buff_ptr, const kal_char *file_name,
4183 kal_uint32 line);
4184extern kal_uint32 query_ctrl_buffer_ext(kal_uint32 size);
4185
4186#if defined(DEBUG_KAL) && defined(DEBUG_BUF2)
4187#define __get_ctrl_buffer(size) get_ctrl_buffer_ext(size, __FILE__, __LINE__)
4188#define __free_ctrl_buffer(ptr) free_ctrl_buffer_ext(ptr, __FILE__, __LINE__)
4189#else /* DEBUG_KAL && DEBUG_BUF2 */
4190#define __get_ctrl_buffer(size) get_ctrl_buffer_ext(size, NULL, 0)
4191#define __free_ctrl_buffer(ptr) free_ctrl_buffer_ext(ptr, NULL, 0)
4192#endif /* DEBUG_KAL && DEBUG_BUF2 */
4193
4194/*******************************************************************************
4195 * <GROUP Functions>
4196 *
4197 * FUNCTION
4198 * get_ctrl_buffer
4199 * DESCRIPTION
4200 * get a memory block at least size bytes from ctrl buffer.
4201 * PARAMETERS
4202 * size: [IN] request memory block.
4203 * RETURNS
4204 * memory block pointer. If all memory blocks used in corresponding ctrl buffer
4205 * used up, system enter fatal error handling.
4206 * NOTE
4207 * (1)This API should be used in protocol stack only.
4208 * SEE ALSO
4209 * free_ctrl_buffer
4210 ******************************************************************************/
4211#define get_ctrl_buffer(size) __get_ctrl_buffer(size)
4212/*******************************************************************************
4213 * <GROUP Functions>
4214 *
4215 * FUNCTION
4216 * free_ctrl_buffer
4217 * DESCRIPTION
4218 * free a memory block allocated from ctrl buffer.
4219 * PARAMETERS
4220 * ptr: [IN] memory block pointer.
4221 * RETURNS
4222 * N/A
4223 * NOTE
4224 * (1)This API should be used in protocol stack only.
4225 * SEE ALSO
4226 * get_ctrl_buffer
4227 ******************************************************************************/
4228#define free_ctrl_buffer(ptr) __free_ctrl_buffer(ptr)
4229/*******************************************************************************
4230 * <GROUP Functions>
4231 *
4232 * FUNCTION
4233 * free_ctrl_buffer_set_null
4234 * DESCRIPTION
4235 * free a memory block allocated from ctrl buffer. then set pointer as null
4236 * PARAMETERS
4237 * ptr: [IN] memory block pointer.
4238 * RETURNS
4239 * N/A
4240 * NOTE
4241 * (1)This API should be used in protocol stack only.
4242 * SEE ALSO
4243 * get_ctrl_buffer
4244 ******************************************************************************/
4245#define free_ctrl_buffer_set_null(ptr) \
4246 do { \
4247 __free_ctrl_buffer(ptr); \
4248 ptr = NULL; \
4249 } while (0)
4250/*******************************************************************************
4251 * <GROUP Functions>
4252 *
4253 * FUNCTION
4254 * query_ctrl_buffer
4255 * DESCRIPTION
4256 * query the avaiable memory blocks from ctrl buffer
4257 * PARAMETERS
4258 * size: [IN] request memory block.
4259 * RETURNS
4260 * the number of avaiable memory blocks
4261 * SEE ALSO
4262 * get_ctrl_buffer
4263 ******************************************************************************/
4264#define query_ctrl_buffer(size) query_ctrl_buffer_ext(size)
4265/*******************************************************************************
4266 * <GROUP Functions>
4267 *
4268 * FUNCTION
4269 * kal_debug_cbs_leakage_check_start
4270 * DESCRIPTION
4271 * enable control buffer leakage check.
4272 * PARAMETERS
4273 * N/A
4274 * RETURNS
4275 * N/A
4276 * SEE ALSO
4277 *
4278 ******************************************************************************/
4279void kal_debug_cbs_leakage_check_start(void);
4280void kal_debug_cbs_leakage_check_stop(void);
4281
4282extern kal_bool kal_set_sensitive_buff_ext(void *buff_ptr);
4283/*******************************************************************************
4284 * <GROUP Functions>
4285 *
4286 * FUNCTION
4287 * kal_set_sensitive_buff
4288 * DESCRIPTION
4289 * set the buffer as a sensitive data buffer.
4290 * PARAMETERS
4291 * buff_ptr: [IN] memory block pointer.
4292 * RETURNS
4293 * N/A
4294 * SEE ALSO
4295 *
4296 ******************************************************************************/
4297#define kal_set_sensitive_buff(ptr) kal_set_sensitive_buff_ext(ptr)
4298
4299/* DOM-NOT_FOR_SDK-END */
4300/*******************************************************************************
4301 * Category 8 : Timer Service
4302 *******************************************************************************/
4303
4304/*******************************************************************************
4305 * <GROUP Functions>
4306 *
4307 * FUNCTION
4308 * kal_get_systicks
4309 * DESCRIPTION
4310 * return elapsed system ticks from boot up
4311 * PARAMETERS
4312 * N/A
4313 * RETURNS
4314 * elapsed system ticks from boot up
4315 * NOTE
4316 * (1)Each tick is KAL_MILLISECS_PER_TICK miliseconds.
4317 * SEE ALSO
4318 * KAL_MILLISECS_PER_TICK
4319 ******************************************************************************/
4320extern kal_uint32 kal_get_systicks(void);
4321/*******************************************************************************
4322 * <GROUP Functions>
4323 *
4324 * FUNCTION
4325 * kal_secs_to_ticks
4326 * DESCRIPTION
4327 * convert seconds to system ticks
4328 * PARAMETERS
4329 * secs : [IN] seconds
4330 * RETURNS
4331 * corresponding system ticks
4332 * NOTE
4333 * This functions is equvilent to (secs * 1000 / KAL_MILLISECS_PER_TICK).
4334 * It uses table lookup to avoid floating division to speed up.
4335 * SEE ALSO
4336 * kal_milli_secs_to_ticks KAL_MILLISECS_PER_TICK
4337 ******************************************************************************/
4338extern kal_uint32 kal_secs_to_ticks(kal_uint32 secs);
4339extern kal_uint32 kal_secs_to_ticks_real(kal_uint32 secs);
4340/*******************************************************************************
4341 * <GROUP Functions>
4342 *
4343 * FUNCTION
4344 * kal_milli_secs_to_ticks
4345 * DESCRIPTION
4346 * convert milliseconds to system ticks
4347 * PARAMETERS
4348 * milli_secs : [IN] milliseconds
4349 * RETURNS
4350 * corresponding system ticks
4351 * NOTE
4352 * This functions is equvilent to ( ( milli_secs + KAL_MILLISECS_PER_TICK / 2 ) / KAL_MILLISECS_PER_TICK).
4353 * It uses table lookup to avoid floating division to speed up.
4354 * SEE ALSO
4355 * kal_milli_secs_to_ticks KAL_MILLISECS_PER_TICK
4356 ******************************************************************************/
4357extern kal_uint32 kal_milli_secs_to_ticks(kal_uint32 milli_secs);
4358extern kal_uint32 kal_milli_secs_to_ticks_real(kal_uint32 milli_secs);
4359/*******************************************************************************
4360 * <GROUP Functions>
4361 *
4362 * FUNCTION
4363 * kal_ticks_to_secs
4364 * DESCRIPTION
4365 * convert system ticks to seconds
4366 * PARAMETERS
4367 * ticks : [IN] ticks count
4368 * RETURNS
4369 * corresponding seconds
4370 * NOTE
4371 * This functions is equvilent to (ticks * KAL_MILLISECS_PER_TICK / 1000).
4372 * It uses table lookup to avoid floating multiplication to speed up.
4373 * SEE ALSO
4374 * kal_ticks_to_milli_secs KAL_MILLISECS_PER_TICK
4375 ******************************************************************************/
4376extern kal_uint32 kal_ticks_to_secs(kal_uint32 ticks);
4377extern kal_uint32 kal_ticks_to_secs_real(kal_uint32 ticks);
4378/*******************************************************************************
4379 * <GROUP Functions>
4380 *
4381 * FUNCTION
4382 * kal_ticks_to_milli_secs
4383 * DESCRIPTION
4384 * convert system ticks to milliseconds
4385 * PARAMETERS
4386 * ticks : [IN] ticks count
4387 * RETURNS
4388 * corresponding milliseconds
4389 * NOTE
4390 * This functions is equvilent to (ticks * KAL_MILLISECS_PER_TICK).
4391 * It uses table lookup to avoid floating multiplication to speed up.
4392 * SEE ALSO
4393 * kal_ticks_to_secs KAL_MILLISECS_PER_TICK
4394 ******************************************************************************/
4395extern kal_uint32 kal_ticks_to_milli_secs(kal_uint32 ticks);
4396extern kal_uint32 kal_ticks_to_milli_secs_real(kal_uint32 ticks);
4397
4398/*******************************************************************************
4399 * Category 8 : Timer Service
4400 *******************************************************************************/
4401/*************************************************************************
4402 * Exported Function Prototypes for KAL timer
4403 *************************************************************************/
4404
4405/* DOM-NOT_FOR_SDK-BEGIN */
4406/*******************************************************************************
4407 * <GROUP Functions>
4408 *
4409 * FUNCTION
4410 * kal_create_timer
4411 * DESCRIPTION
4412 * create a kal timer.
4413 * PARAMETERS
4414 * timer_name : [IN] timer name. It's used for debug only, and only the
4415 * first 8 characters retain.
4416 * RETURNS
4417 * Success: timer pointer.
4418 * Error: system enter fatal error handling.
4419 * NOTE
4420 * (1)It is strongly suggested to call this function only at system initialization stage,
4421 * and the related data allocated for the timer could not be freed once it is created.
4422 * (2)kal timer API is not thread safe and it's strongly suggested to use it
4423 * in single task/HISR only.
4424 * SEE ALSO
4425 * kal_set_timer kal_cancel_timer kal_get_remaining_time kal_enable_delayed_timer kal_disable_delayed_timer
4426 ******************************************************************************/
4427kal_timerid kal_create_timer(kal_char *timer_name);
4428/*******************************************************************************
4429 * <GROUP Functions>
4430 *
4431 * FUNCTION
4432 * kal_set_timer
4433 * DESCRIPTION
4434 * start a kal timer.
4435 * PARAMETERS
4436 * timer_ptr : [IN] timer pointer.
4437 * handler_func_ptr: [IN] pointer of timeout handler, it will be called after
4438 * timeout happens
4439 * handler_param_ptr: [IN] user supply argument for handler_func_ptr
4440 * delay: [IN] timeout duration in terms of time ticks, the maximum value is 0xFFFFFFFF
4441 * reschedule_time: [IN] reset delay to reschedule_time after timeout happens.
4442 * If it's zero, no reschedule happens and the timer is one-shot.
4443 * Otherwise, it's a periodic timer.
4444 * RETURNS
4445 * N/A
4446 * NOTE
4447 * kal_set_timer will cancel previous set timeout event on this timer, and
4448 * start a new one.
4449 * SEE ALSO
4450 * kal_create_timer kal_cancel_timer kal_get_remaining_time kal_enable_delayed_timer kal_disable_delayed_timer
4451 ******************************************************************************/
4452void kal_set_timer(kal_timerid timer_ptr, kal_timer_func_ptr handler_func_ptr,
4453 void *handler_param_ptr, kal_uint32 delay,
4454 kal_uint32 reschedule_time);
4455/*******************************************************************************
4456 * <GROUP Functions>
4457 *
4458 * FUNCTION
4459 * kal_cancel_timer
4460 * DESCRIPTION
4461 * cancel a kal timer.
4462 * PARAMETERS
4463 * timer_ptr : [IN] timer pointer.
4464 * RETURNS
4465 * N/A
4466 * NOTE
4467 * Please note that canceling timer inside HISR may cancel a timer which is
4468 * in expired stage but the callback function not yet been serviced.
4469 * SEE ALSO
4470 * kal_create_timer kal_set_timer kal_get_remaining_time kal_enable_delayed_timer kal_disable_delayed_timer
4471 ******************************************************************************/
4472void kal_cancel_timer(kal_timerid timer_ptr);
4473/*******************************************************************************
4474 * <GROUP Functions>
4475 *
4476 * FUNCTION
4477 * kal_get_remaining_time
4478 * DESCRIPTION
4479 * retrieve the remaining timeout period in units of time ticks
4480 * PARAMETERS
4481 * timer_ptr : [IN] timer pointer.
4482 * RETURNS
4483 * N/A
4484 * SEE ALSO
4485 * kal_create_timer kal_set_timer kal_cancel_timer kal_enable_delayed_timer kal_disable_delayed_timer
4486 ******************************************************************************/
4487kal_uint32 kal_get_remaining_time(kal_timerid timer_ptr);
4488/*******************************************************************************
4489 * <GROUP Functions>
4490 *
4491 * FUNCTION
4492 * kal_enable_delayed_timer
4493 *
4494 * DESCRIPTION
4495 * This routine implements to set the timer as an aligned timer, the max delay feature will be kept
4496 * until kal_disable_delayed_timer() is invoked.
4497 * Application Scenario is listed below:
4498 * case 1: for target_API = [ kal_sleep_task(), kal_retrieve_eg_events_timeout() ]
4499 *
4500 * --> status = kal_enable_delayed_timer(NULL, max_delay);
4501 *
4502 * Attention:
4503 * a. the API return value(status) must be checked: KAL_SUCCESS -> success, others -> fail
4504 * b. max_delay is in ticks, not ms, if you want to set max delay time to (x ms), you
4505 * should use this API like this:
4506 * --> status = kal_enable_delayed_timer(NULL, kal_milli_secs_to_ticks(x));
4507 *
4508 * case 2: for target_API = [ kal_set_timer() ]
4509 *
4510 * --> status = kal_enable_delayed_timer(TIMER_ID, max_delay);
4511 *
4512 * Attention:
4513 * a. the API return value(status) must be checked: KAL_SUCCESS -> success, others -> fail
4514 * b. max_delay is in ticks, not ms, if you want to set max delay time to (x ms), you
4515 * should use this API like this:
4516 * --> status = kal_enable_delayed_timer(TIMER_ID, kal_milli_secs_to_ticks(x));
4517 *
4518 * PARAMETERS
4519 * ext_timer: Id of the timer
4520 * max_delay : max delay ticks
4521 * RETURNS
4522 * KAL_SUCCESS --> success
4523 * KAL_TIMER_NON_TASK_CONTEXT --> invoked illegally in NON-Task context
4524 * KAL_TIMER_INVALID_TIMER_ID --> KAL timer ID is invalid
4525 * KAL_TIMER_MAX_DELAY_OUT_OF_RANGE --> max delay ticks is out of range
4526 * SEE ALSO
4527 * kal_create_timer kal_set_timer kal_cancel_timer kal_get_remaining_time kal_disable_delayed_timer
4528 ******************************************************************************/
4529kal_status kal_enable_delayed_timer(kal_timerid ext_timer, kal_uint32 max_delay);
4530/*******************************************************************************
4531 * <GROUP Functions>
4532 *
4533 * FUNCTION
4534 * kal_disable_delayed_timer
4535 *
4536 * DESCRIPTION
4537 * This routine implements to set the timer as an unaligned timer. normally this API will be used with
4538 * kal_enable_delayed_timer together.
4539 * Application Scenario is listed below:
4540 * case 1: for target_API = [ kal_sleep_task(), kal_retrieve_eg_events_timeout() ]
4541 *
4542 * status = kal_disable_delayed_timer(NULL);
4543 *
4544 * case 2: for target_API = [ kal_set_timer() ]
4545 *
4546 * status = kal_disable_delayed_timer(TIMER_ID);
4547 *
4548 * Attention:
4549 * a. the API return value(status) must be checked: KAL_SUCCESS -> success, others -> fail
4550 * b. max delay feature will be kept unchanged if kal_disable_delayed_timer() isn't invoked.
4551 *
4552 * PARAMETERS
4553 * ext_timer: Id of the timer
4554 * RETURNS
4555 * KAL_SUCCESS --> success
4556 * KAL_TIMER_NON_TASK_CONTEXT --> invoked illegally in NON-Task context
4557 * SEE ALSO
4558 * kal_create_timer kal_set_timer kal_cancel_timer kal_get_remaining_time kal_enable_delayed_timer
4559 ******************************************************************************/
4560kal_status kal_disable_delayed_timer(kal_timerid ext_timer);
4561
4562/* DOM-NOT_FOR_SDK-END */
4563
4564/*************************************************************************
4565 * Exported Function Prototypes for event scheduler
4566 *************************************************************************/
4567
4568/*******************************************************************************
4569 * <GROUP CallBackFunctions>
4570 *
4571 * FUNCTION
4572 * malloc_fp_t
4573 * DESCRIPTION
4574 * pointer to a function that can allocation memory like malloc.
4575 * PARAMETERS
4576 * size: [IN] request memory size in byte.
4577 * RETURNS
4578 * Successful: memory pointer.
4579 * Fail: NULL.
4580 ******************************************************************************/
4581typedef void *(*malloc_fp_t)(unsigned int size);
4582/*******************************************************************************
4583 * <GROUP CallBackFunctions>
4584 *
4585 * FUNCTION
4586 * realloc_fp_t
4587 * DESCRIPTION
4588 * pointer to a function that can re-allocation memory like realloc.
4589 * PARAMETERS
4590 * ptr: [IN] old pointer.
4591 * new_size: [IN] new request memory size in byte.
4592 * RETURNS
4593 * Successful: memory pointer.
4594 * Fail: NULL.
4595 ******************************************************************************/
4596typedef void *(*realloc_fp_t)(void *ptr, unsigned int new_size);
4597/*******************************************************************************
4598 * <GROUP CallBackFunctions>
4599 *
4600 * FUNCTION
4601 * free_fp_t
4602 * DESCRIPTION
4603 * pointer to a function that can free memory like free.
4604 * PARAMETERS
4605 * ptr: [IN] memory pointer to be free.
4606 * RETURNS
4607 * N/A
4608 ******************************************************************************/
4609typedef void (*free_fp_t)(void *ptr);
4610
4611/*******************************************************************************
4612 * <GROUP Functions>
4613 *
4614 * FUNCTION
4615 * evshed_create
4616 * DESCRIPTION
4617 * create a new event scheduler.
4618 * PARAMETERS
4619 * timer_name: [IN] event scheduler name. it's used for debug only, and only the
4620 * first 8 characters retain.
4621 * dest_mod_id: [IN] the module this event scheduler belongs to. When event scheduler
4622 * timeout happens, system sent timeout message to task of this module.
4623 * fuzz: [IN]
4624 * Timer inaccuracy in ticks that the event scheduler allow, regardless of sleep mode.
4625 * If set, the event may delay or prematurely timeout for maximum fuzz ticks.
4626 * If don't like it, just set it to 0.
4627 *
4628 * Advantage -
4629 * Set this argument will save you a lot of CPU resource if the events are frequent and close to each other.
4630 *
4631 * max_delay_ticks: [IN]
4632 * Behaviour -
4633 * Time inaccuracy in ticks the event scheduler allow, due to target enters sleep mode.
4634 * The event may delay for max max_delay_ticks tick if the target enters sleep mode,
4635 * so that the target can sleep longer. The event will suffer no delay if the target doesn't enter sleep mode.
4636 *
4637 * Advantage -
4638 * Set this argument will save the target a lot of power. You are encouraged to set this value for the sake of power.
4639 *
4640 * Note -
4641 * max_delay_ticks = 0 ~ (MAX_DELAY_UNLIMITED - 1) ticks, exact delay ticks
4642 * max_delay_ticks = MAX_DELAY_UNLIMITED ticks, won't wake up MCU from sleep (maximum save power).
4643 *
4644 * RETURNS
4645 * Successful: created event scheduler pointer.
4646 * Fail: system enter fatal error handling.
4647 * NOTE
4648 * (1)This API replaces new_evshed(). And new_evshed() is deprecated,
4649 * it will be removed from next release.
4650 * (2)It is strongly suggested to call this function only at system initialization stage.
4651 * and There is no way to free the event schedule data structure once allocated.
4652 * (3)Event scheduler is not thread safe, if you want to share it in multi-task/hisr,
4653 * please use lock to protect it.
4654 * (4)To reduce power consumption, it's strongly suggested to set max_delay_ticks.
4655 * (5)The inaccuracy of event scheduler comes from
4656 * schedule delay - Time lisr, Time HISR, the owner task may be preempted.
4657 * Task handling message delay - There may be many ILMs to handle before the event expired ILM gets handled
4658 * fuzz
4659 * max_delay_ticks
4660 * SEE ALSO
4661 * evshed_set_event evshed_cancel_event evshed_timer_handler
4662 ******************************************************************************/
4663extern event_scheduler *evshed_create(kal_char *timer_name, module_type dest_mod_id,
4664 kal_uint32 fuzz,
4665 kal_uint32 max_delay_ticks);
4666#define HAS_EVSHED_CREATE 1
4667
4668/*******************************************************************************
4669 * <GROUP Functions>
4670 *
4671 * FUNCTION
4672 * evshed_set_index
4673 * DESCRIPTION
4674 * Set timer_index to distinguish many event schedulers.
4675 * The default timer index is 0.
4676 * PARAMETERS
4677 * es_usr: [IN] event scheduler id returned by evshed_create
4678 * timer_index: [IN] timer index given by user
4679 * RETURNS
4680 * None
4681 ******************************************************************************/
4682extern void evshed_set_index(event_scheduler *es, kal_uint16 timer_index);
4683#define HAS_EVSHED_SET_INDEX 1
4684
4685/*******************************************************************************
4686 * <GROUP Functions>
4687 *
4688 * FUNCTION
4689 * evshed_get_index
4690 * DESCRIPTION
4691 * Get the index set by evshed_set_index
4692 * PARAMETERS
4693 * expired_ilm: [IN] The ilm sent by expired event and got from task queue
4694 * RETURNS
4695 * Sucessful: The timer index of kal_uint32
4696 * Fail: Fatal error if wrong ilm input
4697 ******************************************************************************/
4698extern kal_uint16 evshed_get_index(ilm_struct *expired_ilm);
4699#define HAS_EVSHED_GET_INDEX 1
4700/*******************************************************************************
4701 * <GROUP Functions>
4702 *
4703 * FUNCTION
4704 * evshed_set_event
4705 * DESCRIPTION
4706 * set an event on event scheduler.
4707 * PARAMETERS
4708 * es: [IN] event scheduler pointer.
4709 * event_hf: [IN] the callback function when event timeout.
4710 * event_hf_param: [IN] the user supplied argument for event_hf.
4711 * elapse_time: [IN] how many system ticks elapses before this event timeout.
4712 * RETURNS
4713 * Successful: return set eventid.
4714 * Fail: return NULL.
4715 * NOTE
4716 * System will allocate memory for event id, it will be freed automatically when
4717 * a. event is cancelled
4718 * b. event expired
4719 * It's not allowed to use the event id after above cases.
4720 * If the event id is saved, please be careful to reset it.
4721 * SEE ALSO
4722 * evshed_create evshed_cancel_event evshed_timer_handler
4723 ******************************************************************************/
4724extern eventid evshed_set_event(event_scheduler *es, kal_timer_func_ptr event_hf,
4725 void *event_hf_param, kal_uint32 elapse_time);
4726/*******************************************************************************
4727 * <GROUP Functions>
4728 *
4729 * FUNCTION
4730 * evshed_set_event_userid
4731 * DESCRIPTION
4732 * set an event on event scheduler, and give this event an user id
4733 * PARAMETERS
4734 * es: [IN] event scheduler pointer.
4735 * event_hf: [IN] the callback function when event timeout.
4736 * event_hf_param: [IN] the user supplied argument for event_hf.
4737 * elapse_time: [IN] how many system ticks elapses before this event timeout.
4738 * event_user_id: [IN] User can input an id to distinct the events.
4739 * RETURNS
4740 * Successful: return set eventid.
4741 * Fail: return NULL.
4742 * NOTE
4743 * System will allocate memory for event id, it will be freed automatically when
4744 * a. event is cancelled
4745 * b. event expired
4746 * It's not allowed to use the event id after above cases.
4747 * If the event id is saved, please be careful to reset it.
4748 * SEE ALSO
4749 * evshed_create evshed_cancel_event evshed_timer_handler
4750 ******************************************************************************/
4751extern eventid evshed_set_event_userid(event_scheduler *es,
4752 kal_timer_func_ptr event_hf,
4753 void *event_hf_param, kal_uint32 elapse_time,
4754 kal_uint32 event_user_id);
4755#define HAS_EVSHED_SET_EVENT_USERID 1
4756
4757/*******************************************************************************
4758 * <GROUP Functions>
4759 *
4760 * FUNCTION
4761 * evshed_get_event_userid
4762 * DESCRIPTION
4763 * Get the user id, inputted in evshed_set_event_userid
4764 * PARAMETERS
4765 * user_eventid: [IN] eventid returned by evshed_set_event_userid
4766 * RETURNS
4767 * Successful: returns kal_uint32
4768 * Fail: If user_eventid is NULL, fatal error
4769 * SEE ALSO
4770 * evshed_create evshed_cancel_event evshed_timer_handler
4771 ******************************************************************************/
4772extern kal_uint32 evshed_get_event_userid(eventid user_eventid);
4773#define HAS_EVSHED_GET_EVENT_USERID 1
4774/*******************************************************************************
4775 * <GROUP Functions>
4776 *
4777 * FUNCTION
4778 * evshed_cancel_event
4779 * DESCRIPTION
4780 * cancel a event on event scheduler.
4781 * PARAMETERS
4782 * es: [IN] event scheduler pointer.
4783 * eid: [IN,OUT] pointer to event id.
4784 * RETURNS
4785 * Successful: remain ticks before this event expires.
4786 * Fail: -1.
4787 * NOTE
4788 * (1)system would reset the event ID (eid) to NULL before returning; however,
4789 * caller should pay attention to its privately saved event id
4790 * SEE ALSO
4791 * evshed_create evshed_set_event evshed_timer_handler evshed_delete_all_events
4792 ******************************************************************************/
4793extern kal_int32 evshed_cancel_event(event_scheduler *es, eventid *eid);
4794/*******************************************************************************
4795 * <GROUP Functions>
4796 *
4797 * FUNCTION
4798 * evshed_get_remaining_time
4799 * DESCRIPTION
4800 * get remain ticks before this event expires.
4801 * PARAMETERS
4802 * es: [IN] event scheduler pointer.
4803 * eid: [IN] event id.
4804 * RETURNS
4805 * Successful: remain ticks before this event expires.
4806 ******************************************************************************/
4807extern kal_uint32 evshed_get_remaining_time(event_scheduler *es, eventid eid);
4808
4809/*******************************************************************************
4810 * <GROUP Functions>
4811 *
4812 * FUNCTION
4813 * evshed_delete_all_events
4814 * DESCRIPTION
4815 * delete and cancel all events on event scheduler.
4816 * PARAMETERS
4817 * es: [IN] event scheduler pointer.
4818 * RETURNS
4819 * N/A
4820 * SEE ALSO
4821 * evshed_create evshed_set_event evshed_timer_handler evshed_delete_all_events
4822 *****************************************************************************/
4823extern void evshed_delete_all_events(event_scheduler *es);
4824/*******************************************************************************
4825 * <GROUP Functions>
4826 *
4827 * FUNCTION
4828 * evshed_timer_handler
4829 * DESCRIPTION
4830 * event scheduler main function. It will check all set events status, and call
4831 * the callback function if they are expired.
4832 *
4833 * PARAMETERS
4834 * es: [IN] event scheduler pointer.
4835 * RETURNS
4836 * N/A
4837 * NOTE
4838 * (1)it's not thread-safe. Don't use in parallel.
4839 * (2)If an event is expired, the eventid is freed automatically and don't use it any more.
4840 * In evshed_timer_handler(), system would execute event registered timeout callback function.
4841 * Caller should reset saved event id in registered timeout callback function,
4842 * or cause potential bug to cancel wrong timer event.
4843 * SEE ALSO
4844 * evshed_create evshed_set_event evshed_cancel_event evshed_delete_all_events
4845 *****************************************************************************/
4846extern void evshed_timer_handler(event_scheduler *es);
4847/*******************************************************************************
4848 * <GROUP Functions>
4849 *
4850 * FUNCTION
4851 * evshed_has_pending_events
4852 * DESCRIPTION
4853 * query there is any event pending (not yet expired).
4854 * PARAMETERS
4855 * es: [IN] event scheduler pointer.
4856 * RETURNS
4857 * return KAL_TRUE or KAL_FALSE.
4858 * NOTE
4859 *****************************************************************************/
4860extern kal_bool evshed_has_pending_events(event_scheduler *es);
4861
4862/*******************************************************************************
4863 * <GROUP Functions>
4864 *
4865 * FUNCTION
4866 * evshed_suspend_all_events
4867 * DESCRIPTION
4868 * suspend all of the events set on an event scheduler.
4869 * PARAMETERS
4870 * es: [IN] event scheduler pointer.
4871 * RETURNS
4872 * N/A
4873 * SEE ALSO
4874 * evshed_resume_all_events
4875 *****************************************************************************/
4876extern void evshed_suspend_all_events(event_scheduler *es);
4877/*******************************************************************************
4878 * <GROUP Functions>
4879 *
4880 * FUNCTION
4881 * evshed_resume_all_events
4882 * DESCRIPTION
4883 * resume all of the events set on an event scheduler.
4884 * PARAMETERS
4885 * es: [IN] event scheduler pointer.
4886 * RETURNS
4887 * N/A
4888 * SEE ALSO
4889 * evshed_suspend_all_events
4890 *****************************************************************************/
4891extern void evshed_resume_all_events(event_scheduler *es);
4892
4893/*******************************************************************************
4894 * <GROUP Functions>
4895 *
4896 * FUNCTION
4897 * evshed_enable_protect_property
4898 * DESCRIPTION
4899 * using mutex to protect the operation of event seheduler to avoid race condition whiler it is
4900 * shared by multi-task
4901 * PARAMETERS
4902 * es: [IN] event scheduler pointer.
4903 * RETURNS
4904 * N/A
4905 * NOTE
4906 * (1) Event scheduler is not thread safe, if you want to share it in multi-task,
4907 * You can use lock to protect it while using operation of event scheduler.
4908 * This API is designed for it. Please call this function after calling evshed_create,
4909 * then event scheduler is thread safe without using lock.
4910 * (2) If this is called, the "expired" event could not be deleted by evshed_cancel_event()
4911 * SEE ALSO
4912 * evshed_create
4913 *****************************************************************************/
4914extern void evshed_enable_protect_property(event_scheduler *es);
4915
4916
4917/* DOM-NOT_FOR_SDK-BEGIN */
4918/*******************************************************************************
4919 * Category 9 : Error Handling
4920 *******************************************************************************/
4921#include "kal_ex_api.h"
4922
4923/* DOM-NOT_FOR_SDK-BEGIN */
4924
4925/*******************************************************************************
4926 * Category 10 --- Profiling
4927 *******************************************************************************/
4928
4929/*******************************************************************************
4930 * <GROUP Functions>
4931 *
4932 * FUNCTION
4933 * kal_profile_enable
4934 * DESCRIPTION
4935 * enable cpu usage profile.
4936 * PARAMETERS
4937 * N/A
4938 * RETURNS
4939 * N/A
4940 * SEE ALSO
4941 * kal_profile_get_cpu_usage
4942 ******************************************************************************/
4943void kal_profile_enable(void);
4944/*******************************************************************************
4945 * <GROUP Functions>
4946 *
4947 * FUNCTION
4948 * kal_profile_get_cpu_usage
4949 * DESCRIPTION
4950 * get cpu usage percentage, which is a float number at [0.0, 1.0].
4951 * PARAMETERS
4952 * N/A
4953 * RETURNS
4954 * cpu usage percentage.
4955 * SEE ALSO
4956 * kal_profile_enable
4957 ******************************************************************************/
4958float kal_profile_get_cpu_usage(void);
4959
4960/* DOM-NOT_FOR_SDK-END */
4961
4962/* DOM-NOT_FOR_SDK-BEGIN */
4963/*******************************************************************************
4964 * Category 11 : stack sharing
4965 *******************************************************************************/
4966/*******************************************************************************
4967 * <GROUP Functions>
4968 *
4969 * FUNCTION
4970 * kal_lock_current_stack
4971 * DESCRIPTION
4972 * to lock current stack to avoid sharing its memory with other tasks.
4973 * PARAMETERS
4974 * N/A
4975 * RETURNS
4976 * KAL_SUCCESS.
4977 * NOTE
4978 * this API is used when KAL_STACK_SHARING is enable,
4979 ******************************************************************************/
4980extern kal_uint32 kal_lock_current_stack();
4981
4982/*******************************************************************************
4983 * <GROUP Functions>
4984 *
4985 * FUNCTION
4986 * kal_unlock_current_stack
4987 * DESCRIPTION
4988 * to unlock current task's stack to sharing its memory with other tasks.
4989 * PARAMETERS
4990 * N/A
4991 * RETURNS
4992 * KAL_SUCCESS.
4993 * NOTE
4994 * this API is used when KAL_STACK_SHARING is enable,
4995 ******************************************************************************/
4996extern kal_uint32 kal_unlock_current_stack();
4997
4998/*******************************************************************************
4999 * Category Last ---
5000 *******************************************************************************/
5001
5002/* DOM-NOT_FOR_SDK-END */
5003
5004#ifdef __cplusplus
5005}
5006#endif
5007
5008#endif /* _KAL_PUBLIC_API_H */