[Feature]Upload Modem source code

Change-Id: Id4294f30faced84d3e6fd6d5e61e1111bf287a37
diff --git a/mcu/interface/service/kal/atomic.h b/mcu/interface/service/kal/atomic.h
new file mode 100644
index 0000000..56c1fb4
--- /dev/null
+++ b/mcu/interface/service/kal/atomic.h
@@ -0,0 +1,94 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2009
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   atomic.h
+ *
+ * Project:
+ * --------
+ *   MOLY
+ *
+ * Description:
+ * ------------
+ *   This header file defines the atomic operations.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ *
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+#ifndef __ATOMIC_H__
+#define __ATOMIC_H__
+
+typedef struct {
+    volatile int counter;
+} atomic_t;
+
+#define atomic_read(v)   (*(volatile int *)&(v)->counter)
+#define atomic_set(v, i) (((v)->counter) = (i))
+
+static INLINE int atomic_read_no_wait(const atomic_t *v, int *s)
+{
+   *s = 1;
+   return atomic_read(v);
+}
+
+static INLINE void atomic_set_no_wait(atomic_t *v, int i, int *s)
+{
+   *s = 1;
+   atomic_set(v, i);
+}
+
+#endif /* __ATOMIC_H__ */
diff --git a/mcu/interface/service/kal/clib.h b/mcu/interface/service/kal/clib.h
new file mode 100644
index 0000000..65855be
--- /dev/null
+++ b/mcu/interface/service/kal/clib.h
@@ -0,0 +1,144 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   clib.h
+ *
+ * Project:
+ * --------
+ *   Maui_Software
+ *
+ * Description:
+ * ------------
+ *   For C library type & function porting on MAUI.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ */
+
+#ifndef CLIB_H
+#define CLIB_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !defined(GEN_FOR_PC)
+
+#include <time.h>
+
+
+/* only check the not support function when building target */
+#if defined(__MTK_TARGET__)
+#include <sys/time.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <wchar.h>
+
+/* mark all using deprecated symbol as an error,except cplusplus */
+#if defined(__GNUC__) && !defined(__cplusplus)
+#pragma GCC diagnostic error "-Wdeprecated-declarations"
+#endif
+
+#define NOTSUPPORT_FUNCTION __attribute__((deprecated))
+#define INIT_NOTSUPPORT_FUNCTION
+#define LINKTIME_CHECKING
+#define WANT_CLIB_LIST
+#include "clib_list.h"
+
+#endif /*defined(__MTK_TARGET__)*/
+
+void clib_basic_init(void);
+void clib_init(void);
+void clib_init_time(void);
+
+
+#endif /* !GEN_FOR_PC */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/mcu/interface/service/kal/clib_list.h b/mcu/interface/service/kal/clib_list.h
new file mode 100644
index 0000000..5e7ba5f
--- /dev/null
+++ b/mcu/interface/service/kal/clib_list.h
@@ -0,0 +1,320 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   clib_list.h
+ *
+ * Project:
+ * --------
+ *   Maui_Software
+ *
+ * Description:
+ * ------------
+ *   C library function support level list 
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+
+
+/* Don't direct include this file. You should include kal_release.h. */
+/* functions is tagged by:
+ *    NOTSUPPORT_FUNCTION: NOT SUPPORT, that function is not allowed to be used
+ *    INIT_NOTSUPPORT_FUNCTION: NOT INIT TIME, not used in initialize phase
+ *    none of above 2: that functions is safe to be used in MAUI
+ *    LINKTIME_CHECKING: this not support function will be check in link time
+ */
+#ifndef WANT_CLIB_LIST
+#error "Do you really want this file"
+#endif
+
+#if defined(__GNUC__)
+#define __NOT_USED_SECTION __attribute__((section("SHOULD_NOT_USED_FUNCTION")))
+#else
+#define __NOT_USED_SECTION
+#endif
+
+/* in alloca.h ****************************************************************/
+#if defined(__GNUC__)
+__NOT_USED_SECTION void *alloca(size_t size) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+#else
+void *__alloca(size_t size) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+#endif
+
+/* in locale.h ****************************************************************/
+#if 0
+/* under construction !*/
+#endif /* 0 */
+
+/* in signal.h ****************************************************************/
+__NOT_USED_SECTION void (*signal(int sig, void (*func)(int)))(int)
+    NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int raise(int sig) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+
+/* in stdio.h *****************************************************************/
+__NOT_USED_SECTION int
+remove(const char *filename) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int
+rename(const char *old, const char *newname) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION FILE *tmpfile(void) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION char *tmpnam(char *s) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+
+
+/* in stdlib.h ****************************************************************/
+__NOT_USED_SECTION void *calloc(size_t nmemb, size_t size) NOTSUPPORT_FUNCTION;
+__NOT_USED_SECTION void *_calloc_r(struct _reent *reent,
+                                   size_t nmemb, size_t size) NOTSUPPORT_FUNCTION;
+__NOT_USED_SECTION void free(void *ptr) NOTSUPPORT_FUNCTION;
+__NOT_USED_SECTION void _free_r(struct _reent *reent, void *ptr) NOTSUPPORT_FUNCTION;
+__NOT_USED_SECTION void *malloc(size_t size) NOTSUPPORT_FUNCTION;
+__NOT_USED_SECTION void *_malloc_r(struct _reent *reent,
+                                   size_t size) NOTSUPPORT_FUNCTION;
+__NOT_USED_SECTION void *realloc(void *ptr, size_t size) NOTSUPPORT_FUNCTION;
+__NOT_USED_SECTION void *_realloc_r(struct _reent *reent,
+                                    void *ptr, size_t size) NOTSUPPORT_FUNCTION;
+
+__NOT_USED_SECTION int
+atexit(void (*func)(void)) NOTSUPPORT_FUNCTION; /* C++ library */
+/*Yinli: reslove building for GCC: 'noreturn' function does return.*/
+#if defined(__GNUC__)
+__NOT_USED_SECTION void exit(int status) NOTSUPPORT_FUNCTION;
+__NOT_USED_SECTION void _Exit(int status) NOTSUPPORT_FUNCTION;
+#else
+__NOT_USED_SECTION void exit(int status) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION void _Exit(int status) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+#endif
+__NOT_USED_SECTION char *
+getenv(const char *name) NOTSUPPORT_FUNCTION; /* C++ library */
+__NOT_USED_SECTION int
+system(const char *string) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION void 
+__assert_func(const char *file, int line, 
+              const char *func, const char *failedexpr) NOTSUPPORT_FUNCTION;
+
+/* in string.h ****************************************************************/
+__NOT_USED_SECTION char *strtok(char *__restrict s1, const char *__restrict s2)
+    NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION char *strdup(const char *s) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+
+/* in time.h ******************************************************************/
+struct tm;
+__NOT_USED_SECTION char *
+asctime(const struct tm *timeptr) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION char *
+ctime(const time_t *timer) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION struct tm *
+gmtime(const time_t *timer) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION struct tm *
+localtime(const time_t *timer) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+
+#if !(defined(__SUPPORT_CLIB_TIME__))
+__NOT_USED_SECTION time_t time(time_t *t) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION char *asctime_r(const struct tm *tim_p,
+                                   char *res) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION struct tm *
+gmtime_r(const time_t *tim_p, struct tm *res) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION struct tm *localtime_r(const time_t *tim_p, struct tm *res)
+    NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION char *ctime_r(const time_t *tim_p,
+                                 char *res) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+#endif
+
+
+__NOT_USED_SECTION void __aeabi_div0(void) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+/* default on_exit() will call malloc() to allocate deallocate function node 
+Moly won't exit so on_exit() don't need to save that */
+__NOT_USED_SECTION int on_exit(void (*func)(int, void *),
+                               void *arg) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+/*C++ library will link this function*/
+__NOT_USED_SECTION int puts(const char *s) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+#undef putchar
+__NOT_USED_SECTION int putchar(int c) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int vfprintf(FILE *__restrict stream,
+                                const char *__restrict format,
+                                va_list arg) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int fprintf(FILE *__restrict stream,
+                               const char *__restrict format,
+                               ...) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int fflush(FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int _fflush_r(struct _reent *ptr,
+                                 FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION void setbuf(FILE *__restrict stream, char *__restrict buf)
+    NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int setvbuf(FILE *__restrict stream, char *__restrict buf,
+                               int    mode,
+                               size_t size) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int fscanf(FILE *__restrict stream, const char *__restrict format,
+                              ...) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int scanf(const char *__restrict format,
+                             ...) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int vfscanf(FILE *__restrict stream,
+                               const char *__restrict format,
+                               va_list arg) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int vscanf(const char *__restrict format,
+                              va_list arg) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int fgetc(FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int fputc(int c, FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION char *fgets(char *__restrict s, int n, FILE *__restrict stream)
+    NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int fputs(const char *__restrict s, FILE *__restrict stream)
+    NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+#undef getc
+__NOT_USED_SECTION int getc(FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+#undef getchar
+__NOT_USED_SECTION int   getchar(void) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION char *gets(char *s) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+#undef putc
+__NOT_USED_SECTION int putc(int   c,
+                            FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int ungetc(int   c,
+                              FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int _ungetc_r(struct _reent *ptr, int c,
+                                 FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int fgetpos(FILE *__restrict stream, fpos_t *__restrict pos)
+    NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int fseek(FILE *stream, long int offset,
+                             int whence) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int fsetpos(FILE *__restrict stream, const fpos_t *__restrict pos)
+    NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION long int
+ftell(FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION void rewind(FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+#undef clearerr
+__NOT_USED_SECTION void clearerr(FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+#undef feof
+__NOT_USED_SECTION int feof(FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+#undef ferror
+__NOT_USED_SECTION int ferror(FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION FILE * fopen(const char *__restrict filename,
+      const char *__restrict mode) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION FILE *freopen(const char *__restrict filename, 
+      const char *__restrict mode,
+      FILE *__restrict stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int _fclose_r(struct _reent *ptr,
+	                             FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION int fclose(FILE *stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION size_t fread(void *__restrict ptr, size_t size, size_t nmemb,
+      FILE *__restrict stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION size_t fwrite(const void *__restrict ptr, size_t size, size_t nmemb,
+      FILE *__restrict stream) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
+__NOT_USED_SECTION void perror(const char * s) NOTSUPPORT_FUNCTION LINKTIME_CHECKING;
diff --git a/mcu/interface/service/kal/kal_atomic_api.h b/mcu/interface/service/kal/kal_atomic_api.h
new file mode 100644
index 0000000..d5db322
--- /dev/null
+++ b/mcu/interface/service/kal/kal_atomic_api.h
@@ -0,0 +1,792 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   kal_atomic_api.h
+ *
+ * Project:
+ * --------
+ *   Maui_Software
+ *
+ * Description:
+ * ------------
+ *   This file provides KAL public API prototypes
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ *
+ ****************************************************************************/
+
+#ifndef _KAL_ATOMIC_API_H
+#define _KAL_ATOMIC_API_H
+
+
+/***************************************************************************
+ *
+ *
+ *      NOTE!
+ *      Must use cacheable variables for atomic operations.
+ *
+ *
+ **************************************************************************/
+
+
+/*******************************************************************************
+ * Common Header File Include
+ *******************************************************************************/
+#ifndef GEN_FOR_PC
+#include <stdio.h>
+#include <string.h>
+#endif
+
+#include "kal_general_types.h"
+#include "kal_public_defs.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+
+/* These are atomic primitives that are used to implemented atomic macro api below. 
+   These are not intended for normal use */
+void kal_atomic_set_int(kal_atomic_int32 *var, int value);
+int kal_atomic_read_int(kal_atomic_int32 *var);
+void kal_atomic_update(kal_atomic_int32 *var, kal_int32 add_value,
+                       kal_int32 and_mask);
+int kal_atomic_update_return(kal_atomic_int32 *var, kal_int32 add_value,
+                             kal_int32 and_mask);
+void kal_atomic_toggle_bitmask_int(kal_atomic_int32 *var, kal_uint32 mask);
+int kal_atomic_toggle_bitmask_return_int(kal_atomic_int32 *var, kal_uint32 mask);
+int kal_atomic_swap_int(kal_atomic_int32 *var, kal_int32 new_value);
+int kal_atomic_cas(kal_atomic_int32 *var, kal_int32 compare_value,
+                   kal_int32 new_value);
+int kal_atomic_ici(kal_atomic_int32 *idx_var, kal_int32 buff_size);
+int kal_atomic_dci(kal_atomic_int32 *idx_var, kal_int32 buff_size);
+int kal_atomic_sig(kal_atomic_int32 *var, kal_int32 compare_value);
+int kal_atomic_sil(kal_atomic_int32 *var, kal_int32 compare_value);
+
+
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_init
+ * DESCRIPTION
+ *  Set value to variable. Meant to be used only during init. 
+ * PARAMETERS
+ *  var_ptr  : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  value    : [IN] value to be set
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will not perform a memory barrier.
+ ******************************************************************************/
+#define kal_atomic_init(var_ptr, value) \
+    do {                                \
+        *(var_ptr) = (value);           \
+    } while (0)
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_set
+ * DESCRIPTION
+ *  Set value to a variable atomically. 
+ * PARAMETERS
+ *  var_ptr  : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  value    : [IN] value to be set
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will perform a memory barrier after setting the value.
+ ******************************************************************************/
+#define kal_atomic_set(var_ptr, value) \
+    kal_atomic_set_int((kal_atomic_int32 *)(var_ptr), (value))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_read
+ * DESCRIPTION
+ *  Read variable value atomically.
+ * PARAMETERS
+ *  var_ptr  : [IN] pointer to source (kal_atomic_int32 or kal_atomic_uint32 variable)
+ * RETURNS
+ *  Success: [OUT] value at var_ptr
+ * NOTE
+ *  This function will perform a memory barrier before read.
+ ******************************************************************************/
+#define kal_atomic_read(var_ptr) kal_atomic_read_int((kal_atomic_int32 *)(var_ptr))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_add
+ * DESCRIPTION
+ *  Add value to a variable atomically.
+ * PARAMETERS
+ *  var_ptr  : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  value    : [IN] value to be added
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will not perform a memory barrier.
+ ******************************************************************************/
+#define kal_atomic_add(var_ptr, value) \
+    kal_atomic_update((kal_atomic_int32 *)(var_ptr), (value), ~0)
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_add_return
+ * DESCRIPTION
+ *  Add value to a variable atomically. Return the new value.
+ * PARAMETERS
+ *  var_ptr  : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  value    : [IN] value to be added
+ * RETURNS
+ *  Success: [OUT] new value at var_ptr
+ * NOTE
+ *  This function will perform a memory barrier before and after the add operation.
+ ******************************************************************************/
+#define kal_atomic_add_return(var_ptr, value) \
+    (kal_atomic_update_return((kal_atomic_int32 *)(var_ptr), (value), ~0) + (value))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_sub
+ * DESCRIPTION
+ *  Subtract value from a variable atomically.
+ * PARAMETERS
+ *  var_ptr  : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  value    : [IN] value to be subtracted
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will not perform a memory barrier.
+ ******************************************************************************/
+#define kal_atomic_sub(var_ptr, value) \
+    kal_atomic_update((kal_atomic_int32 *)(var_ptr), -(value), ~0)
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_sub_return
+ * DESCRIPTION
+ *  Subtract value from a variable atomically.
+ * PARAMETERS
+ *  var_ptr  : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  value    : [IN] value to be subtracted
+ * RETURNS
+ *  Success: [OUT] new value at var_ptr
+ * NOTE
+ *  This function will perform a memory barrier before and after the substract operation.
+ ******************************************************************************/
+#define kal_atomic_sub_return(var_ptr, value) \
+    (kal_atomic_update_return((kal_atomic_int32 *)(var_ptr), -(value), ~0) - (value))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_inc
+ * DESCRIPTION
+ *  Increment variable atomically.
+ * PARAMETERS
+ *  var_ptr  : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will not perform a memory barrier.
+ ******************************************************************************/
+#define kal_atomic_inc(var_ptr) kal_atomic_add((var_ptr), 1)
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_inc_return
+ * DESCRIPTION
+ *  Increment value atomically. Return the new value.
+ * PARAMETERS
+ *  var_ptr  : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ * RETURNS
+ *  Success: [OUT] new value at var_ptr
+ * NOTE
+ *  This function will perform a memory barrier before and after the increment operation.
+ ******************************************************************************/
+#define kal_atomic_inc_return(var_ptr) kal_atomic_add_return((var_ptr), 1)
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_dec
+ * DESCRIPTION
+ *  Decrement variable atomically.
+ * PARAMETERS
+ *  var_ptr  : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will not perform a memory barrier.
+ ******************************************************************************/
+#define kal_atomic_dec(var_ptr) kal_atomic_sub((var_ptr), 1)
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_dec_return
+ * DESCRIPTION
+ *  Decrement value atomically. Return the new value.
+ * PARAMETERS
+ *  var_ptr  : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ * RETURNS
+ *  Success: [OUT] new value at var_ptr
+ * NOTE
+ *  This function will perform a memory barrier before and after the decrement operation.
+ ******************************************************************************/
+#define kal_atomic_dec_return(var_ptr) kal_atomic_sub_return((var_ptr), 1)
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_add_compare
+ * DESCRIPTION
+ *  Add value to a variable atomically and compare if result is equal to new_value.
+ * PARAMETERS
+ *  var_ptr   : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  value     : [IN] value to be added
+ *  new_value : [IN] value to be compared with
+ * RETURNS
+ *  Success: [OUT] KAL_TRUE if new value at var_ptr is equal to new_value, otherwise KAL_FALSE
+ * NOTE
+ *  This function will perform a memory barrier before and after the add operation.
+ ******************************************************************************/
+#define kal_atomic_add_compare(var_ptr, value, new_value) \
+    (kal_atomic_add_return((var_ptr), (value)) == (new_value))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_inc_compare
+ * DESCRIPTION
+ *  Increment variable value atomically and compare if result is equal to new_value.
+ * PARAMETERS
+ *  var_ptr   : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  new_value : [IN] value to be compared with
+ * RETURNS
+ *  Success: [OUT] KAL_TRUE if new value at var_ptr is equal to new_value, otherwise KAL_FALSE
+ * NOTE
+ *  This function will perform a memory barrier before and after the increment operation.
+ ******************************************************************************/
+#define kal_atomic_inc_compare(var_ptr, new_value) \
+    (kal_atomic_add_return((var_ptr), 1) == (new_value))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_sub_compare
+ * DESCRIPTION
+ *  Subtract value from a variable atomically and compare if result is equal to new_value.
+ * PARAMETERS
+ *  var_ptr   : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  value     : [IN] value to be subtracted
+ *  new_value : [IN] value to be compared with
+ * RETURNS
+ *  Success: [OUT] KAL_TRUE if new value at var_ptr is equal to new_value, otherwise KAL_FALSE
+ * NOTE
+ *  This function will perform a memory barrier before and after the substract operation.
+ ******************************************************************************/
+#define kal_atomic_sub_compare(var_ptr, value, new_value) \
+    (kal_atomic_sub_return((var_ptr), (value)) == (new_value))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_dec_compare
+ * DESCRIPTION
+ *  Decrement value from a variable atomically and compare if result is equal to new_value.
+ * PARAMETERS
+ *  var_ptr   : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  new_value : [IN] value to be compared with
+ * RETURNS
+ *  Success: [OUT] KAL_TRUE if new value at var_ptr is equal to new_value, otherwise KAL_FALSE
+ * NOTE
+ *  This function will perform a memory barrier before and after the decrement operation.
+ ******************************************************************************/
+#define kal_atomic_dec_compare(var_ptr, new_value) \
+    (kal_atomic_sub_return((var_ptr), 1) == (new_value))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_set_bitmask
+ * DESCRIPTION
+ *  Set a mask of bits in a variable atomically.
+ * PARAMETERS
+ *  var_ptr   : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  mask      : [IN] bit mask to be set
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will not perform a memory barrier.
+ ******************************************************************************/
+#define kal_atomic_set_bitmask(var_ptr, mask) \
+    kal_atomic_update((kal_atomic_int32 *)(var_ptr), (mask), ~(mask))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_set_bitmask_return
+ * DESCRIPTION
+ *  Set a mask of bits in a variable atomically and return the old variable value.
+ * PARAMETERS
+ *  var_ptr   : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  mask      : [IN] bit mask to be set
+ * RETURNS
+ *  Success: [OUT] old value at var_ptr
+ * NOTE
+ *  This function will perform a memory barrier before and after the bit mask set.
+ ******************************************************************************/
+#define kal_atomic_set_bitmask_return(var_ptr, mask) \
+    kal_atomic_update_return((kal_atomic_int32 *)(var_ptr), (mask), ~(mask))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_set_bit
+ * DESCRIPTION
+ *  Set a bit in a variable atomically.
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  bit_nbr    : [IN] bit number to be set
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will not perform a memory barrier.
+ ******************************************************************************/
+#define kal_atomic_set_bit(var_ptr, bit_nbr) \
+    kal_atomic_set_bitmask((var_ptr), (1 << (bit_nbr)))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_set_bit_return
+ * DESCRIPTION
+ *  Set bit in a variable atomically and return the old value of bit
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  bit_nbr    : [IN] bit number to be set
+ * RETURNS
+ *  Success: [OUT] old value of bit
+ * NOTE
+ *  This function will perform a memory barrier before and after the bit set operation.
+ ******************************************************************************/
+#define kal_atomic_set_bit_return(var_ptr, bit_nbr)                \
+    ((kal_atomic_set_bitmask_return((var_ptr), (1 << (bit_nbr))) & \
+      (1 << (bit_nbr))) != 0)
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_clear_bitmask
+ * DESCRIPTION
+ *  Clear mask of bits in a variable atomically.
+ * PARAMETERS
+ *  var_ptr   : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  mask      : [IN] bit mask to be cleared
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will not perform a memory barrier.
+ ******************************************************************************/
+#define kal_atomic_clear_bitmask(var_ptr, mask) \
+    kal_atomic_update((kal_atomic_int32 *)(var_ptr), 0, ~(mask))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_clear_bitmask_return
+ * DESCRIPTION
+ *  Clear mask of bits in a variable atomically and return the old variable value.
+ * PARAMETERS
+ *  var_ptr   : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  mask      : [IN] bit mask to be cleared
+ * RETURNS
+ *  Success: [OUT] old value at var_ptr
+ * NOTE
+ *  This function will perform a memory barrier before and after the bit mask clear operation.
+ ******************************************************************************/
+#define kal_atomic_clear_bitmask_return(var_ptr, mask) \
+    kal_atomic_update_return((kal_atomic_int32 *)(var_ptr), 0, ~(mask))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_clear_bit
+ * DESCRIPTION
+ *  Clear a bit in a variable atomically.
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  bit_nbr    : [IN] bit number to be cleared
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will not perform a memory barrier.
+ ******************************************************************************/
+#define kal_atomic_clear_bit(var_ptr, bit_nbr) \
+    kal_atomic_clear_bitmask((var_ptr), (1 << (bit_nbr)))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_clear_bit_return
+ * DESCRIPTION
+ *  Clear a bit in a variable atomically and return the old value of bit
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  mask       : [IN] bit number to be cleared
+ * RETURNS
+ *  Success: [OUT] old value of bit
+ * NOTE
+ *  This function will perform a memory barrier before and after the bit clear operation.
+ ******************************************************************************/
+#define kal_atomic_clear_bit_return(var_ptr, bit_nbr)                \
+    ((kal_atomic_clear_bitmask_return((var_ptr), (1 << (bit_nbr))) & \
+      (1 << (bit_nbr))) != 0)
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_toggle_bitmask
+ * DESCRIPTION
+ *  Toggle mask of bits in a variable atomically.
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  mask       : [IN] bit mask to be toggled
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will not perform a memory barrier.
+ ******************************************************************************/
+#define kal_atomic_toggle_bitmask(var_ptr, mask) \
+    kal_atomic_toggle_bitmask_int((kal_atomic_int32 *)(var_ptr), (mask))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_toggle_bitmask_return
+ * DESCRIPTION
+ *  Toggle mask of bits in a variable atomically and return the old value of bit
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  mask       : [IN] bit mask to be toggled
+ * RETURNS
+ *  Success: [OUT] old value of bit
+ * NOTE
+ *  This function will perform a memory barrier before and after the bit mask toggle operation.
+ ******************************************************************************/
+#define kal_atomic_toggle_bitmask_return(var_ptr, bitmask) \
+    kal_atomic_toggle_bitmask_return_int((kal_atomic_int32 *)(var_ptr), (bitmask))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_toggle_bit
+ * DESCRIPTION
+ *  Toggle bit in a variable atomically.
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  mask       : [IN] bit number to be toggled
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will not perform a memory barrier.
+ ******************************************************************************/
+#define kal_atomic_toggle_bit(var_ptr, bit_nbr) \
+    kal_atomic_toggle_bitmask((var_ptr), (1 << (bit_nbr)))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_toggle_bit_return
+ * DESCRIPTION
+ *  Toggle bit in a variable atomically and return the old value of bit
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  mask       : [IN] bit number to be toggled
+ * RETURNS
+ *  Success: [OUT] old value of bit
+ * NOTE
+ *  This function will perform a memory barrier before and after the bit toggle operation.
+ ******************************************************************************/
+#define kal_atomic_toggle_bit_return(var_ptr, bit_nbr)                \
+    ((kal_atomic_toggle_bitmask_return((var_ptr), (1 << (bit_nbr))) & \
+      (1 << (bit_nbr))) != 0)
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_clear_set_bitmask
+ * DESCRIPTION
+ *  Clear a bit mask and then set another bit mask in a variable atomically.
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  clear_mask : [IN] bit mask to be cleared
+ *  set_mask   : [IN] bit mask to be set
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will not perform a memory barrier.
+ ******************************************************************************/
+#define kal_atomic_clear_set_bitmask(var_ptr, clear_mask, set_mask) \
+    kal_atomic_update((kal_atomic_int32 *)(var_ptr), (set_mask),    \
+                      ~((clear_mask) | (set_mask)))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_clear_set_bitmask_return
+ * DESCRIPTION
+ *  Clear a bit mask and then set another bit mask in a variable atomically.
+ *  Return the old variable value.
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  clear_mask : [IN] bit mask to be cleared
+ *  set_mask   : [IN] bit mask to be set
+ * RETURNS
+ *  Success: [OUT] old value at var_ptr
+ * NOTE
+ *  This function will perform a memory barrier before and after the bitmask set and clear operation.
+ ******************************************************************************/
+#define kal_atomic_clear_set_bitmask_return(var_ptr, clear_mask, set_mask) \
+    kal_atomic_update_return((kal_atomic_int32 *)(var_ptr), (set_mask),    \
+                             ~((clear_mask) | (set_mask)))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_clear_set_bit
+ * DESCRIPTION
+ *  Clear a bit and then set another bit in a variable atomically.
+ * PARAMETERS
+ *  var_ptr       : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  clear_bit_nbr : [IN] bit number to be cleared
+ *  set_bit_nbr   : [IN] bit number to be set
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will not perform a memory barrier.
+ ******************************************************************************/
+#define kal_atomic_clear_set_bit(var_ptr, clear_bit_nbr, set_bit_nbr) \
+    kal_atomic_clear_set_bitmask((var_ptr), (1 << (clear_bit_nbr)),   \
+                                 (1 << (set_bit_nbr)))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_and_bitmask
+ * DESCRIPTION
+ *  Apply a bitwise AND operation with a given bit mask to a variable atomically.
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  mask       : [IN] bit mask to be ANDed
+ * RETURNS
+ *  -
+ * NOTE
+ *  This function will not perform a memory barrier.
+ ******************************************************************************/
+#define kal_atomic_and_bitmask(var_ptr, mask) \
+    kal_atomic_update((kal_atomic_int32 *)(var_ptr), 0, (mask))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_and_bitmask_return
+ * DESCRIPTION
+ *  Apply a bitwise AND operation with a given bit mask to a variable atomically.
+ *  Return the old variable value.
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  mask       : [IN] bit mask to be ANDed
+ * RETURNS
+ *  Success: [OUT] old value at var_ptr
+ * NOTE
+ *  This function will perform a memory barrier before and after the AND operation.
+ ******************************************************************************/
+#define kal_atomic_and_bitmask_return(var_ptr, mask) \
+    kal_atomic_update_return((kal_atomic_int32 *)(var_ptr), 0, (mask))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_swap_return
+ * DESCRIPTION
+ *  Swap a new value atomically with the value in given variable. Return the old variable value.
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  new_value  : [IN] new value to be swapped
+ * RETURNS
+ *  Success: [OUT] old value at var_ptr
+ * NOTE
+ *  This function will perform a memory barrier before and after the swap operation.
+ ******************************************************************************/
+#define kal_atomic_swap_return(var_ptr, new_value) \
+    kal_atomic_swap_int((kal_atomic_int32 *)(var_ptr), (new_value))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_compare_and_swap_return
+ * DESCRIPTION
+ *  Swap a new value atomically with the value in given variable, if the current variable value
+ *  is equal to compare_value. Return the old variable value.
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination (kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  value      : [IN] value to be compared with
+ *  new_value  : [IN] value to be swapped
+ * RETURNS
+ *  Success: [OUT] old value at var_ptr
+ * NOTE
+ *  This function will perform a memory barrier before and after the compare and swap operation.
+ ******************************************************************************/
+#define kal_atomic_compare_and_swap_return(var_ptr, value, new_value) \
+    kal_atomic_cas((kal_atomic_int32 *)(var_ptr), (value), (new_value))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_inc_circular_index
+ * DESCRIPTION
+ *  Increments index value by one and wraps to 0 if index reaches buffer size.
+ *  Return current value of index
+ * PARAMETERS
+ *  idx_ptr    : [IN] pointer to index variable
+ *  buf_size   : [IN] size of buffer (wraparound point)
+ * RETURNS
+ *  Success: [OUT] current value of index (before inc)
+ * NOTE
+ *  Does not have memory barrier
+ ******************************************************************************/
+#define kal_atomic_inc_circular_index(idx_ptr, buff_size) \
+    kal_atomic_ici((kal_atomic_int32 *)(idx_ptr), (buff_size))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_dec_circular_index
+ * DESCRIPTION
+ *  Decrements index value by one and wraps to max vaule (buffer size - 1) if index reaches -1.
+ *  Return current value of index
+ * PARAMETERS
+ *  idx_ptr    : [IN] pointer to index variable
+ *  buf_size   : [IN] size of buffer (wraparound point)
+ * RETURNS
+ *  Success: [OUT] current value of index (before inc)
+ * NOTE
+ *  Does not have memory barrier
+ ******************************************************************************/
+#define kal_atomic_dec_circular_index(idx_ptr, buff_size) \
+    kal_atomic_dci((kal_atomic_int32 *)(idx_ptr), (buff_size))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_set_if_greater
+ * DESCRIPTION
+ *  Set new value atomically in to variable if new value is greater than old value.
+ *  Return value set to variable
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination(kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  value      : [IN] value to be compared
+ * RETURNS
+ *  Success: [OUT] final value of variable
+ * NOTE
+ *  Does not have memory barrier
+ ******************************************************************************/
+#define kal_atomic_set_if_greater(var_ptr, value) \
+    kal_atomic_sig((kal_atomic_int32 *)(var_ptr), (value))
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_atomic_set_if_less
+ * DESCRIPTION
+ *  Set new value atomically in to variable if new value is less than old value.
+ *  Return value set to variable
+ * PARAMETERS
+ *  var_ptr    : [IN] pointer to destination(kal_atomic_int32 or kal_atomic_uint32 variable)
+ *  value      : [IN] value to be compared
+ * RETURNS
+ *  Success: [OUT] final value of variable
+ * NOTE
+ *  Does not have memory barrier
+ ******************************************************************************/
+#define kal_atomic_set_if_less(var_ptr, value) \
+    kal_atomic_sil((kal_atomic_int32 *)(var_ptr), (value))
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _KAL_ATOMIC_API_H */
diff --git a/mcu/interface/service/kal/kal_ex_api.h b/mcu/interface/service/kal/kal_ex_api.h
new file mode 100644
index 0000000..0783836
--- /dev/null
+++ b/mcu/interface/service/kal/kal_ex_api.h
@@ -0,0 +1,1254 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   kal_ex_api.h
+ *
+ * Project:
+ * --------
+ *   Maui_Software
+ *
+ * Description:
+ * ------------
+ *   This file provides KAL public API prototypes
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ ****************************************************************************/
+
+#ifndef _KAL_EX_API_H
+#define _KAL_EX_API_H
+
+/*******************************************************************************
+ * Common Header File Include
+ *******************************************************************************/
+#ifndef GEN_FOR_PC
+#include <stdio.h>
+#include <string.h>
+#endif
+
+#include "kal_general_types.h"
+#include "kal_public_defs.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+/*******************************************************************************
+ * Category 9 : Error Handling
+ *******************************************************************************/
+
+
+/*
+ * These functions has been duplicated to several files - .\bootloader\src\bl_portingfunc.c
+ * If there's any modification to these functions, please remember to update above file.
+ * If you need to duplicate these functions, please update above file list.
+ */
+#if defined(__UBL__) 
+extern void kal_assert_fail(char* expr, char* file, kal_uint32 line, kal_bool isext, kal_uint32 ex1, kal_uint32 ex2, kal_uint32 ex3, ASSERT_DUMP_PARAM_T *dump_param);
+#else /* __UBL__ */
+#if !defined(__MTK_TARGET__)
+#if defined(__clang_analyzer__)
+extern void kal_assert_fail(char* expr, char* file, kal_uint32 line, kal_bool isext, kal_uint32 ex1, kal_uint32 ex2, kal_uint32 ex3, ASSERT_DUMP_PARAM_T *dump_param) __attribute__((__noreturn__));
+#else /* __clang_analyzer__ */
+extern void kal_assert_fail(char* expr, char* file, kal_uint32 line, kal_bool isext, kal_uint32 ex1, kal_uint32 ex2, kal_uint32 ex3, ASSERT_DUMP_PARAM_T *dump_param);
+#endif /* __clang_analyzer__ */
+#endif /* __MTK_TARGET__  */
+#endif /* __UBL__ */
+
+/*
+ * Error Handling
+ */
+/* NOTE: Module Controlled ASSERT Interface, it will be removed from next release.  */
+#if defined(__DEBUG_ASSERT_SUPPORT__)
+#define DEBUG_ASSERT(expr)                  ASSERT(expr)
+#define DEBUG_EXT_ASSERT1(expr, e1)         EXT_ASSERT1(expr, e1)
+#define DEBUG_EXT_ASSERT2(expr, e1, e2)     EXT_ASSERT3(expr, e1, e2)
+#define DEBUG_EXT_ASSERT3(expr, e1, e2, e3) EXT_ASSERT3(expr, e1, e2, e3)
+#else
+#define DEBUG_ASSERT(expr)                  do {if(!(expr)) {} } while (0)
+#define DEBUG_EXT_ASSERT1(expr, e1)         do {if(!(expr)) {(void)(e1);} } while (0)
+#define DEBUG_EXT_ASSERT2(expr, e1, e2)     do {if(!(expr)) {(void)(e1);(void)(e2);} } while (0)
+#define DEBUG_EXT_ASSERT3(expr, e1, e2, e3) do {if(!(expr)) {(void)(e1);(void)(e2);(void)(e3);} } while (0)
+#endif
+
+/* NOTE : ASSERT() , EXT_ASSERT() is public ,
+ * While EXT_ASSERT_DUMP() is auxiliary  
+ */
+
+#if !defined(__COSIM_BYPASS_DRV__) || defined(__ESL_ENABLE_BREAK__)
+#if defined(__MTK_TARGET__) && !defined(__UBL__)
+#if defined(__MIPS_IA__) || defined(__MIPS_I7200__)
+
+ #if _MIPS_SIM == _ABIP32
+ #define EX_MIPS_GPR_R2 "$t4"
+ #define EX_MIPS_GPR_R3 "$t5"
+ #elif _MIPS_SIM == _ABIO32
+ #define EX_MIPS_GPR_R2 "$v0"
+ #define EX_MIPS_GPR_R3 "$v1"
+ #endif
+
+#if defined(__KAL_ASSERT_LEVEL4__)
+#define ASSERT(expr) \
+do { \
+    if(!(expr)) { \
+        register const kal_char *_expr __asm__ ("$a0") = #expr; \
+        register const kal_char *_file __asm__ ("$a1") = __FILE__; \
+        register long _line __asm__ ("$a2") = __LINE__; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %3         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_expr)), "r" ((_file)), "r" ((_line)), \
+            "K" (ASSERT_LINE) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT1(expr, e1) \
+do { \
+    if(!(expr)) { \
+        register const kal_char *_expr __asm__ ("$a0") = #expr; \
+        register const kal_char *_file __asm__ ("$a1") = __FILE__; \
+        register long _line __asm__ ("$a2") = __LINE__; \
+        register long _e1 __asm__ ("$a3") = e1; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %4         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_expr)), "r" ((_file)), "r" ((_line)), \
+            "r" ((_e1)), "K" (ASSERT_EXT1) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT2(expr, e1, e2) \
+do { \
+    if(!(expr)) { \
+        register const kal_char *_expr __asm__ ("$a0") = #expr; \
+        register const kal_char *_file __asm__ ("$a1") = __FILE__; \
+        register long _line __asm__ ("$a2") = __LINE__; \
+        register long _e1 __asm__ ("$a3") = e1; \
+        register long _e2 __asm__ (EX_MIPS_GPR_R2) = e2; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %5         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_expr)), "r" ((_file)), "r" ((_line)), \
+            "r" ((_e1)), "r" ((_e2)), "K" (ASSERT_EXT2) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT3(expr, e1, e2, e3) \
+do { \
+    if(!(expr)) { \
+        register const kal_char *_expr __asm__ ("$a0") = #expr; \
+        register const kal_char *_file __asm__ ("$a1") = __FILE__; \
+        register long _line __asm__ ("$a2") = __LINE__; \
+        register long _e1 __asm__ ("$a3") = e1; \
+        register long _e2 __asm__ (EX_MIPS_GPR_R2) = e2; \
+        register long _e3 __asm__ (EX_MIPS_GPR_R3) = e3; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %6         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_expr)), "r" ((_file)), "r" ((_line)), \
+            "r" ((_e1)), "r" ((_e2)), "r" ((_e3)), "K" (ASSERT_EXT3) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT(expr, e1, e2, e3) EXT_ASSERT3(expr, e1, e2, e3)
+#define EXT_ASSERT_DUMP(expr, param) \
+do { \
+    if(!(expr)) { \
+        register const kal_char *_expr __asm__ ("$a0") = #expr; \
+        register const kal_char *_file __asm__ ("$a1") = __FILE__; \
+        register long _line __asm__ ("$a2") = __LINE__; \
+        register void *_param __asm__ ("$a3") = (void*)param; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %4         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_expr)), "r" ((_file)), "r" ((_line)), \
+            "r" ((_param)), "K" (ASSERT_EXT_DUMP) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+
+#define CUSTOM_ASSERT(TYPE, expr, dispatch_arg) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        register const kal_char *_expr __asm__ ("$a0") = #expr; \
+        register const kal_char *_file __asm__ ("$a1") = __FILE__; \
+        register long _line __asm__ ("$a2") = __LINE__; \
+        register kal_uint32 __dispatch_arg __asm__ ("$a3") = _dispatch_arg; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %4         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_expr)), "r" ((_file)), "r" ((_line)), \
+            "r" ((__dispatch_arg)), "K" (ASSERT_CUS_##TYPE) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT_EXT1(TYPE, expr, dispatch_arg, e1) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        register const kal_char *_expr __asm__ ("$a0") = #expr; \
+        register const kal_char *_file __asm__ ("$a1") = __FILE__; \
+        register long _line __asm__ ("$a2") = __LINE__; \
+        register kal_uint32 __dispatch_arg __asm__ ("$a3") = _dispatch_arg; \
+        register kal_uint32 __e1 __asm__ (EX_MIPS_GPR_R2) = _e1; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %5         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_expr)), "r" ((_file)), "r" ((_line)), \
+            "r" ((__dispatch_arg)), "r" ((__e1)), "K" (ASSERT_CUS_##TYPE##_EXT1) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT_EXT2(TYPE, expr, dispatch_arg, e1, e2) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        kal_uint32 _e2 = (kal_uint32)(e2); \
+        register const kal_char *_expr __asm__ ("$a0") = #expr; \
+        register const kal_char *_file __asm__ ("$a1") = __FILE__; \
+        register long _line __asm__ ("$a2") = __LINE__; \
+        register kal_uint32 __dispatch_arg __asm__ ("$a3") = _dispatch_arg; \
+        register kal_uint32 __e1 __asm__ (EX_MIPS_GPR_R2) = _e1; \
+        register kal_uint32 __e2 __asm__ (EX_MIPS_GPR_R3) = _e2; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %6         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_expr)), "r" ((_file)), "r" ((_line)), \
+            "r" ((__dispatch_arg)), "r" ((__e1)), "r" ((__e2)), "K" (ASSERT_CUS_##TYPE##_EXT2) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+/* NOTE: at assert level 4, e3 argument is ignore due to shortage of regs */
+#define CUSTOM_ASSERT_EXT3(TYPE, expr, dispatch_arg, e1, e2, e3) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        kal_uint32 _e2 = (kal_uint32)(e2); \
+        register const kal_char *_expr __asm__ ("$a0") = #expr; \
+        register const kal_char *_file __asm__ ("$a1") = __FILE__; \
+        register long _line __asm__ ("$a2") = __LINE__; \
+        register kal_uint32 __dispatch_arg __asm__ ("$a3") = _dispatch_arg; \
+        register kal_uint32 __e1 __asm__ (EX_MIPS_GPR_R2) = _e1; \
+        register kal_uint32 __e2 __asm__ (EX_MIPS_GPR_R3) = _e2; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %6         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_expr)), "r" ((_file)), "r" ((_line)), \
+            "r" ((__dispatch_arg)), "r" ((__e1)), "r" ((__e2)), "K" (ASSERT_CUS_##TYPE##_EXT3) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+
+#define CUSTOM_ASSERT_ADDR(expr, dispatch_arg) CUSTOM_ASSERT(ADDR, expr, dispatch_arg)
+#define CUSTOM_ASSERT_ADDR_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(ADDR, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_ADDR_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(ADDR, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_ADDR_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(ADDR, expr, dispatch_arg, e1, e2, e3)
+
+#define CUSTOM_ASSERT_MODID(expr, dispatch_arg) CUSTOM_ASSERT(MODID, expr, dispatch_arg)
+#define CUSTOM_ASSERT_MODID_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(MODID, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_MODID_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(MODID, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_MODID_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(MODID, expr, dispatch_arg, e1, e2, e3)
+
+#define CUSTOM_ASSERT_MOFID(expr, dispatch_arg) CUSTOM_ASSERT(MOFID, expr, dispatch_arg)
+#define CUSTOM_ASSERT_MOFID_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(MOFID, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_MOFID_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(MOFID, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_MOFID_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(MOFID, expr, dispatch_arg, e1, e2, e3)
+
+#elif defined(__KAL_ASSERT_LEVEL3__)
+#define ASSERT(expr) \
+do { \
+    if(!(expr)) { \
+        register const kal_char *_file __asm__ ("$a0") = __FILE__; \
+        register long _line __asm__ ("$a1") = __LINE__; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %2         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_file)), "r" ((_line)), "K" (ASSERT_LINE) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT1(expr, e1) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        register const kal_char *_file __asm__ ("$a0") = __FILE__; \
+        register long _line __asm__ ("$a1") = __LINE__; \
+        register kal_uint32 __e1 __asm__ ("$a2") = _e1; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %3         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_file)), "r" ((_line)), "r" ((__e1)), "K" (ASSERT_EXT1) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT2(expr, e1, e2) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        kal_uint32 _e2 = (kal_uint32)(e2); \
+        register const kal_char *_file __asm__ ("$a0") = __FILE__; \
+        register long _line __asm__ ("$a1") = __LINE__; \
+        register kal_uint32 __e1 __asm__ ("$a2") = _e1; \
+        register kal_uint32 __e2 __asm__ ("$a3") = _e2; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %4         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_file)), "r" ((_line)), \
+            "r" ((__e1)), "r" ((__e2)), "K" (ASSERT_EXT2) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT3(expr, e1, e2, e3) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        kal_uint32 _e2 = (kal_uint32)(e2); \
+        kal_uint32 _e3 = (kal_uint32)(e3); \
+        register const kal_char *_file __asm__ ("$a0") = __FILE__; \
+        register long _line __asm__ ("$a1") = __LINE__; \
+        register kal_uint32 __e1 __asm__ ("$a2") = _e1; \
+        register kal_uint32 __e2 __asm__ ("$a3") = _e2; \
+        register kal_uint32 __e3 __asm__ (EX_MIPS_GPR_R2) = _e3; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %5         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_file)), "r" ((_line)), \
+            "r" ((__e1)), "r" ((__e2)), "r" ((__e3)), "K" (ASSERT_EXT3) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT(expr, e1, e2, e3) EXT_ASSERT3(expr, e1, e2, e3)
+#define EXT_ASSERT_DUMP(expr, param) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _param = (kal_uint32)(param); \
+        register const kal_char *_file __asm__ ("$a0") = __FILE__; \
+        register long _line __asm__ ("$a1") = __LINE__; \
+        register kal_uint32 __param __asm__ ("$a2") = _param; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %3         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_file)), "r" ((_line)), \
+            "r" ((__param)), "K" (ASSERT_EXT_DUMP) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+
+#define CUSTOM_ASSERT(TYPE, expr, dispatch_arg) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        register const kal_char *_file __asm__ ("$a0") = __FILE__; \
+        register long _line __asm__ ("$a1") = __LINE__; \
+        register kal_uint32 __dispatch_arg __asm__ ("$a2") = _dispatch_arg; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %3         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_file)), "r" ((_line)), "r" ((__dispatch_arg)), "K" (ASSERT_CUS_##TYPE) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT_EXT1(TYPE, expr, dispatch_arg, e1) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        register const kal_char *_file __asm__ ("$a0") = __FILE__; \
+        register long _line __asm__ ("$a1") = __LINE__; \
+        register kal_uint32 __dispatch_arg __asm__ ("$a2") = _dispatch_arg; \
+        register kal_uint32 __e1 __asm__ ("$a3") = _e1; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %4         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_file)), "r" ((_line)), \
+            "r" ((__dispatch_arg)), "r" ((__e1)), "K" (ASSERT_CUS_##TYPE##_EXT1) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT_EXT2(TYPE, expr, dispatch_arg, e1, e2) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        kal_uint32 _e2 = (kal_uint32)(e2); \
+        register const kal_char *_file __asm__ ("$a0") = __FILE__; \
+        register long _line __asm__ ("$a1") = __LINE__; \
+        register kal_uint32 __dispatch_arg __asm__ ("$a2") = _dispatch_arg; \
+        register kal_uint32 __e1 __asm__ ("$a3") = _e1; \
+        register kal_uint32 __e2 __asm__ (EX_MIPS_GPR_R2) = _e2; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %5         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_file)), "r" ((_line)), \
+            "r" ((__dispatch_arg)), "r" ((__e1)), "r" ((__e2)), "K" (ASSERT_CUS_##TYPE##_EXT2) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT_EXT3(TYPE, expr, dispatch_arg, e1, e2, e3) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        kal_uint32 _e2 = (kal_uint32)(e2); \
+        kal_uint32 _e3 = (kal_uint32)(e3); \
+        register const kal_char *_file __asm__ ("$a0") = __FILE__; \
+        register long _line __asm__ ("$a1") = __LINE__; \
+        register kal_uint32 __dispatch_arg __asm__ ("$a2") = _dispatch_arg; \
+        register kal_uint32 __e1 __asm__ ("$a3") = _e1; \
+        register kal_uint32 __e2 __asm__ (EX_MIPS_GPR_R2) = _e2; \
+        register kal_uint32 __e3 __asm__ (EX_MIPS_GPR_R3) = _e3; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %6         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_file)), "r" ((_line)), \
+            "r" ((__dispatch_arg)), "r" ((__e1)), "r" ((__e2)), "r" ((__e3)), "K" (ASSERT_CUS_##TYPE##_EXT3) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+
+#define CUSTOM_ASSERT_ADDR(expr, dispatch_arg) CUSTOM_ASSERT(ADDR, expr, dispatch_arg)
+#define CUSTOM_ASSERT_ADDR_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(ADDR, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_ADDR_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(ADDR, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_ADDR_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(ADDR, expr, dispatch_arg, e1, e2, e3)
+
+#define CUSTOM_ASSERT_MODID(expr, dispatch_arg) CUSTOM_ASSERT(MODID, expr, dispatch_arg)
+#define CUSTOM_ASSERT_MODID_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(MODID, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_MODID_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(MODID, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_MODID_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(MODID, expr, dispatch_arg, e1, e2, e3)
+
+#define CUSTOM_ASSERT_MOFID(expr, dispatch_arg) CUSTOM_ASSERT(MOFID, expr, dispatch_arg)
+#define CUSTOM_ASSERT_MOFID_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(MOFID, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_MOFID_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(MOFID, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_MOFID_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(MOFID, expr, dispatch_arg, e1, e2, e3)
+
+#elif defined(__KAL_ASSERT_LEVEL2__)
+#define ASSERT(expr) \
+do { \
+    if(!(expr)) { \
+        register long _line __asm__ ("$a0") = __LINE__; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %1         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_line)), "K" (ASSERT_LINE) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT1(expr, e1) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        register long _line __asm__ ("$a0") = __LINE__; \
+        register long __e1 __asm__ ("$a1") = _e1; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %2         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_line)), "r" ((__e1)), "K" (ASSERT_EXT1) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT2(expr, e1, e2) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        kal_uint32 _e2 = (kal_uint32)(e2); \
+        register long _line __asm__ ("$a0") = __LINE__; \
+        register long __e1 __asm__ ("$a1") = _e1; \
+        register long __e2 __asm__ ("$a2") = _e2; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %3         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_line)), \
+            "r" ((__e1)), "r" ((__e2)), "K" (ASSERT_EXT2) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT3(expr, e1, e2, e3) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        kal_uint32 _e2 = (kal_uint32)(e2); \
+        kal_uint32 _e3 = (kal_uint32)(e3); \
+        register long _line __asm__ ("$a0") = __LINE__; \
+        register long __e1 __asm__ ("$a1") = _e1; \
+        register long __e2 __asm__ ("$a2") = _e2; \
+        register long __e3 __asm__ ("$a3") = _e3; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %4         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_line)), \
+            "r" ((__e1)), "r" ((__e2)), "r" ((__e3)), "K" (ASSERT_EXT3) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT(expr, e1, e2, e3) EXT_ASSERT3(expr, e1, e2, e3)
+#define EXT_ASSERT_DUMP(expr, param) \
+do { \
+    if(!(expr)) { \
+        register long _line __asm__ ("$a0") = __LINE__; \
+        register void *_param __asm__ ("$a1") = (void*)param; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %2         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_line)), \
+            "r" ((_param)), "K" (ASSERT_EXT_DUMP) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT(TYPE, expr, dispatch_arg) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        register long _line __asm__ ("$a0") = __LINE__; \
+        register kal_uint32 __dispatch_arg __asm__ ("$a1") = _dispatch_arg; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %2         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_line)), "r" ((__dispatch_arg)), "K" (ASSERT_CUS_##TYPE) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT_EXT1(TYPE, expr, dispatch_arg, e1) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        register long _line __asm__ ("$a0") = __LINE__; \
+        register kal_uint32 __dispatch_arg __asm__ ("$a1") = _dispatch_arg; \
+        register kal_uint32 __e1 __asm__ ("$a2") = _e1; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %3         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_line)), \
+            "r" ((__dispatch_arg)), "r" ((__e1)), "K" (ASSERT_CUS_##TYPE##_EXT1) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT_EXT2(TYPE, expr, dispatch_arg, e1, e2) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        kal_uint32 _e2 = (kal_uint32)(e2); \
+        register long _line __asm__ ("$a0") = __LINE__; \
+        register kal_uint32 __dispatch_arg __asm__ ("$a1") = _dispatch_arg; \
+        register kal_uint32 __e1 __asm__ ("$a2") = _e1; \
+        register kal_uint32 __e2 __asm__ ("$a3") = _e2; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %4         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_line)), \
+            "r" ((__dispatch_arg)), "r" ((__e1)), "r" ((__e2)), "K" (ASSERT_CUS_##TYPE##_EXT2) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT_EXT3(TYPE, expr, dispatch_arg, e1, e2, e3) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        kal_uint32 _e1 = (kal_uint32)(e1); \
+        kal_uint32 _e2 = (kal_uint32)(e2); \
+        kal_uint32 _e3 = (kal_uint32)(e3); \
+        register long _line __asm__ ("$a0") = __LINE__; \
+        register kal_uint32 __dispatch_arg __asm__ ("$a1") = _dispatch_arg; \
+        register kal_uint32 __e1 __asm__ ("$a2") = _e1; \
+        register kal_uint32 __e2 __asm__ ("$a3") = _e2; \
+        register kal_uint32 __e3 __asm__ (EX_MIPS_GPR_R2) = _e3; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %5         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_line)), \
+            "r" ((__dispatch_arg)), "r" ((__e1)), "r" ((__e2)), "r" ((__e3)), "K" (ASSERT_CUS_##TYPE##_EXT3) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+
+#define CUSTOM_ASSERT_ADDR(expr, dispatch_arg) CUSTOM_ASSERT(ADDR, expr, dispatch_arg)
+#define CUSTOM_ASSERT_ADDR_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(ADDR, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_ADDR_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(ADDR, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_ADDR_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(ADDR, expr, dispatch_arg, e1, e2, e3)
+
+#define CUSTOM_ASSERT_MODID(expr, dispatch_arg) CUSTOM_ASSERT(MODID, expr, dispatch_arg)
+#define CUSTOM_ASSERT_MODID_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(MODID, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_MODID_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(MODID, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_MODID_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(MODID, expr, dispatch_arg, e1, e2, e3)
+
+#define CUSTOM_ASSERT_MOFID(expr, dispatch_arg) CUSTOM_ASSERT(MOFID, expr, dispatch_arg)
+#define CUSTOM_ASSERT_MOFID_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(MOFID, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_MOFID_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(MOFID, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_MOFID_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(MOFID, expr, dispatch_arg, e1, e2, e3)
+
+#elif defined(__KAL_ASSERT_LEVEL1__)
+#define ASSERT(expr) \
+do { \
+    if(!(expr)) { \
+        register long _line __asm__ ("$a0") = __LINE__; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %1         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_line)), "K" (ASSERT_LINE) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT1(expr, e1) \
+do { \
+    if(!(expr)) { \
+        (void)(e1); \
+        register long _line __asm__ ("$a0") = __LINE__; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %1         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_line)), "K" (ASSERT_EXT1) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT2(expr, e1, e2) \
+do { \
+    if(!(expr)) { \
+        (void)(e1); \
+        (void)(e2); \
+        register long _line __asm__ ("$a0") = __LINE__; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %1         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_line)), "K" (ASSERT_EXT2) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT3(expr, e1, e2, e3) \
+do { \
+    if(!(expr)) { \
+        (void)(e1); \
+        (void)(e2); \
+        (void)(e3); \
+        register long _line __asm__ ("$a0") = __LINE__; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %1         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_line)), "K" (ASSERT_EXT3) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT(expr, e1, e2, e3) EXT_ASSERT3(expr, e1, e2, e3)
+#define EXT_ASSERT_DUMP(expr, param) \
+do { \
+    if(!(expr)) { \
+        (void)(param); \
+        register long _line __asm__ ("$a0") = __LINE__; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %1         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((_line)), "K" (ASSERT_EXT_DUMP) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT(TYPE, expr, dispatch_arg) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        register kal_uint32 __dispatch_arg __asm__ ("$a0") = _dispatch_arg; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %1         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((__dispatch_arg)), "K" (ASSERT_CUS_##TYPE) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT_EXT1(TYPE, expr, dispatch_arg, e1) \
+do { \
+    if(!(expr)) { \
+        (void)(e1); \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        register kal_uint32 __dispatch_arg __asm__ ("$a0") = _dispatch_arg; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %1         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((__dispatch_arg)), "K" (ASSERT_CUS_##TYPE##_EXT1) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT_EXT2(TYPE, expr, dispatch_arg, e1, e2) \
+do { \
+    if(!(expr)) { \
+        (void)(e1); \
+        (void)(e2); \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        register kal_uint32 __dispatch_arg __asm__ ("$a0") = _dispatch_arg; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %1         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((__dispatch_arg)), "K" (ASSERT_CUS_##TYPE##_EXT2) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT_EXT3(TYPE, expr, dispatch_arg, e1, e2, e3) \
+do { \
+    if(!(expr)) { \
+        (void)(e1); \
+        (void)(e2); \
+        (void)(e3); \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        register kal_uint32 __dispatch_arg __asm__ ("$a0") = _dispatch_arg; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %1         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((__dispatch_arg)), "K" (ASSERT_CUS_##TYPE##_EXT3) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+
+#define CUSTOM_ASSERT_ADDR(expr, dispatch_arg) CUSTOM_ASSERT(ADDR, expr, dispatch_arg)
+#define CUSTOM_ASSERT_ADDR_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(ADDR, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_ADDR_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(ADDR, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_ADDR_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(ADDR, expr, dispatch_arg, e1, e2, e3)
+
+#define CUSTOM_ASSERT_MODID(expr, dispatch_arg) CUSTOM_ASSERT(MODID, expr, dispatch_arg)
+#define CUSTOM_ASSERT_MODID_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(MODID, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_MODID_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(MODID, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_MODID_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(MODID, expr, dispatch_arg, e1, e2, e3)
+
+#define CUSTOM_ASSERT_MOFID(expr, dispatch_arg) CUSTOM_ASSERT(MOFID, expr, dispatch_arg)
+#define CUSTOM_ASSERT_MOFID_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(MOFID, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_MOFID_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(MOFID, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_MOFID_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(MOFID, expr, dispatch_arg, e1, e2, e3)
+
+#else  /* __KAL_ASSERT_LEVEL0__*/
+#define ASSERT(expr) do {if(!(expr)) {} } while (0)
+#define EXT_ASSERT1(expr, e1) \
+do { \
+    if(!(expr)) { \
+        (void)(e1); \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %0         \n" \
+            ".set   pop       \n" \
+            : \
+            : "K" (ASSERT_EXT1) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT2(expr, e1, e2) \
+do { \
+    if(!(expr)) { \
+        (void)(e1); \
+        (void)(e2); \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %0         \n" \
+            ".set   pop       \n" \
+            : \
+            : "K" (ASSERT_EXT2) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT3(expr, e1, e2, e3) \
+do { \
+    if(!(expr)) { \
+        (void)(e1); \
+        (void)(e2); \
+        (void)(e3); \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %0         \n" \
+            ".set   pop       \n" \
+            : \
+            : "K" (ASSERT_EXT3) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define EXT_ASSERT(expr, e1, e2, e3) EXT_ASSERT3(expr, e1, e2, e3)
+#define EXT_ASSERT_DUMP(expr, param) \
+do { \
+    if(!(expr)) { \
+        (void)(param); \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %0         \n" \
+            ".set   pop       \n" \
+            : \
+            : "K" (ASSERT_EXT_DUMP) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT(TYPE, expr, dispatch_arg) \
+do { \
+    if(!(expr)) { \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        register kal_uint32 __dispatch_arg __asm__ ("$a0") = _dispatch_arg; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %1         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((__dispatch_arg)), "K" (ASSERT_CUS_##TYPE) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT_EXT1(TYPE, expr, dispatch_arg, e1) \
+do { \
+    if(!(expr)) { \
+        (void)(e1); \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        register kal_uint32 __dispatch_arg __asm__ ("$a0") = _dispatch_arg; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %1         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((__dispatch_arg)), "K" (ASSERT_CUS_##TYPE##_EXT1) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT_EXT2(TYPE, expr, dispatch_arg, e1, e2) \
+do { \
+    if(!(expr)) { \
+        (void)(e1); \
+        (void)(e2); \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        register kal_uint32 __dispatch_arg __asm__ ("$a0") = _dispatch_arg; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %1         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((__dispatch_arg)), "K" (ASSERT_CUS_##TYPE##_EXT2) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+#define CUSTOM_ASSERT_EXT3(TYPE, expr, dispatch_arg, e1, e2, e3) \
+do { \
+    if(!(expr)) { \
+        (void)(e1); \
+        (void)(e2); \
+        (void)(e3); \
+        kal_uint32 _dispatch_arg = (kal_uint32)(dispatch_arg); \
+        register kal_uint32 __dispatch_arg __asm__ ("$a0") = _dispatch_arg; \
+        __asm__ __volatile__( \
+            ".set   push      \n" \
+            ".set   noreorder \n" \
+            ".set   noat      \n" \
+            "break %1         \n" \
+            ".set   pop       \n" \
+            : \
+            : "r" ((__dispatch_arg)), "K" (ASSERT_CUS_##TYPE##_EXT3) \
+            : ); \
+        __builtin_unreachable (); \
+    } \
+} while (0)
+
+#define CUSTOM_ASSERT_ADDR(expr, dispatch_arg) CUSTOM_ASSERT(ADDR, expr, dispatch_arg)
+#define CUSTOM_ASSERT_ADDR_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(ADDR, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_ADDR_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(ADDR, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_ADDR_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(ADDR, expr, dispatch_arg, e1, e2, e3)
+
+#define CUSTOM_ASSERT_MODID(expr, dispatch_arg) CUSTOM_ASSERT(MODID, expr, dispatch_arg)
+#define CUSTOM_ASSERT_MODID_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(MODID, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_MODID_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(MODID, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_MODID_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(MODID, expr, dispatch_arg, e1, e2, e3)
+
+#define CUSTOM_ASSERT_MOFID(expr, dispatch_arg) CUSTOM_ASSERT(MOFID, expr, dispatch_arg)
+#define CUSTOM_ASSERT_MOFID_EXT1(expr, dispatch_arg, e1) CUSTOM_ASSERT_EXT1(MOFID, expr, dispatch_arg, e1)
+#define CUSTOM_ASSERT_MOFID_EXT2(expr, dispatch_arg, e1, e2) CUSTOM_ASSERT_EXT2(MOFID, expr, dispatch_arg, e1, e2)
+#define CUSTOM_ASSERT_MOFID_EXT3(expr, dispatch_arg, e1, e2, e3) CUSTOM_ASSERT_EXT3(MOFID, expr, dispatch_arg, e1, e2, e3)
+
+#endif /* __KAL_ASSERT_LEVEL__*/
+
+#else  /* __MIPS_IA__ || __MIPS_I7200__ */
+	 #error "Unsupported CPU type in assertion"
+#endif /* __MIPS_IA__ || __MIPS_I7200__ */
+
+#else  /* __MTK_TARGET__ && !__UBL__ */
+
+/* align to the highest assert level in MoDIS, no shrinking requirement */
+#define ASSERT(expr) do {if(!(expr)) kal_assert_fail((kal_char *)#expr, (kal_char *)__FILE__, __LINE__, KAL_FALSE, 0, 0, 0, NULL); } while (0)
+#define EXT_ASSERT3(expr, e1, e2, e3) do {if(!(expr)) kal_assert_fail((kal_char *)#expr, (kal_char *)__FILE__, __LINE__, KAL_TRUE, (e1), (e2), (e3), NULL); } while (0)
+#define EXT_ASSERT2(expr, e1, e2) EXT_ASSERT3(expr, e1, e2, 0)
+#define EXT_ASSERT1(expr, e1) EXT_ASSERT3(expr, e1, 0, 0)
+#define EXT_ASSERT(expr, e1, e2, e3) EXT_ASSERT3(expr, e1, e2, e3)
+#define EXT_ASSERT_DUMP(expr, param) do {if(!(expr)) kal_assert_fail((kal_char *)#expr, (kal_char *)__FILE__, __LINE__, KAL_TRUE, 0, 0, 0, (param)); } while (0)
+
+#endif /* __MTK_TARGET__ && !__UBL__ */
+#else  /* !__COSIM_BYPASS_DRV__ || __ESL_ENABLE_BREAK__ */
+extern void MDM_ASSERT(kal_uint32 e1, kal_uint32 e2, kal_uint32 e3); //extern MDM_ASSERT API in init_trc_api.h
+#define ASSERT(expr)                  do {if(!(expr)) {MDM_ASSERT(0, 0, 0); __builtin_unreachable();} } while (0)
+#define EXT_ASSERT3(expr, e1, e2, e3) do {if(!(expr)) {MDM_ASSERT((kal_uint32)e1, (kal_uint32)e2, (kal_uint32)e3); __builtin_unreachable();} } while (0)
+#define EXT_ASSERT2(expr, e1, e2)     EXT_ASSERT3(expr, e1, e2, 0)
+#define EXT_ASSERT1(expr, e1)         EXT_ASSERT3(expr, e1, 0, 0)
+#define EXT_ASSERT(expr, e1, e2, e3)  EXT_ASSERT3(expr, e1, e2, e3)
+#define EXT_ASSERT_DUMP(expr, param)  EXT_ASSERT3(expr, param, 0, 0)
+#endif /* !__COSIM_BYPASS_DRV__ || __ESL_ENABLE_BREAK__ */
+
+
+/* DOM-NOT_FOR_SDK-END */
+
+#ifdef __BUILD_DOM__
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  ASSERT
+ * DESCRIPTION
+ *  assert the condition is true, otherwise enter system exception handling.
+ * PARAMETERS
+ *  expr: [IN] the condition to be evaluated
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  (1)The assertion only takes effect when DEBUG_KAL is defined.
+ *  (2)No matter DEBUG_KAL is defined or not, the expr will be evaluated.
+ * SEE ALSO
+ *   EXT_ASSERT EXT_ASSERT_DUMP
+ ******************************************************************************/
+#define ASSERT(expr) __ASSERT(expr)
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  EXT_ASSERT
+ * DESCRIPTION
+ *  external assert the condition is true, otherwise enter system exception handling.
+ * PARAMETERS
+ *  expr: [IN] the condition to be evaluated.
+ *  e1: [IN] first extra expression recorded.
+ *  e2: [IN] second extra expression recorded.
+ *  e3: [IN] third extra expression recorded.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  (1)The assertion takes effect all the time, both DEBUG_KAL and RELEASE_KAL.
+ * SEE ALSO
+ *   ASSERT EXT_ASSERT_DUMP
+ ******************************************************************************/
+#define EXT_ASSERT(expr, e1, e2, e3) __EXT_ASSERT(expr, e1, e2, e3)
+#endif /*__BUILD_DOM__*/
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* _KAL_EX_API_H */
diff --git a/mcu/interface/service/kal/kal_general_types.h b/mcu/interface/service/kal/kal_general_types.h
new file mode 100644
index 0000000..225225d
--- /dev/null
+++ b/mcu/interface/service/kal/kal_general_types.h
@@ -0,0 +1,1346 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   kal_general_types.h
+ *
+ * Project:
+ * --------
+ *   Maui_Software
+ *
+ * Description:
+ * ------------
+ *   This file provides general fundemental types definations.
+ *   Independent with underlaying RTOS.
+ *
+ *   User who include this file may not require KAL API at all.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ ****************************************************************************/
+
+#ifndef _KAL_GENERAL_TYPES_H
+#define _KAL_GENERAL_TYPES_H
+
+#if defined(__ESL_COSIM_LTE__) || defined(__SYSTEMC__)
+#include "inttypes.h"
+#include "limits.h"
+#endif
+#include "clib.h"
+
+/*******************************************************************************
+ * Type Definitions
+ *******************************************************************************/
+
+/* portable character for multichar character set */
+typedef char kal_char;
+/* portable wide character for unicode character set */
+typedef unsigned short kal_wchar;
+
+/* portable 8-bit unsigned integer */
+typedef unsigned char kal_uint8;
+/* portable 8-bit signed integer */
+typedef signed char kal_int8;
+/* portable 16-bit unsigned integer */
+typedef unsigned short int kal_uint16;
+/* portable 16-bit signed integer */
+typedef signed short int kal_int16;
+/* portable 32-bit unsigned integer */
+typedef unsigned int kal_uint32;
+/* portable 32-bit signed integer */
+typedef signed int kal_int32;
+
+/* Workaround for Cgen standard header parsing issues */
+#if !(defined(GEN_FOR_PC) && defined(_MSC_VER))
+#include <stdint.h>
+#include <stddef.h>
+#else
+typedef signed int int_fast8_t;
+typedef signed int int_fast16_t;
+typedef signed int int_fast32_t;
+typedef signed long long int_fast64_t;
+typedef unsigned int uint_fast8_t;
+typedef unsigned int uint_fast16_t;
+typedef unsigned int uint_fast32_t;
+typedef unsigned long long uint_fast64_t;
+typedef signed int intptr_t;
+typedef unsigned int uintptr_t;
+typedef signed int ptrdiff_t;
+#endif
+
+/* fast signed integer types.
+ * fastest signed integer type with width of
+ * at least 8, 16, 32 and 64 bits respectively. */
+typedef int_fast8_t kal_int_fast8;
+typedef int_fast16_t kal_int_fast16;
+typedef int_fast32_t kal_int_fast32;
+typedef int_fast64_t kal_int_fast64;
+
+/* fast unsigned integer types.
+ * fastest unsigned integer type with width of
+ * at least 8, 16, 32 and 64 bits respectively. */
+typedef uint_fast8_t kal_uint_fast8;
+typedef uint_fast16_t kal_uint_fast16;
+typedef uint_fast32_t kal_uint_fast32;
+typedef uint_fast64_t kal_uint_fast64;
+
+/* types useful for integer operations on pointers. */
+typedef intptr_t kal_intptr;
+typedef uintptr_t kal_uintptr;
+typedef ptrdiff_t kal_ptrdiff;
+
+/* portable 64-bit unsigned integer */
+#if defined(__ARMCC_VERSION) || defined(__GNUC__) || defined(__MINGW32__) || \
+    defined(GEN_FOR_PC)
+typedef unsigned long long kal_uint64;
+#elif defined(_MSC_VER)
+typedef unsigned __int64 kal_uint64;
+#endif /* Cross RVCT/GCC/VC9 Compiler marco definition */
+
+/* portable 64-bit signed integer */
+#if defined(__ARMCC_VERSION) || defined(__GNUC__) || defined(__MINGW32__) || \
+    defined(GEN_FOR_PC)
+typedef signed long long kal_int64;
+#elif defined(_MSC_VER)
+typedef __int64          kal_int64;
+#endif /* Cross RVCT/GCC/VC9 Compiler marco definition */
+
+
+#if !defined(_WINNT_H) && !defined(_WINNT_)
+typedef unsigned short WCHAR;
+#endif
+
+
+/* boolean representation */
+
+#if defined(__UE_SIMULATOR__)
+
+/* Windows enum is always 32-bit, but target compiler uses the smallest data
+   type which can be used to present the enum value range. Therefore we use
+   char type in UESIM to force 8-bit size for variables which are of kal_bool
+   type to ensure target compatibility. kal_bool_t is used to preserve
+   KAL_FALSE and KAL_TRUE as enum constants. */
+
+typedef enum {
+    /* FALSE value */
+    KAL_FALSE,
+    /* TRUE value */
+    KAL_TRUE
+} kal_bool_t;
+
+typedef unsigned char kal_bool;
+#else  /* defined (__UE_SIMULATOR__) */
+typedef enum {
+    /* FALSE value */
+    KAL_FALSE,
+    /* TRUE value */
+    KAL_TRUE
+} kal_bool;
+#endif /* defined (__UE_SIMULATOR__) */
+
+/*******************************************************************************
+ * Constant definition
+ *******************************************************************************/
+#ifndef NULL
+#define NULL 0
+#endif
+
+/*******************************************************************************
+ * ALIGN and PACK macro definition
+ *******************************************************************************/
+
+#if defined(__ARMCC_VERSION)
+#define DECLARE_ALIGN_BEGIN(n) __align(n)
+#define DECLARE_ALIGN_END(n)
+#define DECLARE_ALIGN_MIDDLE(n)
+#elif defined(__MINGW32__) /* end of __ARMCC_VERSION */
+#define DECLARE_ALIGN_BEGIN(n)
+#define DECLARE_ALIGN_END(n) __attribute__((aligned(n)))
+#define DECLARE_ALIGN_MIDDLE(n)
+#elif defined(__GNUC__) /* end of __MINGW32__ */
+#define DECLARE_ALIGN_BEGIN(n)
+#define DECLARE_ALIGN_END(n) __attribute__((aligned(n)))
+#define DECLARE_ALIGN_MIDDLE(n)
+#elif defined(_MSC_VER) && (_MSC_VER >= 1500) /* end of __GNUC__ */
+#define DECLARE_ALIGN_BEGIN(n) __declspec(align(n))
+#define DECLARE_ALIGN_END(n) /* end of _MSC_VER */
+#define DECLARE_ALIGN_MIDDLE(n)
+#else /* end of _MSC_VER */
+#error "Unsupported Compiler in Simulator"
+#endif
+
+#if defined(__ARMCC_VERSION)
+#define PRAGMA_BEGIN_PACK_STRUCT _Pragma("push") _Pragma("pack(1)")
+#define PRAGMA_END_PACK_STRUCT _Pragma("pop")
+#elif defined(__MINGW32__) /* end of __ARMCC_VERSION */
+#define PRAGMA_BEGIN_PACK_STRUCT _Pragma("pack(push, 1)")
+#define PRAGMA_END_PACK_STRUCT _Pragma("pack(pop)")
+#elif defined(__GNUC__) /* end of _MINGW32_ */
+#define PRAGMA_BEGIN_PACK_STRUCT _Pragma("pack(push, 1)")
+#define PRAGMA_END_PACK_STRUCT _Pragma("pack(pop)")
+#elif defined(_MSC_VER) && (_MSC_VER >= 1500) /* end of __GNUC__ */
+#define PRAGMA_BEGIN_PACK_STRUCT __pragma(pack(push, 1))
+#define PRAGMA_END_PACK_STRUCT __pragma(pack(pop))
+#else /* end of _MSC_VER */
+#error "Unsupported Compiler in Simulator"
+#endif
+
+
+#if defined(__ARMCC_VERSION)
+#define RO_CODE_SECTION(section_name) __attribute__((section(#section_name)))
+#define RO_DATA_SECTION(section_name) __attribute__((section(#section_name)))
+#define RW_DATA_SECTION(section_name) __attribute__((section(#section_name)))
+#define ZI_DATA_SECTION(section_name) \
+    __attribute__((zero_init, section(#section_name)))
+#define DEFAULT_SECTION
+#elif defined(__MINGW32__) /* end of __ARMCC_VERSION */
+#define RO_CODE_SECTION(section_name) __attribute__((section(#section_name)))
+#define RO_DATA_SECTION(section_name) __attribute__((section(#section_name)))
+#define RW_DATA_SECTION(section_name) __attribute__((section(#section_name)))
+#define ZI_DATA_SECTION(section_name) __attribute__((section(#section_name)))
+#define DEFAULT_SECTION
+#elif defined(__GNUC__) /* end of _MINGW32_ */
+#define RO_CODE_SECTION(section_name) __attribute__((section(#section_name)))
+#define RO_DATA_SECTION(section_name) __attribute__((section(#section_name)))
+#define RW_DATA_SECTION(section_name) __attribute__((section(#section_name)))
+#define ZI_DATA_SECTION(section_name) __attribute__((section(#section_name)))
+#define DEFAULT_SECTION
+#elif defined(_MSC_VER) && (_MSC_VER >= 1500) /* end of __GNUC__ */
+#define RO_CODE_SECTION(section_name)
+#define RO_DATA_SECTION(section_name)
+#define RW_DATA_SECTION(section_name)
+#define ZI_DATA_SECTION(section_name)
+#define DEFAULT_SECTION
+#else /* end of _MSC_VER */
+#error "Unsupported Compiler in Simulator"
+#endif
+
+
+#if defined(__ARMCC_VERSION)
+#define DECLARE_MIPS16
+#elif defined(__MINGW32__) /* end of __ARMCC_VERSION */
+#define DECLARE_MIPS16
+#elif defined(__GNUC__) && defined(GEN_FOR_PC) /* end of __MINGW32__ */
+#define DECLARE_MIPS16
+#elif defined(__GNUC__) /*  defined(__GNUC__) && defined(GEN_FOR_PC) */
+#if defined(__nanomips__)
+#define DECLARE_MIPS16
+#else
+#define DECLARE_MIPS16 __attribute__((mips16))
+#endif
+#elif defined(_MSC_VER) && (_MSC_VER >= 1500) /* end of __GNUC__ */
+#define DECLARE_MIPS16
+#else /* end of defined(_MSC_VER) && (_MSC_VER >= 1500) */
+#error "Unsupported Compiler in Simulator"
+#endif
+
+
+#if defined(__ARMCC_VERSION)
+#define DECLARE_MIPS32
+#elif defined(__MINGW32__) /* end of __ARMCC_VERSION */
+#define DECLARE_MIPS32
+#elif defined(__GNUC__) && defined(GEN_FOR_PC) /* end of __MINGW32__ */
+#define DECLARE_MIPS32
+#elif defined(__GNUC__) /*  defined(__GNUC__) && defined(GEN_FOR_PC) */
+#if defined(__nanomips__)
+#define DECLARE_MIPS32
+#else
+#define DECLARE_MIPS32 __attribute__((nomips16))
+#endif
+#elif defined(_MSC_VER) && (_MSC_VER >= 1500) /* end of __GNUC__ */
+#define DECLARE_MIPS32
+#else /* end of defined(_MSC_VER) && (_MSC_VER >= 1500) */
+#error "Unsupported Compiler in Simulator"
+#endif
+
+
+#if defined(__ARMCC_VERSION)
+#define DECLARE_MIPS32_TEMP
+#elif defined(__MINGW32__) /* end of __ARMCC_VERSION */
+#define DECLARE_MIPS32_TEMP
+#elif defined(__GNUC__) && defined(GEN_FOR_PC) /* end of __MINGW32__ */
+#define DECLARE_MIPS32_TEMP
+#elif defined(__GNUC__) /*  defined(__GNUC__) && defined(GEN_FOR_PC) */
+#if defined(__nanomips__)
+#define DECLARE_MIPS32_TEMP
+#else
+#define DECLARE_MIPS32_TEMP __attribute__((nomips16))
+#endif
+#elif defined(_MSC_VER) && (_MSC_VER >= 1500) /* end of __GNUC__ */
+#define DECLARE_MIPS32_TEMP
+#else /* end of defined(_MSC_VER) && (_MSC_VER >= 1500) */
+#error "Unsupported Compiler in Simulator"
+#endif
+
+
+#if defined(__ARMCC_VERSION)
+#define DECLARE_NOINLINE __attribute__((noinline))
+#elif defined(__MINGW32__) /* end of __ARMCC_VERSION */
+#define DECLARE_NOINLINE __attribute__((noinline))
+#elif defined(__GNUC__) /* end of _MINGW32_ */
+#define DECLARE_NOINLINE __attribute__((noinline))
+#elif defined(_MSC_VER) && (_MSC_VER >= 1500) /* end of __GNUC__ */
+#define DECLARE_NOINLINE
+#else /* end of _MSC_VER */
+#error "Unsupported Compiler in Simulator"
+#endif
+
+
+#if defined(__ARMCC_VERSION)
+#define DECLARE_WEAK __attribute__((weak))
+#elif defined(__MINGW32__) /* end of __ARMCC_VERSION */
+#define DECLARE_WEAK __attribute__((weak))
+#elif defined(__GNUC__) /* end of _MINGW32_ */
+#define DECLARE_WEAK __attribute__((weak))
+#elif defined(_MSC_VER) && (_MSC_VER >= 1500) /* end of __GNUC__ */
+#define DECLARE_WEAK
+#else /* end of _MSC_VER */
+#error "Unsupported Compiler in Simulator"
+#endif
+
+
+#if defined(__ARMCC_VERSION)
+#define DECLARE_DEPRECATED __attribute__((deprecated))
+#elif defined(__MINGW32__) /* end of __ARMCC_VERSION */
+#define DECLARE_DEPRECATED __attribute__((deprecated))
+#elif defined(__GNUC__) /* end of _MINGW32_ */
+#define DECLARE_DEPRECATED __attribute__((deprecated))
+#elif defined(_MSC_VER) && (_MSC_VER >= 1500) /* end of __GNUC__ */
+#define DECLARE_DEPRECATED
+#else /* end of _MSC_VER */
+#error "Unsupported Compiler in Simulator"
+#endif
+
+
+#if defined(__ARMCC_VERSION)
+#define UNUSED_PARAMETER(x) (void)(x)
+#elif defined(__MINGW32__) /* end of __ARMCC_VERSION */
+#define UNUSED_PARAMETER(x) (void)(x)
+#elif defined(__GNUC__) /* end of _MINGW32_ */
+#define UNUSED_PARAMETER(x) (void)(x)
+#elif defined(_MSC_VER) && (_MSC_VER >= 1500) /* end of __GNUC__ */
+#define UNUSED_PARAMETER(x) (void)(x)
+#else /* end of _MSC_VER */
+#error "Unsupported Compiler in Simulator"
+#endif
+
+
+/*******************************************************************************
+ * Type Definitions
+ *******************************************************************************/
+#if defined(_MSC_VER) && (_MSC_VER >= 1500)
+#define SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, alignment) \
+    kal_char                                                       \
+        DISCARD__##name[sizeof(char[1 - 2 * !!!(!(_aligned_size % alignment))])];
+#elif defined(__GNUC__) /* for both pcore and l1core*/
+#define SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, alignment) \
+    __attribute__((section("SHOULD_NOT_USED_RODATA"))) kal_char    \
+        DISCARD__##name[sizeof(char[1 - 2 * !!!(!(_aligned_size % alignment))])];
+#endif
+
+
+#if defined(__ARMCC_VERSION)
+#error "Unsupported Compiler in Simulator"
+#elif defined(__MINGW32__) /* end of __ARMCC_VERSION */
+/** DC **/
+#define DEFINE_RCU_DC_ARRAY(type, name, size) type name[size];
+#define DEFINE_RCU_C_ARRAY(type, name, size) type  name[size];
+
+/** DNC **/
+#define DEFINE_DNC_SHARED_VAR(type, name) type name;
+#define DEFINE_DNC_SHARED_ARRAY(type, name, size) type     name[size];
+#define DEFINE_RCU_DNC_SHARED_ARRAY(type, name, size) type name[size];
+
+#define DEFINE_DNC_SHARED_VAR_ASSIGN(type, name, ...) type name = {__VA_ARGS__};
+#define DEFINE_DNC_SHARED_ARRAY_ASSIGN(type, name, size, ...) \
+    type name[size] = {__VA_ARGS__};
+
+/** NC **/
+#define DEFINE_NC_SHARED_VAR(type, name) DEFINE_DNC_SHARED_VAR(type, name)
+#define DEFINE_NC_SHARED_ARRAY(type, name, size) \
+    DEFINE_DNC_SHARED_ARRAY(type, name, size)
+#define DEFINE_RCU_NC_SHARED_ARRAY(type, name, size) \
+    DEFINE_RCU_DNC_SHARED_ARRAY(type, name, size)
+
+#define DEFINE_NC_SHARED_VAR_ASSIGN(type, name, ...) \
+    DEFINE_DNC_SHARED_VAR_ASSIGN(type, name, {__VA_ARGS__})
+#define DEFINE_NC_SHARED_ARRAY_ASSIGN(type, name, size, ...) \
+    DEFINE_DNC_SHARED_ARRAY_ASSIGN(type, name, size, {__VA_ARGS__})
+
+/** DNC ALIGNED **/
+#define DEFINE_DNC_ALIGNED_SHARED_VAR(type, name, _aligned_size) type name;
+#define DEFINE_DNC_ALIGNED_SHARED_ARRAY(type, name, size, _aligned_size) \
+    type name[size];
+
+#define DEFINE_DNC_ALIGNED_SHARED_VAR_ASSIGN(type, name, _aligned_size, ...) \
+    type name = {__VA_ARGS__};
+#define DEFINE_DNC_ALIGNED_SHARED_ARRAY_ASSIGN(type, name, size, alignd_size, ...) \
+    type name[size] = {__VA_ARGS__};
+
+/** NC ALIGNED **/
+#define DEFINE_NC_ALIGNED_SHARED_VAR(type, name, _aligned_size) \
+    DEFINE_DNC_ALIGNED_SHARED_VAR(type, name, _aligned_size)
+#define DEFINE_NC_ALIGNED_SHARED_ARRAY(type, name, size, _aligned_size) \
+    DEFINE_DNC_ALIGNED_SHARED_ARRAY(type, name, size, _aligned_size)
+
+#define DEFINE_NC_ALIGNED_SHARED_VAR_ASSIGN(type, name, _aligned_size, ...) \
+    DEFINE_DNC_ALIGNED_SHARED_VAR_ASSIGN(type, name, _aligned_size, {__VA_ARGS__})
+#define DEFINE_NC_ALIGNED_SHARED_ARRAY_ASSIGN(type, name, size, _aligned_size, ...) \
+    DEFINE_DNC_ALIGNED_SHARED_ARRAY_ASSIGN(type, name, size, _aligned_size,         \
+                                           {__VA_ARGS__})
+
+#elif defined(_MSC_VER) && (_MSC_VER >= 1500) /* end of __MINGW32__ */
+/** DC **/
+#define DEFINE_RCU_DC_ARRAY(type, name, size) __declspec(align(32)) type name[size];
+#define DEFINE_RCU_C_ARRAY(type, name, size) __declspec(align(32)) type name[size];
+
+/** DNC **/
+#define DEFINE_DNC_SHARED_VAR(type, name) __declspec(align(32)) type name;
+#define DEFINE_DNC_SHARED_ARRAY(type, name, size) \
+    __declspec(align(32)) type name[size];
+#define DEFINE_RCU_DNC_SHARED_ARRAY(type, name, size) \
+    __declspec(align(32)) type name[size];
+
+#define DEFINE_DNC_SHARED_VAR_ASSIGN(type, name, ...) \
+    __declspec(align(32)) type name = {__VA_ARGS__};
+#define DEFINE_DNC_SHARED_ARRAY_ASSIGN(type, name, size, ...) \
+    __declspec(align(32)) type name[size] = {__VA_ARGS__};
+
+/** NC **/ /* we do not apply the alignment as GCC since VC only support constant value alignment */
+#define DEFINE_NC_SHARED_VAR(type, name) __declspec(align(4)) type name;
+#define DEFINE_NC_SHARED_ARRAY(type, name, size) \
+    __declspec(align(4)) type name[size];
+#define DEFINE_RCU_NC_SHARED_ARRAY(type, name, size) \
+    __declspec(align(32)) type name[size];
+
+#define DEFINE_NC_SHARED_VAR_ASSIGN(type, name, ...) \
+    __declspec(align(4)) type name = {__VA_ARGS__};
+#define DEFINE_NC_SHARED_ARRAY_ASSIGN(type, name, size, ...) \
+    __declspec(align(4)) type name[size] = {__VA_ARGS__};
+
+/** DNC ALIGNED **/
+#define DEFINE_DNC_ALIGNED_SHARED_VAR(type, name, _aligned_size) \
+    __declspec(align(_aligned_size)) type name;                  \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, 32);
+#define DEFINE_DNC_ALIGNED_SHARED_ARRAY(type, name, size, _aligned_size) \
+    __declspec(align(_aligned_size)) type name[size];                    \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, 32);
+
+#define DEFINE_DNC_ALIGNED_SHARED_VAR_ASSIGN(type, name, _aligned_size, ...) \
+    __declspec(align(_aligned_size)) type name = {__VA_ARGS__};              \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, 32);
+#define DEFINE_DNC_ALIGNED_SHARED_ARRAY_ASSIGN(type, name, size, _aligned_size, \
+                                               ...)                             \
+    __declspec(align(_aligned_size)) type name[size] = {__VA_ARGS__};           \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, 32);
+
+/** NC ALIGNED **/
+#define DEFINE_NC_ALIGNED_SHARED_VAR(type, name, _aligned_size) \
+    __declspec(align(_aligned_size)) type name;                 \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, (_aligned_size >= 32 ? 32 : 4));
+#define DEFINE_NC_ALIGNED_SHARED_ARRAY(type, name, size, _aligned_size) \
+    __declspec(align(_aligned_size)) type name[size];                   \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, (_aligned_size >= 32 ? 32 : 4));
+
+#define DEFINE_NC_ALIGNED_SHARED_VAR_ASSIGN(type, name, _aligned_size, ...) \
+    __declspec(align(_aligned_size)) type name = {__VA_ARGS__};             \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, (_aligned_size >= 32 ? 32 : 4));
+#define DEFINE_NC_ALIGNED_SHARED_ARRAY_ASSIGN(type, name, size, _aligned_size, ...) \
+    __declspec(align(_aligned_size)) type name[size] = {__VA_ARGS__};               \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, (_aligned_size >= 32 ? 32 : 4));
+
+
+/*MCU-RO & HW-RW *********************************/
+/** DNC ALIGNED **/
+#define __MCURO_HWRW_DNC_ALIGNED_NOINIT(_aligned_size)
+
+/** DC ALIGNED **/
+#define __MCURO_HWRW_DC_ALIGNED_NOINIT(_aligned_size)
+
+/** NC ALIGNED **/
+#define __MCURO_HWRW_NC_ALIGNED_NOINIT(_aligned_size)
+
+/** C ALIGNED **/
+#define __MCURO_HWRW_C_ALIGNED_NOINIT(_aligned_size)
+
+/*MCU-RW & HW-RW *********************************/
+/** DNC ALIGNED **/
+#define __MCURW_HWRW_DNC_ALIGNED_RW(_aligned_size)
+#define __MCURW_HWRW_DNC_ALIGNED_ZI(_aligned_size)
+
+/** DC ALIGNED **/
+#define __MCURW_HWRW_DC_ALIGNED_RW(_aligned_size)
+#define __MCURW_HWRW_DC_ALIGNED_ZI(_aligned_size)
+
+/** NC ALIGNED **/
+#define __MCURW_HWRW_NC_ALIGNED_RW(_aligned_size)
+#define __MCURW_HWRW_NC_ALIGNED_ZI(_aligned_size)
+
+/** C ALIGNED **/
+#define __MCURW_HWRW_C_ALIGNED_RW(_aligned_size)
+#define __MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+
+/** IOCU **/
+#define __IOCU2_NON_ALLOC_MCURW_HWRW_C_ALIGNED_RW(_aligned_size)
+#define __IOCU2_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_00_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_01_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_02_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_03_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_04_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_05_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_06_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_07_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_08_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_09_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_10_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_11_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_12_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_13_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_14_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU2_15_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_READ_ALLOC_MCURW_HWRW_C_ALIGNED_RW(_aligned_size)
+#define __IOCU3_READ_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_RW(_aligned_size)
+#define __IOCU3_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_00_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_01_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_02_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_03_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_04_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_05_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_06_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_07_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_08_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_09_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_10_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_11_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_12_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_13_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_14_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+#define __IOCU3_15_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size)
+
+/*MCU-RW & HW-RO *********************************/
+/** DNC ALIGNED **/
+#define __MCURW_HWRO_DNC_ALIGNED_RW(_aligned_size)
+#define __MCURW_HWRO_DNC_ALIGNED_ZI(_aligned_size)
+
+/** NC ALIGNED **/
+#define __MCURW_HWRO_NC_ALIGNED_RW(_aligned_size)
+#define __MCURW_HWRO_NC_ALIGNED_ZI(_aligned_size)
+
+/** DC ALIGNED **/
+#define __MCURW_HWRO_DC_ALIGNED_RW(_aligned_size)
+#define __MCURW_HWRO_DC_ALIGNED_ZI(_aligned_size)
+
+/** C ALIGNED **/ /** Variables be declared without any specified will be default placed in .data or .bss section  **/
+#define __MCURW_HWRO_C_ALIGNED_RW(_aligned_size)
+#define __MCURW_HWRO_C_ALIGNED_ZI(_aligned_size)
+
+/* Per-Core Section *********************************/
+/* Core0 */
+/** DNC ALIGNED **/
+#define __PER_CORE_DNC_ALIGNED_RW_CORE0(_aligned_size)
+#define __PER_CORE_DNC_ALIGNED_ZI_CORE0(_aligned_size)
+
+/** NC ALIGNED **/
+#define __PER_CORE_NC_ALIGNED_RW_CORE0(_aligned_size)
+#define __PER_CORE_NC_ALIGNED_ZI_CORE0(_aligned_size)
+
+/** DC ALIGNED **/
+#define __PER_CORE_DC_ALIGNED_RW_CORE0(_aligned_size)
+#define __PER_CORE_DC_ALIGNED_ZI_CORE0(_aligned_size)
+
+/** C ALIGNED **/
+#define __PER_CORE_C_ALIGNED_RW_CORE0(_aligned_size)
+#define __PER_CORE_C_ALIGNED_ZI_CORE0(_aligned_size)
+
+/* Core0 */
+/** DNC ALIGNED **/
+#define __PER_CORE_DNC_ALIGNED_RW_CORE1(_aligned_size)
+#define __PER_CORE_DNC_ALIGNED_ZI_CORE1(_aligned_size)
+
+/** NC ALIGNED **/
+#define __PER_CORE_NC_ALIGNED_RW_CORE1(_aligned_size)
+#define __PER_CORE_NC_ALIGNED_ZI_CORE1(_aligned_size)
+
+/** DC ALIGNED **/
+#define __PER_CORE_DC_ALIGNED_RW_CORE1(_aligned_size)
+#define __PER_CORE_DC_ALIGNED_ZI_CORE1(_aligned_size)
+
+/** C ALIGNED **/
+#define __PER_CORE_C_ALIGNED_RW_CORE1(_aligned_size)
+#define __PER_CORE_C_ALIGNED_ZI_CORE1(_aligned_size)
+
+/* Core2 */
+/** DNC ALIGNED **/
+#define __PER_CORE_DNC_ALIGNED_RW_CORE2(_aligned_size)
+#define __PER_CORE_DNC_ALIGNED_ZI_CORE2(_aligned_size)
+
+/** NC ALIGNED **/
+#define __PER_CORE_NC_ALIGNED_RW_CORE2(_aligned_size)
+#define __PER_CORE_NC_ALIGNED_ZI_CORE2(_aligned_size)
+
+/** DC ALIGNED **/
+#define __PER_CORE_DC_ALIGNED_RW_CORE2(_aligned_size)
+#define __PER_CORE_DC_ALIGNED_ZI_CORE2(_aligned_size)
+
+/** C ALIGNED **/
+#define __PER_CORE_C_ALIGNED_RW_CORE2(_aligned_size)
+#define __PER_CORE_C_ALIGNED_ZI_CORE2(_aligned_size)
+
+/** C NOINIT ALIGNED **/
+#define __EXTSRAM_C_ALIGNED_NOINIT(_aligned_size)
+
+#if defined(__ESL_MASE_GEN97__)
+#include "kal_general_types_MASE.h"
+#endif
+#elif defined(__GNUC__)
+/** DC **/
+#define DEFINE_RCU_DC_ARRAY(type, name, size) \
+    type name[size] __attribute__((section("DYNAMICCACHEABLEZI_C"), aligned(32)));
+#define DEFINE_RCU_C_ARRAY(type, name, size) \
+    type name[size] __attribute__((aligned(32)));
+
+/** DNC **/
+#define DEFINE_DNC_SHARED_VAR(type, name) \
+    type name __attribute__((section("DYNAMICCACHEABLEZI_NC"), aligned(32)));
+#define DEFINE_DNC_SHARED_ARRAY(type, name, size) \
+    type name[size] __attribute__((section("DYNAMICCACHEABLEZI_NC"), aligned(32)));
+#define DEFINE_RCU_DNC_SHARED_ARRAY(type, name, size) \
+    type name[size] __attribute__((section("DYNAMICCACHEABLEZI_NC"), aligned(32)));
+
+#define DEFINE_DNC_SHARED_VAR_ASSIGN(type, name, ...)                            \
+    type name __attribute__((section("DYNAMICCACHEABLERW_NC"), aligned(32))) = { \
+        __VA_ARGS__};
+#define DEFINE_DNC_SHARED_ARRAY_ASSIGN(type, name, size, ...) \
+    type name[size] __attribute__(                            \
+        (section("DYNAMICCACHEABLERW_NC"), aligned(32))) = {__VA_ARGS__};
+
+/** NC **/
+#define DEFINE_NC_SHARED_VAR(type, name) \
+    type name __attribute__(             \
+        (section("NONCACHEDZI"), aligned((sizeof(type) >= 32 ? 32 : 4))));
+#define DEFINE_NC_SHARED_ARRAY(type, name, size) \
+    type name[size] __attribute__(               \
+        (section("NONCACHEDZI"), aligned(((sizeof(type) * size) >= 32 ? 32 : 4))));
+#define DEFINE_RCU_NC_SHARED_ARRAY(type, name, size) \
+    type name[size] __attribute__((section("NONCACHEDZI"), aligned(32)));
+
+#define DEFINE_NC_SHARED_VAR_ASSIGN(type, name, ...) \
+    type name                                        \
+        __attribute__((section("NONCACHEDRW"),       \
+                       aligned((sizeof(type) >= 32 ? 32 : 4)))) = {__VA_ARGS__};
+#define DEFINE_NC_SHARED_ARRAY_ASSIGN(type, name, size, ...) \
+    type name[size] __attribute__(                           \
+        (section("NONCACHEDRW"),                             \
+         aligned(((sizeof(type) * size) >= 32 ? 32 : 4)))) = {__VA_ARGS__};
+
+/** DNC ALIGNED **/
+#define DEFINE_DNC_ALIGNED_SHARED_VAR(type, name, _aligned_size)                   \
+    type name                                                                      \
+        __attribute__((section("DYNAMICCACHEABLEZI_NC"), aligned(_aligned_size))); \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, 32);
+#define DEFINE_DNC_ALIGNED_SHARED_ARRAY(type, name, size, _aligned_size)           \
+    type name[size]                                                                \
+        __attribute__((section("DYNAMICCACHEABLEZI_NC"), aligned(_aligned_size))); \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, 32);
+
+#define DEFINE_DNC_ALIGNED_SHARED_VAR_ASSIGN(type, name, _aligned_size, ...) \
+    type name __attribute__((section("DYNAMICCACHEABLERW_NC"),               \
+                             aligned(_aligned_size))) = {__VA_ARGS__};       \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, 32);
+#define DEFINE_DNC_ALIGNED_SHARED_ARRAY_ASSIGN(type, name, size, _aligned_size, \
+                                               ...)                             \
+    type name[size] __attribute__((section("DYNAMICCACHEABLERW_NC"),            \
+                                   aligned(_aligned_size))) = {__VA_ARGS__};    \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, 32);
+
+/** NC ALIGNED **/
+#define DEFINE_NC_ALIGNED_SHARED_VAR(type, name, _aligned_size)        \
+    type name __attribute__(                                           \
+        (section("NONCACHEDZI"),                                       \
+         aligned((_aligned_size >= 32                                  \
+                      ? _aligned_size                                  \
+                      : (sizeof(type) >= 32 ? 32 : _aligned_size))))); \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, (_aligned_size >= 32 ? 32 : 4));
+#define DEFINE_NC_ALIGNED_SHARED_ARRAY(type, name, size, _aligned_size)         \
+    type name[size] __attribute__(                                              \
+        (section("NONCACHEDZI"),                                                \
+         aligned((_aligned_size >= 32                                           \
+                      ? _aligned_size                                           \
+                      : ((sizeof(type) * size) >= 32 ? 32 : _aligned_size))))); \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, (_aligned_size >= 32 ? 32 : 4));
+
+#define DEFINE_NC_ALIGNED_SHARED_VAR_ASSIGN(type, name, _aligned_size, ...) \
+    type name __attribute__(                                                \
+        (section("NONCACHEDRW"),                                            \
+         aligned((_aligned_size >= 32                                       \
+                      ? _aligned_size                                       \
+                      : (sizeof(type) >= 32 ? 32 : _aligned_size))))) = {   \
+        __VA_ARGS__};                                                       \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, (_aligned_size >= 32 ? 32 : 4));
+#define DEFINE_NC_ALIGNED_SHARED_ARRAY_ASSIGN(type, name, size, _aligned_size, ...) \
+    type name[size] __attribute__(                                                  \
+        (section("NONCACHEDRW"),                                                    \
+         aligned((_aligned_size >= 32                                               \
+                      ? _aligned_size                                               \
+                      : ((sizeof(type) * size) >= 32 ? 32 : _aligned_size))))) = {  \
+        __VA_ARGS__};                                                               \
+    SHARED_VAR_ALIGNMENT_CHECK(name, _aligned_size, (_aligned_size >= 32 ? 32 : 4));
+
+
+/*MCU-RO & HW-RW *********************************/
+/** DNC ALIGNED **/
+#define __MCURO_HWRW_DNC_ALIGNED_NOINIT(_aligned_size) \
+    __attribute__((section("MCURO_HWRW_DNC_NOINIT"), aligned(_aligned_size)))
+
+/** DC ALIGNED **/
+#define __MCURO_HWRW_DC_ALIGNED_NOINIT(_aligned_size) \
+    __attribute__((section("MCURO_HWRW_DC_NOINIT"), aligned(_aligned_size)))
+
+/** NC ALIGNED **/
+#define __MCURO_HWRW_NC_ALIGNED_NOINIT(_aligned_size) \
+    __attribute__((section("MCURO_HWRW_NC_NOINIT"), aligned(_aligned_size)))
+
+/** C ALIGNED **/
+#define __MCURO_HWRW_C_ALIGNED_NOINIT(_aligned_size) \
+    __attribute__((section("MCURO_HWRW_C_NOINIT"), aligned(_aligned_size)))
+
+/*MCU-RW & HW-RW *********************************/
+/** DNC ALIGNED **/
+#define __MCURW_HWRW_DNC_ALIGNED_RW(_aligned_size) \
+    __attribute__((section("MCURW_HWRW_DNC_RW"), aligned(_aligned_size)))
+
+#define __MCURW_HWRW_DNC_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("MCURW_HWRW_DNC_ZI"), aligned(_aligned_size)))
+
+/** DC ALIGNED **/
+#define __MCURW_HWRW_DC_ALIGNED_RW(_aligned_size) \
+    __attribute__((section("MCURW_HWRW_DC_RW"), aligned(_aligned_size)))
+
+#define __MCURW_HWRW_DC_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("MCURW_HWRW_DC_ZI"), aligned(_aligned_size)))
+
+/** NC ALIGNED **/
+#define __MCURW_HWRW_NC_ALIGNED_RW(_aligned_size) \
+    __attribute__((section("MCURW_HWRW_NC_RW"), aligned(_aligned_size)))
+
+#define __MCURW_HWRW_NC_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("MCURW_HWRW_NC_ZI"), aligned(_aligned_size)))
+
+/** C ALIGNED **/
+#define __MCURW_HWRW_C_ALIGNED_RW(_aligned_size) \
+    __attribute__((section("MCURW_HWRW_C_RW"), aligned(_aligned_size)))
+
+#define __MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+
+/** IOCU **/
+#define __IOCU2_NON_ALLOC_MCURW_HWRW_C_ALIGNED_RW(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_NON_ALLOC_MCURW_HWRW_C_RW"), aligned(_aligned_size)))
+
+#define __IOCU2_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_00_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_00_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_01_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_01_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_02_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_02_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_03_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_03_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_04_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_04_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_05_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_05_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_06_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_06_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_07_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_07_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_08_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_08_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_09_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_09_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_10_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_10_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_11_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_11_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_12_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_12_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_13_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_NON_ALLOC_MCURW_HWRHWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_14_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_14_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU2_15_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                               \
+        (section("IOCU2_15_NON_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+
+#define __IOCU3_READ_ALLOC_MCURW_HWRW_C_ALIGNED_RW(_aligned_size) \
+    __attribute__(                                                \
+        (section("IOCU3_READ_ALLOC_MCURW_HWRW_C_RW"), aligned(_aligned_size)))
+
+#define __IOCU3_READ_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__(                                                \
+        (section("IOCU3_READ_ALLOC_MCURW_HWRW_C_ZI"), aligned(_aligned_size)))
+#define __IOCU3_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_RW(_aligned_size) \
+    __attribute__((section("IOCU3_READ_WRITE_ALLOC_MCURW_HWRW_C_RW"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_00_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_00_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_01_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_01_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_02_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_02_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_03_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_03_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_04_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_04_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_05_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_05_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_06_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_06_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_07_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_07_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_08_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_08_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_09_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_09_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_10_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_10_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_11_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_11_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_12_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_12_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_13_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_13_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_14_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_14_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+#define __IOCU3_15_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("IOCU3_15_READ_WRITE_ALLOC_MCURW_HWRW_C_ZI"),   \
+                   aligned(_aligned_size)))
+
+/*MCU-RW & HW-RO *********************************/
+/** DNC ALIGNED **/
+#define __MCURW_HWRO_DNC_ALIGNED_RW(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLERW_NC"), aligned(_aligned_size)))
+
+#define __MCURW_HWRO_DNC_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLEZI_NC"), aligned(_aligned_size)))
+
+/** NC ALIGNED **/
+#define __MCURW_HWRO_NC_ALIGNED_RW(_aligned_size) \
+    __attribute__((section("NONCACHEDRW"), aligned(_aligned_size)))
+
+#define __MCURW_HWRO_NC_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("NONCACHEDZI"), aligned(_aligned_size)))
+
+/** DC ALIGNED **/
+#define __MCURW_HWRO_DC_ALIGNED_RW(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLERW_C"), aligned(_aligned_size)))
+
+#define __MCURW_HWRO_DC_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLEZI_C"), aligned(_aligned_size)))
+#if defined(__MD95__) || defined(__MD97__) || defined(__MD97P__)
+
+/** C ALIGNED **/ /** Variables be declared without any specified will be default placed in .data or .bss section  **/
+#define __MCURW_HWRO_C_ALIGNED_RW(_aligned_size) \
+    __attribute__((section("CACHED_EXTSRAM_WT"), aligned(_aligned_size)))
+
+#define __MCURW_HWRO_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section("CACHED_EXTSRAM_WT_ZI"), aligned(_aligned_size)))
+
+/** C ALIGNED **/ /** Variables be declared without any specified will be default placed in .data or .bss section  **/
+#define __MCURW_HWRO_C_ALIGNED_RW_WB(_aligned_size) \
+    __attribute__((section(".data"), aligned(_aligned_size)))
+
+#define __MCURW_HWRO_C_ALIGNED_ZI_WB(_aligned_size) \
+    __attribute__((section(".bss"), aligned(_aligned_size)))
+
+#else
+/** C ALIGNED **/ /** Variables be declared without any specified will be default placed in .data or .bss section  **/
+#define __MCURW_HWRO_C_ALIGNED_RW(_aligned_size) \
+    __attribute__((section(".data"), aligned(_aligned_size)))
+
+#define __MCURW_HWRO_C_ALIGNED_ZI(_aligned_size) \
+    __attribute__((section(".bss"), aligned(_aligned_size)))
+#endif
+
+/* Per-Core Section *********************************/
+/* Core0 */
+/** DNC ALIGNED **/
+#define __PER_CORE_DNC_ALIGNED_RW_CORE0(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLERW_NC_CORE0"), aligned(_aligned_size)))
+
+#define __PER_CORE_DNC_ALIGNED_ZI_CORE0(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLEZI_NC_CORE0"), aligned(_aligned_size)))
+
+/** NC ALIGNED **/
+#define __PER_CORE_NC_ALIGNED_RW_CORE0(_aligned_size) \
+    __attribute__((section("NONCACHEDRW_CORE0"), aligned(_aligned_size)))
+
+#define __PER_CORE_NC_ALIGNED_ZI_CORE0(_aligned_size) \
+    __attribute__((section("NONCACHEDZI_CORE0"), aligned(_aligned_size)))
+
+/** DC ALIGNED **/
+#define __PER_CORE_DC_ALIGNED_RW_CORE0(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLERW_C_CORE0"), aligned(_aligned_size)))
+
+#define __PER_CORE_DC_ALIGNED_ZI_CORE0(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLEZI_C_CORE0"), aligned(_aligned_size)))
+
+/** C ALIGNED **/
+#define __PER_CORE_C_ALIGNED_RW_CORE0(_aligned_size) \
+    __attribute__((section("DATA_CORE0"), aligned(_aligned_size)))
+
+#define __PER_CORE_C_ALIGNED_ZI_CORE0(_aligned_size) \
+    __attribute__((section("BSS_CORE0"), aligned(_aligned_size)))
+
+
+/* Core1 */
+/** DNC ALIGNED **/
+#define __PER_CORE_DNC_ALIGNED_RW_CORE1(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLERW_NC_CORE1"), aligned(_aligned_size)))
+
+#define __PER_CORE_DNC_ALIGNED_ZI_CORE1(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLEZI_NC_CORE1"), aligned(_aligned_size)))
+
+/** NC ALIGNED **/
+#define __PER_CORE_NC_ALIGNED_RW_CORE1(_aligned_size) \
+    __attribute__((section("NONCACHEDRW_CORE1"), aligned(_aligned_size)))
+
+#define __PER_CORE_NC_ALIGNED_ZI_CORE1(_aligned_size) \
+    __attribute__((section("NONCACHEDZI_CORE1"), aligned(_aligned_size)))
+
+/** DC ALIGNED **/
+#define __PER_CORE_DC_ALIGNED_RW_CORE1(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLERW_C_CORE1"), aligned(_aligned_size)))
+
+#define __PER_CORE_DC_ALIGNED_ZI_CORE1(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLEZI_C_CORE1"), aligned(_aligned_size)))
+
+/** C ALIGNED **/
+#define __PER_CORE_C_ALIGNED_RW_CORE1(_aligned_size) \
+    __attribute__((section("DATA_CORE1"), aligned(_aligned_size)))
+
+#define __PER_CORE_C_ALIGNED_ZI_CORE1(_aligned_size) \
+    __attribute__((section("BSS_CORE1"), aligned(_aligned_size)))
+
+
+/* Core2 */
+/** DNC ALIGNED **/
+#define __PER_CORE_DNC_ALIGNED_RW_CORE2(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLERW_NC_CORE2"), aligned(_aligned_size)))
+
+/** NC ALIGNED **/
+#define __PER_CORE_NC_ALIGNED_RW_CORE2(_aligned_size) \
+    __attribute__((section("NONCACHEDRW_CORE2"), aligned(_aligned_size)))
+
+#define __PER_CORE_NC_ALIGNED_ZI_CORE2(_aligned_size) \
+    __attribute__((section("NONCACHEDZI_CORE2"), aligned(_aligned_size)))
+
+/** DC ALIGNED **/
+#define __PER_CORE_DC_ALIGNED_RW_CORE2(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLERW_C_CORE2"), aligned(_aligned_size)))
+
+#define __PER_CORE_DC_ALIGNED_ZI_CORE2(_aligned_size) \
+    __attribute__((section("DYNAMICCACHEABLEZI_C_CORE2"), aligned(_aligned_size)))
+
+/** C ALIGNED **/
+#define __PER_CORE_C_ALIGNED_RW_CORE2(_aligned_size) \
+    __attribute__((section("DATA_CORE2"), aligned(_aligned_size)))
+
+#define __PER_CORE_C_ALIGNED_ZI_CORE2(_aligned_size) \
+    __attribute__((section("BSS_CORE2"), aligned(_aligned_size)))
+
+/** C NOINIT ALIGNED **/
+#define __EXTSRAM_C_ALIGNED_NOINIT(_aligned_size) \
+    __attribute__ ((section("CACHED_EXTSRAM_NOINIT"), aligned(_aligned_size)))
+#endif
+
+#define DECLARE_SHARED_VAR(type, name) extern type name;
+#define DECLARE_SHARED_ARRAY(type, name, size) extern type name[size];
+
+#define SHARED_VAR(name) (name)
+#define SHARED_ARRAY(name) (name)
+#define SHARED_pVAR(name) (&name)
+#define SHARED_pARRAY(name) (&name)
+
+
+#endif /* _KAL_GENERAL_TYPES_H */
diff --git a/mcu/interface/service/kal/kal_general_types_MASE.h b/mcu/interface/service/kal/kal_general_types_MASE.h
new file mode 100644
index 0000000..0ce5f8f
--- /dev/null
+++ b/mcu/interface/service/kal/kal_general_types_MASE.h
@@ -0,0 +1,188 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   kal_general_types_MASE.h
+ *
+ * Project:
+ * --------
+ *   Maui_Software
+ *
+ * Description:
+ * ------------
+ *   This file provides alignment macros used on MASE platform on PC builds (MODIS HW COPRO).
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ *
+ *
+ ****************************************************************************/
+
+#ifndef _KAL_GENERAL_TYPES_MASE_H
+#define _KAL_GENERAL_TYPES_MASE_H
+
+#if !defined(__ESL_MASE_GEN97__)
+#error This file should be used in MASE only (MODIS HW COPRO build)
+#endif
+
+#undef __MCURO_HWRW_DNC_ALIGNED_NOINIT
+#undef __MCURO_HWRW_DC_ALIGNED_NOINIT
+#undef __MCURO_HWRW_NC_ALIGNED_NOINIT
+#undef __MCURO_HWRW_C_ALIGNED_NOINIT
+#undef __MCURW_HWRW_DNC_ALIGNED_RW
+#undef __MCURW_HWRW_DNC_ALIGNED_ZI
+#undef __MCURW_HWRW_DC_ALIGNED_RW
+#undef __MCURW_HWRW_DC_ALIGNED_ZI
+#undef __IOCU2_NON_ALLOC_MCURW_HWRW_C_ALIGNED_RW
+#undef __IOCU2_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_00_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_01_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_02_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_03_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_04_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_05_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_06_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_07_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_08_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_09_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_10_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_11_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_12_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_13_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_14_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU2_15_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_READ_ALLOC_MCURW_HWRW_C_ALIGNED_RW
+#undef __IOCU3_READ_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_RW
+#undef __IOCU3_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_00_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_01_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_02_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_03_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_04_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_05_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_06_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_07_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_08_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_09_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_10_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_11_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_12_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_13_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_14_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __IOCU3_15_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI
+#undef __MCURW_HWRO_DC_ALIGNED_RW
+#undef __MCURW_HWRO_DC_ALIGNED_ZI
+
+
+/*MCU-RO & HW-RW *********************************/
+/** DNC ALIGNED **/
+#define __MCURO_HWRW_DNC_ALIGNED_NOINIT(_aligned_size)  __declspec( align( _aligned_size ) )
+
+/** DC ALIGNED **/
+#define __MCURO_HWRW_DC_ALIGNED_NOINIT(_aligned_size)  __declspec( align( _aligned_size ) )
+
+/** NC ALIGNED **/
+#define __MCURO_HWRW_NC_ALIGNED_NOINIT(_aligned_size)  __declspec( align( _aligned_size ) )
+
+/** C ALIGNED **/
+#define __MCURO_HWRW_C_ALIGNED_NOINIT(_aligned_size)  __declspec( align( _aligned_size ) )
+
+/*MCU-RW & HW-RW *********************************/
+/** DNC ALIGNED **/
+#define __MCURW_HWRW_DNC_ALIGNED_RW(_aligned_size)  __declspec( align( _aligned_size ) )
+#define __MCURW_HWRW_DNC_ALIGNED_ZI(_aligned_size)  __declspec( align( _aligned_size ) )
+
+/** DC ALIGNED **/
+#define __MCURW_HWRW_DC_ALIGNED_RW(_aligned_size)  __declspec( align( _aligned_size ) )
+#define __MCURW_HWRW_DC_ALIGNED_ZI(_aligned_size)  __declspec( align( _aligned_size ) )
+
+/** IOCU **/
+#define __IOCU2_NON_ALLOC_MCURW_HWRW_C_ALIGNED_RW(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_00_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_01_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_02_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_03_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_04_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_05_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_06_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_07_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_08_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_09_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_10_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_11_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_12_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_13_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_14_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU2_15_NON_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_READ_ALLOC_MCURW_HWRW_C_ALIGNED_RW(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_READ_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_RW(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_00_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_01_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_02_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_03_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_04_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_05_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_06_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_07_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_08_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_09_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_10_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_11_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_12_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_13_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_14_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+#define __IOCU3_15_READ_WRITE_ALLOC_MCURW_HWRW_C_ALIGNED_ZI(_aligned_size) __declspec( align( _aligned_size ) )
+
+/** DC ALIGNED **/
+#define __MCURW_HWRO_DC_ALIGNED_RW(_aligned_size)  __declspec( align( _aligned_size ) )
+#define __MCURW_HWRO_DC_ALIGNED_ZI(_aligned_size)  __declspec( align( _aligned_size ) )
+
+#endif /* _KAL_GENERAL_TYPES_MASE_H */
diff --git a/mcu/interface/service/kal/kal_hrt_api.h b/mcu/interface/service/kal/kal_hrt_api.h
new file mode 100644
index 0000000..8e8aa1a
--- /dev/null
+++ b/mcu/interface/service/kal/kal_hrt_api.h
@@ -0,0 +1,496 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   kal_hrt_api.h
+ *
+ * Project:
+ * --------
+ *   Maui_Software
+ *
+ * Description:
+ * ------------
+ *   This file provides KAL Hard Realtime Domain API prototypes
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+****************************************************************************/
+
+#ifndef _KAL_HRT_API_H
+#define _KAL_HRT_API_H
+
+
+#include "kal_general_types.h"
+#include "kal_public_defs.h"
+#include "kal_hrt_defs.h"
+#include "kal_atomic_api.h"
+#include "kal_inline_api.h"
+#include "mips_ia_utils_public.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+
+/*******************************************************************************
+ * Category 1 : Only Used for HRT Domain
+ *              Normal Domain uses following APIs will fatal
+ ******************************************************************************/
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_tc_create_workqueue
+ * DESCRIPTION
+ *  create workqueue for LISR
+ * PARAMETERS
+ *  wq_name: [IN] name of workqueue variable
+ *  wq_size: [IN] size of workqueue
+ * RETURNS
+ *  N/A
+ ******************************************************************************/
+#define kal_hrt_tc_create_workqueue_isrc(wq_name, wq_size) HRT_CQUEUE(wq_name, wq_size)
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_register_mt_q
+ * DESCRIPTION
+ *  register workqueue for LISR
+ * PARAMETERS
+ *  irqvector: [IN] irq vector id
+ *  wq_id: [IN] KAL_Q0 for common queue (Only for Gen93)
+ *              KAL_Q1 for child workqueue of TC2
+ *              KAL_Q2 for child workqueue of TC3
+ *  wq: [IN] address of workqueue
+ * RETURNS
+ *  Failed: fatal error handling.
+ ******************************************************************************/
+void kal_hrt_register_mt_q_isrc(kal_uint32 irqvector, kal_workqueueid wq_id, void *wq);
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_tc_consume_work
+ * DESCRIPTION
+ *  Consume work from workqueue(s) until queue(s) are empty
+ *  ONLY parent TC (TC1) can consume work
+ * PARAMETERS
+ *  wq_mask: [IN] KAL_Q1_MASK for child workqueue of TC2
+ *                KAL_Q2_MASK for child workqueue of TC3
+ *                KAL_Q1_Q2_MASK
+ * RETURNS
+ *  Failed: fatal error handling.
+ ******************************************************************************/
+void kal_hrt_tc_consume_work(kal_workqueue_mask wq_mask);
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_tc_dispatch_work
+ * DESCRIPTION
+ *  dispatch work to workqueue
+ * PARAMETERS
+ *  wq_id: [IN] KAL_Q0 for common queue (Only for Gen93)
+ *              KAL_Q1 for child workqueue of TC2
+ *              KAL_Q2 for child workqueue of TC3
+ *  func_ptr: [IN] function pointer for TC executes
+ *  func_param: [IN] function parameter
+ * RETURNS
+ *  Failed: fatal error handling.
+ ******************************************************************************/
+void kal_hrt_tc_dispatch_work(kal_workqueueid wq_id, void *func_ptr,
+                              void *func_param);
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_tc_set_queue_nested_irq_shared
+ * DESCRIPTION
+ *  set work queue as shared for nesting interrupt
+ * PARAMETERS
+ *  wq_id: [IN] KAL_Q1 for child workqueue of TC2
+ *              KAL_Q2 for child workqueue of TC3
+ *  shared: [IN] shared or not shared
+ * RETURNS
+ *  Failed: fatal error handling.
+ * NOTE: If queue is not set back to not shared before IRQ returns, an assert is triggered
+ ******************************************************************************/
+void kal_hrt_tc_set_queue_nested_irq_shared(kal_workqueueid wq_id, kal_bool shared);
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_tc_dispatch_work
+ * DESCRIPTION
+ *  dispatch work to workqueue of irq currently nested
+ * PARAMETERS
+ *  wq_id: [IN] KAL_Q0 for common queue (Only for Gen93)
+ *              KAL_Q1 for child workqueue of TC2
+ *              KAL_Q2 for child workqueue of TC3
+ *  func_ptr: [IN] function pointer for TC executes
+ *  func_param: [IN] function parameter
+ *  irq_id: [IN] irq id of nested irq which queue to dispatch
+ * RETURNS
+ *  KAL_TRUE or KAL_FALSE
+ ******************************************************************************/
+kal_bool kal_hrt_tc_dispatch_work_nested_irq(kal_workqueueid wq_id, void *func_ptr,
+                                             void *func_param, kal_uint32 irq_id);
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_tc_checkpoint
+ * DESCRIPTION
+ *  check whether workqueues are empty, may be blocked or return directly
+ * PARAMETERS
+ *  wq_mask: [IN] KAL_Q0_MASK for common queue (Only for Gen93)
+ *                KAL_Q1_MASK for child workqueue of TC2
+ *                KAL_Q2_MASK for child workqueue of TC3
+ *                KAL_Q0_Q1_MASK (Only for Gen93)
+ *                KAL_Q0_Q2_MASK (Only for Gen93)
+ *                KAL_Q1_Q2_MASK
+ *                KAL_Q0_Q1_Q2_MASK (Only for Gen93)
+ *  timeout: [IN] KAL_NO_WAIT, KAL_INFINITE_WAIT
+ * RETURNS
+ *  [OUT] KAL_Q0_EXECUTE: common queue not finish (Only for Gen93)
+ *        KAL_Q1_EXECUTE: child workqueue of TC2 not finish
+ *        KAL_Q2_EXECUTE: child workqueue of TC3 not finish
+ *        KAL_Q0_Q1_EXECUTE: common queue and child workqueue of TC2 not finish (Only for Gen93)
+ *        KAL_Q0_Q2_EXECUTE: common queue and child workqueue of TC3 not finish (Only for Gen93)
+ *        KAL_Q1_Q2_EXECUTE: child workqueues of TC2/3 not finish
+ *        KAL_ALL_Q_FINISH: all queried workqueues are finish
+ *  Failed: fatal error handling.
+ ******************************************************************************/
+kal_uint32 kal_hrt_tc_checkpoint(kal_workqueue_mask wq_mask, kal_uint32 timeout);
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_activate_hisr_index
+ * DESCRIPTION
+ *  activate specified HISR for HRT domain LISR
+ * PARAMETERS
+ *  ext_hisr: [IN] HISR index.
+ * RETURNS
+ *  N/A
+ ******************************************************************************/
+#if defined(__MTK_TARGET__)
+extern void kal_hrt_activate_hisr_index(kal_hisr ext_hisr) DECLARE_MIPS16;
+#else
+extern void kal_hrt_activate_hisr_index(kal_hisr ext_hisr);
+#endif
+
+/*******************************************************************************
+ * Category 2 : Used for HRT and Normal Domain
+ *              Following APIs are designed for HRT Domain used.
+ *              Normal Domain uses them won't cause fatal.
+ ******************************************************************************/
+
+/*************************************************************************
+ * FUNCTION
+ *  kal_hrt_SaveAndSetIRQMask
+ * DESCRIPTION
+ *  This function disables IRQ and returnes the original IRQ setting
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  the original IRQ setting.
+ *************************************************************************/
+kal_uint32 kal_hrt_SaveAndSetIRQMask(void);
+
+/*************************************************************************
+ * FUNCTION
+ *  kal_hrt_RestoreIRQMask
+ * DESCRIPTION
+ *  This function restores IRQ without Qbit checking
+ * PARAMETERS
+ *  restored IRQ setting.
+ * RETURNS
+ *  N/A
+ *************************************************************************/
+void kal_hrt_RestoreIRQMask(kal_uint32 irq);
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_take_itc_lock
+ * DESCRIPTION
+ *  take kal itc lock based on itc id. Will mask interrupts
+ * PARAMETERS
+ *  itc_id: itc lock id to be taken
+ *  wait_mode: KAL_NO_WAIT or KAL_INFINITE_WAIT
+ * RETURNS
+ *  KAL_SUCCESS or KAL_ITC_NOT_AVAILABLE.
+ ******************************************************************************/
+kal_status kal_hrt_take_itc_lock(kal_itc_lock_id itc_id, kal_int32 wait_mode);
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_give_itc_lock
+ * DESCRIPTION
+ *  give kal itc lock based on itc id. Will restore interrupts based on old state
+ * PARAMETERS
+ *  itc_id: itc lock id to be given
+ * RETURNS
+ *  none
+ ******************************************************************************/
+void kal_hrt_give_itc_lock(kal_itc_lock_id itc_id);
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_rcu_create
+ * DESCRIPTION
+ *  create a RCU from the given memory pool
+ * PARAMETERS
+ *  buff_addr: [IN] the address of the memory pool.
+ *  allocated_buff_size: [IN] the size of the memory pool.
+ *  buff_size: [IN] the size of a block.
+ *  reserved: [IN] reserved, fill 0.
+ * RETURNS
+ *  Successful: the created RCU id.
+ *  Failed: fatal error handling.
+ ******************************************************************************/
+kalcc_rcuid kal_hrt_rcu_create(void *buff_addr, kal_uint32 allocated_buff_size,
+                               kal_uint32 buff_size, kal_uint32 reserved);
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_rcu_get_free_buff
+ * DESCRIPTION
+ *  get a free block for updating
+ * PARAMETERS
+ *  id: [IN] the target RCU id.
+ * RETURNS
+ *  Successful: the address of the free block.
+ *  Failed: fatal error handling.
+ ******************************************************************************/
+void *kal_hrt_rcu_get_free_buff(kalcc_rcuid id);
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_rcu_commit_data
+ * DESCRIPTION
+ *  mark this block as latest block ready for ready
+ * PARAMETERS
+ *  data: [IN] the address of the updated block.
+ * RETURNS
+ *  Successful: KAL_SUCCESS.
+ *  Failed: fatal error handling.
+ ******************************************************************************/
+kal_status kal_hrt_rcu_commit_data(void *data);
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_rcu_get_read_lock
+ * DESCRIPTION
+ *  get the latest updated block of the RCU
+ * PARAMETERS
+ *  id: [IN] the target RCU id.
+ * RETURNS
+ *  Successful: the address of the latest updated block.
+ *  Failed: fatal error handling.
+ ******************************************************************************/
+void *kal_hrt_rcu_get_read_lock(kalcc_rcuid id);
+
+/*******************************************************************************
+ * FUNCTION
+ *  kal_hrt_rcu_free_read_lock
+ * DESCRIPTION
+ *  free the block for writer to update
+ * PARAMETERS
+ *  data: [IN] the address of the block.
+ * RETURNS
+ *  Successful: KAL_SUCCESS.
+ *  Failed: fatal error handling.
+ ******************************************************************************/
+kal_status kal_hrt_rcu_free_read_lock(void *data);
+
+
+/*******************************************************************************
+ * Category 3 : Common with kal_public_api.h
+ ******************************************************************************/
+#if defined(KAL_ON_OSCAR)
+#define kal_snprintf _snprintf
+#else
+#define kal_snprintf snprintf
+#endif
+
+#define kal_sprintf sprintf
+extern kal_char *kal_strtok_r(kal_char *string, const kal_char *seperators,
+                              kal_char **ppLast);
+#define kal_toWCHAR(asciiString) L##asciiString
+extern char *kal_itoa(int value, char *str, int radix);
+
+extern int kal_wstrlen(const WCHAR *wstr);
+extern WCHAR *kal_wstrcpy(WCHAR *to, const WCHAR *from);
+extern WCHAR *kal_wstrncpy(WCHAR *to, const WCHAR *from, int n);
+extern int kal_wstrcmp(const WCHAR *s1, const WCHAR *s2);
+extern int kal_wstrncmp(const WCHAR *s1, const WCHAR *s2, int n);
+extern WCHAR *kal_wstrcat(WCHAR *s1, const WCHAR *s2);
+extern WCHAR *kal_wstrncat(WCHAR *s1, const WCHAR *s2, int n);
+extern WCHAR *kal_wstrchr(const WCHAR *s, int c);
+extern WCHAR *kal_wstrrchr(const WCHAR *str, int ch);
+
+extern int kal_dchar_strlen(const char *wstr);
+extern char *kal_dchar_strcpy(char *to, const char *from);
+extern char *kal_dchar_strncpy(char *to, const char *from, int n);
+extern int kal_dchar_strcmp(const char *s1, const char *s2);
+extern int kal_dchar_strncmp(const char *s1, const char *s2, int n);
+extern char *kal_dchar_strcat(char *s1, const char *s2);
+extern char *kal_dchar_strncat(char *s1, const char *s2, int n);
+extern char *kal_dchar_strchr(const char *s, int c);
+extern char *kal_dchar_strrchr(const char *str, int ch);
+extern void kal_dchar2char(WCHAR *outstr, char *tostr);
+extern void kal_wsprintf(WCHAR *outstr, char *fmt, ...);
+
+extern kal_bool   kal_query_systemInit(void);
+extern kal_uint32 kal_get_current_lisr_ID(void);
+
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_curent_domain
+ * DESCRIPTION
+ *  return current domain
+ * RETURNS
+ *  enum kal_domain: KAL_DOMAIN_NORMAL/KAL_DOMAIN_HRT/KAL_DOMAIN_CHRT
+ ******************************************************************************/
+#if defined(__MTK_TARGET__)
+#if !defined(__kal_get_current_domain__)
+#define __kal_get_current_domain__
+#if defined(__MIPS_I7200__)
+#define kal_get_current_domain() (miu_mfc0(MIU_C0_KSCRATCH4) & 0x3)
+#endif /* defined(__MIPS_I7200__) */
+#endif /* __kal_get_current_domain__ */
+#else  /* __MTK_TARGET__ */
+#define kal_get_current_domain() 0
+#endif /* __MTK_TARGET__ */
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_if_hrt_domain
+ * DESCRIPTION
+ *  Identify if current VPE is HRT domain
+ * PARAMETERS
+ *  VPE ID
+ * RETURNS
+ *  KAL_TRUE if current VPE is HRT domain
+ ******************************************************************************/
+#if !defined(__MTK_TARGET__)
+#define kal_get_domain(vpe_id) 0
+#define kal_if_hrt_domain(vpe_id) 0
+#endif /* __MTK_TARGET__ */
+
+extern kal_bool kal_if_hisr(void);
+
+#if defined(__MTK_TARGET__)
+#if !defined(__kal_if_lisr__)
+#define __kal_if_lisr__
+#define kal_if_lisr() (miu_mfc0(MIU_C0_USERLOCAL) > 0)
+#endif
+#else
+extern kal_bool kal_if_lisr(void);
+#endif
+
+/* NOTE: this is not public API. DO NOT use it outside kal */
+extern kal_bool kal_hrt_if_lisr_mt(void);
+
+extern kal_uint32 kal_get_systicks(void);
+extern kal_uint32 kal_secs_to_ticks(kal_uint32 secs);
+extern kal_uint32 kal_secs_to_ticks_real(kal_uint32 secs);
+extern kal_uint32 kal_milli_secs_to_ticks(kal_uint32 milli_secs);
+extern kal_uint32 kal_milli_secs_to_ticks_real(kal_uint32 milli_secs);
+extern kal_uint32 kal_ticks_to_secs(kal_uint32 ticks);
+extern kal_uint32 kal_ticks_to_secs_real(kal_uint32 ticks);
+extern kal_uint32 kal_ticks_to_milli_secs(kal_uint32 ticks);
+extern kal_uint32 kal_ticks_to_milli_secs_real(kal_uint32 ticks);
+
+#include "kal_ex_api.h"
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _KAL_HRT_API_H */
diff --git a/mcu/interface/service/kal/kal_hrt_defs.h b/mcu/interface/service/kal/kal_hrt_defs.h
new file mode 100644
index 0000000..98b4670
--- /dev/null
+++ b/mcu/interface/service/kal/kal_hrt_defs.h
@@ -0,0 +1,235 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   kal_hrt_defs.h
+ *
+ * Project:
+ * --------
+ *   Maui_Software
+ *
+ * Description:
+ * ------------
+ *   This file provides KAL Hard Realtime Domain definitions
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+#ifndef __KAL_HRT_DEFS_H__
+#define __KAL_HRT_DEFS_H__
+
+#if !defined(__PRODUCTION_RELEASE__)
+/* under construction !*/
+#endif /* __PRODUCTION_RELEASE__ */
+
+
+typedef struct kal_workqueue_node {
+    void *     func_ptr;
+    void *     func_param;
+    kal_uint16 func_index;
+//kal_uint8 reserved0;
+//kal_uint8 reserved1;
+#if defined(MT_FLOW_DEBUG)
+    kal_uint32 insert_timestamp;
+#endif /*MT_FLOW_DEBUG*/
+} kal_workqueue_node_t;
+
+#define MT_Q_HDR           \
+    kal_uint32 head;       \
+    kal_uint32 tail;       \
+    kal_uint32 total_item; \
+    kal_uint32 lock;       \
+    kal_bool   is_full;    \
+    kal_uint8  is_nested_irq_shared;
+
+typedef struct kal_workqueue_struct {
+    MT_Q_HDR
+    kal_workqueue_node_t queue[1];
+} kal_workqueue_struct;
+
+/* Circular queue definition for HRT domain */
+#define HRT_CQUEUE(_q, _length)              \
+    struct {                                 \
+        MT_Q_HDR                             \
+        kal_workqueue_node_t queue[_length]; \
+    } _q = {                                 \
+        .head                 = 0,           \
+        .tail                 = 0,           \
+        .total_item           = _length,     \
+        .lock                 = 0,           \
+        .is_full              = KAL_FALSE,   \
+        .is_nested_irq_shared = KAL_FALSE,   \
+    }
+#if defined(MT_FLOW_DEBUG)
+#define HRT_CQUEUE_INSERT(_q, _item)                     \
+    do {                                                 \
+        _item.insert_timestamp = ust_get_current_time(); \
+        (_q).queue[(_q).tail]  = _item;                  \
+        (_q).tail++;                                     \
+        if ((_q).tail == (_q).total_item)                \
+            (_q).tail = 0;                               \
+        if ((_q).head == (_q).tail)                      \
+            (_q).is_full = KAL_TRUE;                     \
+    } while (0)
+#else
+#define HRT_CQUEUE_INSERT(_q, _item)      \
+    do {                                  \
+        (_q).queue[(_q).tail] = _item;    \
+        (_q).tail++;                      \
+        if ((_q).tail == (_q).total_item) \
+            (_q).tail = 0;                \
+        if ((_q).head == (_q).tail)       \
+            (_q).is_full = KAL_TRUE;      \
+    } while (0)
+#endif
+#define HRT_CQUEUE_DISCARD(_q)            \
+    do {                                  \
+        (_q).head++;                      \
+        if ((_q).head == (_q).total_item) \
+            (_q).head = 0;                \
+        if ((_q).is_full == KAL_TRUE)     \
+            (_q).is_full = KAL_FALSE;     \
+    } while (0)
+
+#define HRT_CQUEUE_IS_FULL(_q) ((_q).is_full)
+#define HRT_CQUEUE_IS_EMPTY(_q) (((_q).head == (_q).tail) && !(_q).is_full)
+
+#if defined(__MD97__) || defined(__MD97P__)
+/* 3 vpes/core, each vpe has 1 child tc*/
+#define MT_TCID_TO_WQID(tcid) 0
+/* only parent tc can call this */
+#define MT_WQID_TO_TCID(wqid) (miu_get_current_tc_id() + wqid + 1)
+#else
+#error no MT config yet
+#endif
+
+#define HRT_MT_SHARED_Q KAL_Q_MAX
+
+/* LISR multi-threading structure */
+#define LISR_MT_MAGIC_ID 0x454E4D54 // ENMT
+
+typedef struct {
+    kal_uint32            magic_id;
+    kal_uint32            wait;
+    kal_workqueue_struct *wq[KAL_Q_MAX];
+} kal_lisr_mt;
+
+typedef struct {
+    void *mt_stack_ptr[KAL_Q_MAX];
+} kal_mt_stack_ptr;
+
+#endif /* __KAL_HRT_DEFS_H__  */
diff --git a/mcu/interface/service/kal/kal_inline_api.h b/mcu/interface/service/kal/kal_inline_api.h
new file mode 100644
index 0000000..8a05043
--- /dev/null
+++ b/mcu/interface/service/kal/kal_inline_api.h
@@ -0,0 +1,150 @@
+#ifndef _KAL_INLINE_API_H
+#define _KAL_INLINE_API_H
+
+#include "kal_general_types.h"
+#include "mips_ia_utils_public.h"
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_query_boot_mode
+ * DESCRIPTION
+ *  query system boot mode.
+ * PARAMETERS
+ *  N/A
+ * SEE ALSO
+ *  boot_mode_type
+ ******************************************************************************/
+INLINE_MODIFIER INLINE INLINE_ALWAYS boot_mode_type kal_query_boot_mode(void)
+{
+    extern boot_mode_type system_boot_mode;
+    return system_boot_mode;
+}
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_set_boot_mode
+ * DESCRIPTION
+ *  set system boot mode (for Seamless META Switch)
+ * PARAMETERS
+ *  boot_mode_type 
+ * SEE ALSO
+ *  boot_mode_type
+ ******************************************************************************/
+INLINE_MODIFIER INLINE INLINE_ALWAYS void kal_set_boot_mode(boot_mode_type boot_mode)
+{
+    extern boot_mode_type system_boot_mode;
+    system_boot_mode = boot_mode;
+}
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_current_core_id
+ * DESCRIPTION
+ *  get current executed CORE ID
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  current executed CORE ID: 0 ~ 3.
+ ******************************************************************************/
+INLINE INLINE_ALWAYS static kal_uint32 kal_get_current_core_id(void)
+{
+#if defined(__MTK_TARGET__)
+    kal_uint32 cpu_id = 0;
+
+    cpu_id = miu_get_current_core_id();
+
+    return cpu_id;
+#else
+    return 0;
+#endif
+}
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_current_vpe_id
+ * DESCRIPTION
+ *  get current executed VPE ID
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  current executed VPE ID: 0 ~ 7.
+ ******************************************************************************/
+INLINE INLINE_ALWAYS static kal_uint32 kal_get_current_vpe_id(void)
+{
+
+#if defined(__MTK_TARGET__)
+    kal_uint32 cpu_id = 0;
+
+    cpu_id = miu_get_current_vpe_id();
+
+    return cpu_id;
+#else
+    return 0;
+#endif
+}
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_current_tc_id
+ * DESCRIPTION
+ *  get current executed TC ID
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  current executed TC ID: 0 ~ 3.
+ ******************************************************************************/
+INLINE INLINE_ALWAYS static kal_uint32 kal_get_current_tc_id(void)
+{
+#if defined(__MTK_TARGET__)
+    kal_uint32 tc_id = 0;
+
+    tc_id = miu_get_current_tc_id();
+
+    return tc_id;
+#else
+    return 0;
+#endif
+}
+
+/*******************************************************************************
+ * Category 1 : StdLib-like Function
+ *******************************************************************************/
+INLINE_MODIFIER INLINE INLINE_ALWAYS void *kal_mem_cpy(void *dest, const void *src,
+                                         kal_uint32 size)
+{
+    return memcpy(dest, src, size);
+}
+
+INLINE_MODIFIER INLINE INLINE_ALWAYS void *kal_mem_set(void *dest, kal_int32 value,
+                                         kal_uint32 size)
+{
+    return memset(dest, value, size);
+}
+
+INLINE_MODIFIER INLINE INLINE_ALWAYS kal_int32 kal_mem_cmp(const void *src1, const void *src2,
+                                             kal_uint32 size)
+{
+    return memcmp(src1, src2, size);
+}
+
+INLINE_MODIFIER INLINE INLINE_ALWAYS void *kal_mem_bwcpy(void *dest, const void *src,
+                                           kal_uint32 size)
+{
+    char *      destaddr = (char *)dest + (size - 1);
+    char const *srcaddr  = (char *)src + (size - 1);
+    while (size-- > 0)
+        *destaddr-- = *srcaddr--;
+    return destaddr;
+}
+
+#endif
diff --git a/mcu/interface/service/kal/kal_iram_section_defs.h b/mcu/interface/service/kal/kal_iram_section_defs.h
new file mode 100644
index 0000000..366b24b
--- /dev/null
+++ b/mcu/interface/service/kal/kal_iram_section_defs.h
@@ -0,0 +1,252 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   kal_iram_section_defs.h
+ *
+ * Project:
+ * --------
+ *   Maui_Software
+ *
+ * Description:
+ * ------------
+ *   This header file is used to define MACROs for placing data to a dedicated section
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+#ifndef __KAL_INTERNAL_RAM_DEFINATIONS__
+#define __KAL_INTERNAL_RAM_DEFINATIONS__
+
+#include "kal_general_types.h"
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1500)
+/** SPRAM **/
+    /* Core0 */
+    #define __ISPRAM_ROCODE_CORE0 
+    #define __DSPRAM_RODATA_ALIGNED_CORE0(_aligned_size)           
+    #define __DSPRAM_RW_ALIGNED_CORE0(_aligned_size)      
+    #define __DSPRAM_ZI_ALIGNED_CORE0(_aligned_size)      
+    /* Core1 */
+    #define __ISPRAM_ROCODE_CORE1 
+    #define __DSPRAM_RODATA_ALIGNED_CORE1(_aligned_size)           
+    #define __DSPRAM_RW_ALIGNED_CORE1(_aligned_size)      
+    #define __DSPRAM_ZI_ALIGNED_CORE1(_aligned_size)      
+    /* Core2 */
+    #define __ISPRAM_ROCODE_CORE2 
+    #define __DSPRAM_RODATA_ALIGNED_CORE2(_aligned_size)           
+    #define __DSPRAM_RW_ALIGNED_CORE2(_aligned_size)      
+    #define __DSPRAM_ZI_ALIGNED_CORE2(_aligned_size)      
+   
+/** L2SRAM **/
+    /* L2 cached */
+    #define __L2SRAM_L2CACHED_ROCODE
+    #define __L2SRAM_L2CACHED_ALIGNED_RODATA(_aligned_size)       
+    #define __L2SRAM_L2CACHED_ALIGNED_RW(_aligned_size)           
+    #define __L2SRAM_L2CACHED_ALIGNED_ZI(_aligned_size)           
+
+    /* L2 Non-cached */
+    #define __L2SRAM_L2_NON_CACHED_ROCODE
+    #define __L2SRAM_L2_NON_CACHED_ALIGNED_RODATA(_aligned_size)           
+    #define __L2SRAM_L2_NON_CACHED_ALIGNED_RW(_aligned_size)          
+    #define __L2SRAM_L2_NON_CACHED_ALIGNED_ZI(_aligned_size)      
+
+/* L2CACHE LOCK (MCU-RW & HW-RW) *********************************/
+    /** C ALIGNED **/
+    #define __MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_ROCODE    
+    #define __MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_ROCODE_MIPS32
+    #define __MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_ROCODE_NO_ATTRIBUTE
+    #define __MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_RODATA(_aligned_size)          
+    #define __MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_RW(_aligned_size)     
+    #define __MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_ZI(_aligned_size)      
+
+
+#elif defined(__GNUC__) /* end of defined(_MSC_VER) && (_MSC_VER >= 1500) */
+
+
+/** SPRAM **/
+    /* Core0 */
+    #define __ISPRAM_ROCODE_CORE0 \
+        __attribute__ ((section("ISPRAM_ROCODE_CORE0"))) __attribute__((code_readable ("no")))
+    
+    #define __DSPRAM_RODATA_ALIGNED_CORE0(_aligned_size) \
+        __attribute__ ((section("DSPRAM_RODATA_CORE0"), aligned(_aligned_size)))
+         
+    #define __DSPRAM_RW_ALIGNED_CORE0(_aligned_size) \
+        __attribute__ ((section("DSPRAM_RW_CORE0"), aligned(_aligned_size)))
+
+    #define __DSPRAM_ZI_ALIGNED_CORE0(_aligned_size) \
+        __attribute__ ((section("DSPRAM_ZI_CORE0"), aligned(_aligned_size)))
+        
+    /* Core1 */
+    #define __ISPRAM_ROCODE_CORE1 \
+        __attribute__ ((section("ISPRAM_ROCODE_CORE1"))) __attribute__((code_readable ("no")))
+    
+    #define __DSPRAM_RODATA_ALIGNED_CORE1(_aligned_size) \
+        __attribute__ ((section("DSPRAM_RODATA_CORE1"), aligned(_aligned_size)))
+         
+    #define __DSPRAM_RW_ALIGNED_CORE1(_aligned_size) \
+        __attribute__ ((section("DSPRAM_RW_CORE1"), aligned(_aligned_size)))
+    
+    #define __DSPRAM_ZI_ALIGNED_CORE1(_aligned_size) \
+        __attribute__ ((section("DSPRAM_ZI_CORE1"), aligned(_aligned_size)))
+            
+    /* Core2 */
+    #define __ISPRAM_ROCODE_CORE2    
+
+    #define __DSPRAM_RODATA_ALIGNED_CORE2(_aligned_size) \
+        __attribute__ ((aligned(_aligned_size)))         
+
+    #define __DSPRAM_RW_ALIGNED_CORE2(_aligned_size) \
+        __attribute__ ((aligned(_aligned_size)))
+    
+    #define __DSPRAM_ZI_ALIGNED_CORE2(_aligned_size) \
+        __attribute__ ((aligned(_aligned_size)))
+
+    
+/** L2SRAM **/
+    /* L2 cached */
+    #define __L2SRAM_L2CACHED_ROCODE
+    
+    #define __L2SRAM_L2CACHED_ALIGNED_RODATA(_aligned_size) \
+        __attribute__ ((aligned(_aligned_size)))
+         
+    #define __L2SRAM_L2CACHED_ALIGNED_RW(_aligned_size) \
+        __attribute__ ((aligned(_aligned_size)))
+    
+    #define __L2SRAM_L2CACHED_ALIGNED_ZI(_aligned_size) \
+        __attribute__ ((aligned(_aligned_size)))
+
+    /* L2 Non-cached */
+    #define __L2SRAM_L2_NON_CACHED_ROCODE
+    
+    #define __L2SRAM_L2_NON_CACHED_ALIGNED_RODATA(_aligned_size) \
+        __attribute__ ((aligned(_aligned_size)))
+         
+    #define __L2SRAM_L2_NON_CACHED_ALIGNED_RW(_aligned_size) \
+        __attribute__ ((aligned(_aligned_size)))
+    
+    #define __L2SRAM_L2_NON_CACHED_ALIGNED_ZI(_aligned_size) \
+        __attribute__ ((aligned(_aligned_size)))
+
+
+
+/* L2CACHE LOCK (MCU-RW & HW-RW) *********************************/
+    /** C ALIGNED **/
+#if !defined(__MD95__) /*Remove static L2C lock section on Gen95*/
+
+    #define __MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_ROCODE \
+        __attribute__ ((section("L2CACHE_LOCK_ROCODE"))) DECLARE_MIPS16
+
+    #define __MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_ROCODE_MIPS32 \
+        __attribute__ ((section("L2CACHE_LOCK_ROCODE"))) DECLARE_MIPS32
+    
+    #define __MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_ROCODE_NO_ATTRIBUTE \
+        __attribute__ ((section("L2CACHE_LOCK_ROCODE")))
+    
+    #define __MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_RODATA(_aligned_size) \
+        __attribute__ ((section("L2CACHE_LOCK_RODATA"), aligned(_aligned_size)))
+         
+    #define __MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_RW(_aligned_size) \
+        __attribute__ ((section("L2CACHE_LOCK_RW"), aligned(_aligned_size)))
+
+    #define __MCURW_HWRW_C_ALIGNED_L2CACHE_LOCK_ZI(_aligned_size) \
+        __attribute__ ((section("L2CACHE_LOCK_ZI"), aligned(_aligned_size)))
+
+#endif /*!__MD95__*/
+#endif
+
+
+#endif /* __KAL_INTERNAL_RAM_DEFINATIONS__  */
diff --git a/mcu/interface/service/kal/kal_itc.h b/mcu/interface/service/kal/kal_itc.h
new file mode 100644
index 0000000..c985ad0
--- /dev/null
+++ b/mcu/interface/service/kal/kal_itc.h
@@ -0,0 +1,1078 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2018
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   kal_itc.h
+ *
+ * Project:
+ * --------
+ *   UMOLYE
+ *
+ * Description:
+ * ------------
+ *   This file provides KAL ITC related APIs
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ *
+****************************************************************************/
+
+#ifndef _KAL_ITC_H
+#define _KAL_ITC_H
+
+/*******************************************************************************
+ * Include Statements
+ *******************************************************************************/
+#include "kal_general_types.h"
+#include "kal_public_defs.h"
+
+/*******************************************************************************
+ * Definitions and macros
+ *******************************************************************************/
+#ifdef __MTK_TARGET__
+#define KAL_SPINLOCK_CREATEDLIST
+#endif
+
+#ifndef HW_ITC_GRP
+#if defined(__MD93__)
+#define KAL_ITC_GRP 3         /* Context takes ITC */
+#elif defined(__MD95__)
+#define KAL_ITC_GRP 3         /* Context takes ITC */
+#elif defined(__MD97__)
+#define KAL_ITC_GRP 2         /* Context takes ITC, or Critical HRT LISR */
+#elif defined(__MD97P__)
+#define KAL_ITC_GRP 2         /* For now, MD97P defs same as in MD97 */
+#else
+#warning "unknown MDMCU version"
+#endif
+#else
+#define KAL_ITC_GRP HW_ITC_GRP  /* Context takes ITC */
+#endif
+
+#define KAL_ITC_MAX_NAME (8)
+#define KAL_SPIN_LOCK_ID 0x53504c4bUL
+
+/* Select correct DI API to use based on the current domain and VPE */
+#define KAL_ITC_DI(ret_addr, is_hrt)                              \
+    ({                                                            \
+        kal_int32 _irq_state;                                     \
+        if (is_hrt == KAL_TRUE) {                                 \
+            _irq_state = kal_hrt_SaveAndSetIRQMask_ITC(ret_addr); \
+        } else {                                                  \
+            _irq_state = SaveAndSetIRQMask();                     \
+        }                                                         \
+        _irq_state;                                               \
+    })
+
+/* Select correct EI API to use based on the current context and VPE */
+#define KAL_ITC_EI(irq_state, ret_addr, is_hrt)              \
+    do {                                                     \
+        if (is_hrt == KAL_TRUE) {                            \
+            kal_hrt_RestoreIRQMask_ITC(irq_state, ret_addr); \
+        } else {                                             \
+            RestoreIRQMask(irq_state);                       \
+        }                                                    \
+    } while (0)
+
+/* Primitive macro for taking the lock, return only after getting the lock */
+#if defined(__mips16) || defined(__nanomips__)
+#define KAL_ITC_LOCK_TAKE(lock)                         \
+    ({                                                  \
+        kal_status _ret = 0;                            \
+        __asm__ __volatile__(                           \
+            "1: ll      %1, %2;"                        \
+            "   beqz    %1, 2f;"                        \
+            "   pause;"                                 \
+            "   b       1b;"                            \
+            "2: li      %1, 1;"                         \
+            "   sc      %1, %0;"                        \
+            "   beqz    %1, 1b;"                        \
+            : "=ZC"(lock), "+d"(_ret)                   \
+            : "ZC"(lock)                                \
+            : "memory");                                \
+        _ret;                                           \
+    })
+#else
+#define KAL_ITC_LOCK_TAKE(lock)                         \
+    ({                                                  \
+        kal_status _ret = 0;                            \
+        __asm__ __volatile__(                           \
+            "   .set    push;"                          \
+            "   .set    noreorder;"                     \
+            "1: ll      %1, %2;"                        \
+            "   beqz    %1, 2f;"                        \
+            "   li      %1, 1;"                         \
+            "   pause;"                                 \
+            "   b       1b;"                            \
+            "   nop;"                                   \
+            "2: sc      %1, %0;"                        \
+            "   beqz    %1, 1b;"                        \
+            "   nop;"                                   \
+            "   .set    pop;"                           \
+            : "=ZC"(lock), "+d"(_ret)                   \
+            : "ZC"(lock)                                \
+            : "memory");                                \
+        _ret;                                           \
+    })
+#endif
+
+/* Primitive macro for taking the lock, return only after getting the lock, 
+ * does disable interrupts. 
+ * Old irq status saved in irq_mask */
+#if defined(__mips16) || defined(__nanomips__)
+#define KAL_ITC_LOCK_TAKE_DI(lock, irq_mask)                          \
+    ({                                                                \
+        kal_status _ret = 0;                                          \
+        __asm__ __volatile__(                                         \
+            "   di      %2;"                                          \
+            "   ehb;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                \
+            "1: ll      %1, %3;"                                      \
+            "   beqz    %1, 3f;"                                      \
+            "   beqz    %2, 2f;"                                      \
+            "   ei;"                                                  \
+            "2: pause;"                                               \
+            "   di      %2;"                                          \
+            "   ehb;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                \
+            "   b       1b;"                                          \
+            "3: li      %1, 1;"                                       \
+            "   sc      %1, %0;"                                      \
+            "   beqz    %1, 1b;"                                      \
+            : "=ZC"(lock), "+d"(_ret), "+d"(irq_mask)                 \
+            : "ZC"(lock)                                              \
+            : "memory");                                              \
+        _ret;                                                         \
+    })
+#else
+#define KAL_ITC_LOCK_TAKE_DI(lock, irq_mask)                          \
+    ({                                                                \
+        kal_status _ret = 0;                                          \
+        __asm__ __volatile__(                                         \
+            "   .set    push;"                                        \
+            "   .set    noreorder;"                                   \
+            "   di      %2;"                                          \
+            "   ehb;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                \
+            "1: ll      %1, %3;"                                      \
+            "   beqz    %1, 3f;"                                      \
+            "   li      %1, 1;"                                       \
+            "   beqz    %2, 2f;"                                      \
+            "   nop;"                                                 \
+            "   ei;"                                                  \
+            "2: pause;"                                               \
+            "   di      %2;"                                          \
+            "   ehb;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                \
+            "   b       1b;"                                          \
+            "   nop;"                                                 \
+            "3: sc      %1, %0;"                                      \
+            "   beqz    %1, 1b;"                                      \
+            "   nop;"                                                 \
+            "   .set    pop;"                                         \
+            : "=ZC"(lock), "+d"(_ret), "+d"(irq_mask)                 \
+            : "ZC"(lock)                                              \
+            : "memory");                                              \
+        _ret;                                                         \
+    })
+#endif
+
+/* Primitive macro for trying the lock, return success or fail */
+#if defined(__mips16) || defined(__nanomips__)
+#define KAL_ITC_LOCK_TRY(lock)                          \
+    ({                                                  \
+        kal_status _ret = 0;                            \
+        __asm__ __volatile__(                           \
+            "   ll      %1, %2;"                        \
+            "   bnez    %1, 1f;"                        \
+            "   li      %1, 1;"                         \
+            "   sc      %1, %0;"                        \
+            "   b       2f;"                            \
+            "1: li      %1, 0;"                         \
+            "2: ;"                                      \
+            : "=ZC"(lock), "+d"(_ret)                   \
+            : "ZC"(lock)                                \
+            : "memory");                                \
+        _ret = _ret != 0 ? KAL_SUCCESS : KAL_ERROR;     \
+        _ret;                                           \
+    })
+#else
+#define KAL_ITC_LOCK_TRY(lock)                          \
+    ({                                                  \
+        kal_status _ret = 0;                            \
+        __asm__ __volatile__(                           \
+            "   .set    push;"                          \
+            "   .set    noreorder;"                     \
+            "   ll      %1, %2;"                        \
+            "   bnez    %1, 1f;"                        \
+            "   li      %1, 0;"                         \
+            "   li      %1, 1;"                         \
+            "   sc      %1, %0;"                        \
+            "1: ;"                                      \
+            "   .set    pop;"                           \
+            : "=ZC"(lock), "+d"(_ret)                   \
+            : "ZC"(lock)                                \
+            : "memory");                                \
+        _ret = _ret != 0 ? KAL_SUCCESS : KAL_ERROR;     \
+        _ret;                                           \
+    })
+#endif
+
+/* Primitive macro for trying the lock, return success or fail,
+ * does disable interrupts if success. 
+ * Old irq status saved in irq_mask */
+#if defined(__mips16) || defined(__nanomips__)
+#define KAL_ITC_LOCK_TRY_DI(lock, irq_mask)                     \
+    ({                                                          \
+        kal_status _ret = 0;                                    \
+        __asm__ __volatile__(                                   \
+            "   di      %2;"                                    \
+            "   ehb;"                                           \
+            "   ext     %2, %2, 0, 1;"                          \
+            "   ll      %1, %3;"                                \
+            "   bnez    %1, 1f;"                                \
+            "   li      %1, 1;"                                 \
+            "   sc      %1, %0;"                                \
+            "   b       2f;"                                    \
+            "1: li      %1, 0;"                                 \
+            "2: ;"                                              \
+            : "=ZC"(lock), "+d"(_ret), "+d"(irq_mask)           \
+            : "ZC"(lock)                                        \
+            : "memory");                                        \
+        if (_ret != 0) {                                        \
+            _ret = KAL_SUCCESS;                                 \
+        } else {                                                \
+            _ret = KAL_ERROR;                                   \
+            if (irq_mask != 0) {                                \
+                __asm__ __volatile__("ei; ehb;" ::: "memory");  \
+            }                                                   \
+        }                                                       \
+        _ret;                                                   \
+    })
+#else
+#define KAL_ITC_LOCK_TRY_DI(lock, irq_mask)                     \
+    ({                                                          \
+        kal_status _ret = 0;                                    \
+        __asm__ __volatile__(                                   \
+            "   .set    push;"                                  \
+            "   .set    noreorder;"                             \
+            "   di      %2;"                                    \
+            "   ehb;"                                           \
+            "   ext     %2, %2, 0, 1;"                          \
+            "   ll      %1, %3;"                                \
+            "   bnez    %1, 1f;"                                \
+            "   li      %1, 0;"                                 \
+            "   li      %1, 1;"                                 \
+            "   sc      %1, %0;"                                \
+            "1: ;"                                              \
+            "   .set    pop;"                                   \
+            : "=ZC"(lock), "+d"(_ret), "+d"(irq_mask)           \
+            : "ZC"(lock)                                        \
+            : "memory");                                        \
+        if (_ret != 0) {                                        \
+            _ret = KAL_SUCCESS;                                 \
+        } else {                                                \
+            _ret = KAL_ERROR;                                   \
+            if (irq_mask != 0) {                                \
+                __asm__ __volatile__("ei; ehb;" ::: "memory");  \
+            }                                                   \
+        }                                                       \
+        _ret;                                                   \
+    })
+#endif
+
+/* Primitive macro for taking the lock, return only after getting the lock, 
+ * does disable interrupts and disable MT. 
+ * Old irq status saved in irq_mask, old MT status saved in mt_mask */
+#if defined(__mips16) || defined(__nanomips__)
+#define KAL_ITC_LOCK_TAKE_DI_DMT(lock, irq_mask, mt_mask)                               \
+    ({                                                                                  \
+        kal_status _ret = 0;                                                            \
+        __asm__ __volatile__(                                                           \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "1: ll      %1, %4;"                                                        \
+            "   beqz    %1, 4f;"                                                        \
+            "   beqz    %2, 2f;"                                                        \
+            "   ei;"                                                                    \
+            "2: beqz    %3, 3f;"                                                        \
+            "   emt;"                                                                   \
+            "   ehb;"                                                                   \
+            "3: pause;"                                                                 \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "   b       1b;"                                                            \
+            "4: li      %1, 1;"                                                         \
+            "   sc      %1, %0;"                                                        \
+            "   beqz    %1, 1b;"                                                        \
+            : "=ZC" (lock), "+d" (_ret), "+d" (irq_mask), "+d" (mt_mask)                \
+            : "ZC" (lock)                                                               \
+            : "memory"                                                                  \
+        );                                                                              \
+        _ret;                                                                           \
+    })
+#else
+#define KAL_ITC_LOCK_TAKE_DI_DMT(lock, irq_mask, mt_mask)                               \
+    ({                                                                                  \
+        kal_status _ret = 0;                                                            \
+        __asm__ __volatile__(                                                           \
+            "   .set    push;"                                                          \
+            "   .set    noreorder;"                                                     \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "1: ll      %1, %4;"                                                        \
+            "   beqz    %1, 4f;"                                                        \
+            "   li      %1, 1;"                                                         \
+            "   beqz    %2, 2f;"                                                        \
+            "   nop;"                                                                   \
+            "   ei;"                                                                    \
+            "2: beqz    %2, 3f;"                                                        \
+            "   nop;"                                                                   \
+            "   emt;"                                                                   \
+            "   ehb;"                                                                   \
+            "3: pause;"                                                                 \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "   b       1b;"                                                            \
+            "   nop;"                                                                   \
+            "4: sc      %1, %0;"                                                        \
+            "   beqz    %1, 1b;"                                                        \
+            "   nop;"                                                                   \
+            "   .set    pop;"                                                           \
+            : "=ZC" (lock), "+d" (_ret), "+d" (irq_mask), "+d" (mt_mask)                \
+            : "ZC" (lock)                                                               \
+            : "memory"                                                                  \
+        );                                                                              \
+        _ret;                                                                           \
+    })
+#endif
+
+/* Primitive macro for trying the lock, return success or fail,
+ * does disable interrupts and MT if success. 
+ * Old irq status saved in irq_mask, old MT status saved in mt_mask */
+#if defined(__mips16) || defined(__nanomips__)
+#define KAL_ITC_LOCK_TRY_DI_DMT(lock, irq_maski, mt_mask)                               \
+    ({                                                                                  \
+        kal_status _ret = 0;                                                            \
+        __asm__ __volatile__(                                                           \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "   ll      %1, %4;"                                                        \
+            "   bnez    %1, 1f;"                                                        \
+            "   li      %1, 1;"                                                         \
+            "   sc      %1, %0;"                                                        \
+            "   b       2f;"                                                            \
+            "1: li      %1, 0;"                                                         \
+            "2: ;"                                                                      \
+            : "=ZC" (lock), "+d" (_ret), "+d" (irq_mask), "+d" (mt_mask)                \
+            : "ZC" (lock)                                                               \
+            : "memory"                                                                  \
+        );                                                                              \
+        if (_ret != 0) {                                                                \
+            _ret = KAL_SUCCESS;                                                         \
+        } else {                                                                        \
+            _ret = KAL_ERROR;                                                           \
+            if (irq_mask != 0) {                                                        \
+                __asm__ __volatile__("ei; ehb;":::"memory");                            \
+            }                                                                           \
+            if (mt_mask != 0) {                                                         \
+                __asm__ __volatile__("emt; ehb;":::"memory");                           \
+            }                                                                           \
+        }                                                                               \
+        _ret;                                                                           \
+    })
+#else
+#define KAL_ITC_LOCK_TRY_DI_DMT(lock, irq_mask, mt_mask)                                \
+    ({                                                                                  \
+        kal_status _ret = 0;                                                            \
+        __asm__ __volatile__(                                                           \
+            "   .set    push;"                                                          \
+            "   .set    noreorder;"                                                     \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "   ll      %1, %4;"                                                        \
+            "   bnez    %1, 1f;"                                                        \
+            "   li      %1, 0;"                                                         \
+            "   li      %1, 1;"                                                         \
+            "   sc      %1, %0;"                                                        \
+            "1: ;"                                                                      \
+            "   .set    pop;"                                                           \
+            : "=ZC" (lock), "+d" (_ret), "+d" (irq_mask), "+d" (mt_mask)                \
+            : "ZC" (lock)                                                               \
+            : "memory"                                                                  \
+        );                                                                              \
+        if (_ret != 0) {                                                                \
+            _ret = KAL_SUCCESS;                                                         \
+        } else {                                                                        \
+            _ret = KAL_ERROR;                                                           \
+            if (irq_mask != 0) {                                                        \
+                __asm__ __volatile__("ei; ehb;":::"memory");                            \
+            }                                                                           \
+            if (mt_mask != 0) {                                                         \
+                __asm__ __volatile__("emt; ehb;":::"memory");                           \
+            }                                                                           \
+        }                                                                               \
+        _ret;                                                                           \
+    })
+#endif
+
+/* Primitive macro for taking the lock, return only after getting the lock, 
+ * does disable interrupts, disable MT, and raise prio to HW_ITC_GRP. 
+ * Old irq status saved in irq_mask, old MT status saved in mt_mask,
+ * old prio saved in prio. */
+#if defined(__nanomips__)
+#define KAL_ITC_LOCK_TAKE_DI_DMT_PRIO(lock, irq_mask, mt_mask, prio)                    \
+    ({                                                                                  \
+        kal_status _ret = 0;                                                            \
+        kal_uint32 _new_prio = KAL_ITC_GRP;                                             \
+        __asm__ __volatile__(                                                           \
+            "   mfc0    %4, $2, 6;"                                                     \
+            "   move    %1, %4;"                                                        \
+            "   ins     %1, %6, 2, 2;"                                                  \
+            "   ext     %4, %4, 2, 2;"                                                  \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   mtc0    %1, $2, 6;"                                                     \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "1: ll      %1, %5;"                                                        \
+            "   beqz    %1, 4f;"                                                        \
+            "   beqz    %2, 2f;"                                                        \
+            "   ei;"                                                                    \
+            "   ehb;"                                                                   \
+            "2: beqz    %3, 3f;"                                                        \
+            "   emt;"                                                                   \
+            "   ehb;"                                                                   \
+            "3: pause;"                                                                 \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "   b       1b;"                                                            \
+            "4: li      %1, 1;"                                                         \
+            "   sc      %1, %0;"                                                        \
+            "   beqz    %1, 1b;"                                                        \
+            : "=ZC" (lock), "+d" (_ret), "+d" (irq_mask), "+d" (mt_mask), "+d" (prio)   \
+            : "ZC" (lock), "d" (_new_prio)                                              \
+            : "memory"                                                                  \
+        );                                                                              \
+        _ret;                                                                           \
+    })
+#elif defined(__mips16)
+#define KAL_ITC_LOCK_TAKE_DI_DMT_PRIO(lock, irq_mask, mt_mask, prio)                    \
+    ({                                                                                  \
+        kal_status _ret = 0;                                                            \
+        kal_uint32 _new_prio = KAL_ITC_GRP;                                             \
+        __asm__ __volatile__(                                                           \
+            "   mfc0    %4, $2, 6;"                                                     \
+            "   move    %1, %4;"                                                        \
+            "   ins     %1, %6, 0, 2;"                                                  \
+            "   ext     %4, %4, 0, 2;"                                                  \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   mtc0    %1, $2, 6;"                                                     \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "1: ll      %1, %5;"                                                        \
+            "   beqz    %1, 4f;"                                                        \
+            "   beqz    %2, 2f;"                                                        \
+            "   ei;"                                                                    \
+            "   ehb;"                                                                   \
+            "2: beqz    %3, 3f;"                                                        \
+            "   emt;"                                                                   \
+            "   ehb;"                                                                   \
+            "3: pause;"                                                                 \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "   b       1b;"                                                            \
+            "4: li      %1, 1;"                                                         \
+            "   sc      %1, %0;"                                                        \
+            "   beqz    %1, 1b;"                                                        \
+            : "=ZC" (lock), "+d" (_ret), "+d" (irq_mask), "+d" (mt_mask), "+d" (prio)   \
+            : "ZC" (lock), "d" (_new_prio)                                              \
+            : "memory"                                                                  \
+        );                                                                              \
+        _ret;                                                                           \
+    })
+#else
+#define KAL_ITC_LOCK_TAKE_DI_DMT_PRIO(lock, irq_mask, mt_mask, prio)                    \
+    ({                                                                                  \
+        kal_status _ret = 0;                                                            \
+        kal_uint32 _new_prio = KAL_ITC_GRP;                                             \
+        __asm__ __volatile__(                                                           \
+            "   .set    push;"                                                          \
+            "   .set    noreorder;"                                                     \
+            "   mfc0    %4, $2, 6;"                                                     \
+            "   move    %1, %4;"                                                        \
+            "   ins     %1, %6, 0, 2;"                                                  \
+            "   ext     %4, %4, 0, 2;"                                                  \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   mtc0    %1, $2, 6;"                                                     \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "1: ll      %1, %5;"                                                        \
+            "   beqz    %1, 4f;"                                                        \
+            "   li      %1, 1;"                                                         \
+            "   beqz    %2, 2f;"                                                        \
+            "   nop;"                                                                   \
+            "   ei;"                                                                    \
+            "   ehb;"                                                                   \
+            "2: beqz    %2, 3f;"                                                        \
+            "   nop;"                                                                   \
+            "   emt;"                                                                   \
+            "   ehb;"                                                                   \
+            "3: pause;"                                                                 \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "   b       1b;"                                                            \
+            "   nop;"                                                                   \
+            "4: sc      %1, %0;"                                                        \
+            "   beqz    %1, 1b;"                                                        \
+            "   nop;"                                                                   \
+            "   .set    pop;"                                                           \
+            : "=ZC" (lock), "+d" (_ret), "+d" (irq_mask), "+d" (mt_mask), "+d" (prio)   \
+            : "ZC" (lock), "d" (_new_prio)                                              \
+            : "memory"                                                                  \
+        );                                                                              \
+        _ret;                                                                           \
+    })
+#endif
+
+/* Primitive macro for trying the lock, return success or fail,
+ * does disable interrupts and MT, and raise prio to HW_ITC_GRP if success. 
+ * Old irq status saved in irq_mask, old MT status saved in mt_mask,
+ * old prio saved in prio. */
+#if defined(__nanomips__)
+#define KAL_ITC_LOCK_TRY_DI_DMT_PRIO(lock, irq_maski, mt_mask, prio)                    \
+    ({                                                                                  \
+        kal_status _ret = 0;                                                            \
+        kal_uint32 _new_prio = KAL_ITC_GRP;                                             \
+        __asm__ __volatile__(                                                           \
+            "   mfc0    %4, $2, 6;"                                                     \
+            "   move    %1, %4;"                                                        \
+            "   ins     %1, %6, 2, 2;"                                                  \
+            "   ext     %4, %4, 2, 2;"                                                  \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   mtc0    %1, $2, 6;"                                                     \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "   ll      %1, %5;"                                                        \
+            "   bnez    %1, 1f;"                                                        \
+            "   li      %1, 1;"                                                         \
+            "   sc      %1, %0;"                                                        \
+            "   b       2f;"                                                            \
+            "1: li      %1, 0;"                                                         \
+            "2: ;"                                                                      \
+            : "=ZC" (lock), "+d" (_ret), "+d" (irq_mask), "+d" (mt_mask), "+d" (prio)   \
+            : "ZC" (lock), "d" (_new_prio)                                              \
+            : "memory"                                                                  \
+        );                                                                              \
+        if (_ret != 0) {                                                                \
+            _ret = KAL_SUCCESS;                                                         \
+        } else {                                                                        \
+            _ret = KAL_ERROR;                                                           \
+            if (irq_mask != 0) {                                                        \
+                __asm__ __volatile__("ei; ehb;":::"memory");                            \
+            }                                                                           \
+            if (prio != KAL_ITC_GRP) {                                                  \
+                kal_uint32 _tc_schedule = 0;                                            \
+                __asm__ __volatile__(                                                   \
+                    "   mfc0    %0, $2, 6;"                                             \
+                    "   ins     %0, %1, 2, 2;"                                          \
+                    "   mtc0    %0, $2, 6;"                                             \
+                    "   ehb;"                                                           \
+                    : "+d" (_tc_schedule)                                               \
+                    : "d" (prio)                                                        \
+                    :                                                                   \
+                );                                                                      \
+            }                                                                           \
+            if (mt_mask != 0) {                                                         \
+                __asm__ __volatile__("emt; ehb;":::"memory");                           \
+            }                                                                           \
+        }                                                                               \
+        _ret;                                                                           \
+    })
+#elif defined(__mips16)
+#define KAL_ITC_LOCK_TRY_DI_DMT_PRIO(lock, irq_maski, mt_mask, prio)                    \
+    ({                                                                                  \
+        kal_status _ret = 0;                                                            \
+        kal_uint32 _new_prio = KAL_ITC_GRP;                                             \
+        __asm__ __volatile__(                                                           \
+            "   mfc0    %4, $2, 6;"                                                     \
+            "   move    %1, %4;"                                                        \
+            "   ins     %1, %6, 0, 2;"                                                  \
+            "   ext     %4, %4, 0, 2;"                                                  \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   mtc0    %1, $2, 6;"                                                     \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "   ll      %1, %5;"                                                        \
+            "   bnez    %1, 1f;"                                                        \
+            "   li      %1, 1;"                                                         \
+            "   sc      %1, %0;"                                                        \
+            "   b       2f;"                                                            \
+            "1: li      %1, 0;"                                                         \
+            "2: ;"                                                                      \
+            : "=ZC" (lock), "+d" (_ret), "+d" (irq_mask), "+d" (mt_mask), "+d" (prio)   \
+            : "ZC" (lock), "d" (_new_prio)                                              \
+            : "memory"                                                                  \
+        );                                                                              \
+        if (_ret != 0) {                                                                \
+            _ret = KAL_SUCCESS;                                                         \
+        } else {                                                                        \
+            _ret = KAL_ERROR;                                                           \
+            if (irq_mask != 0) {                                                        \
+                __asm__ __volatile__("ei; ehb;":::"memory");                            \
+            }                                                                           \
+            if (prio != KAL_ITC_GRP) {                                                  \
+                kal_uint32 _tc_schedule = 0;                                            \
+                __asm__ __volatile__(                                                   \
+                    "   mfc0    %0, $2, 6;"                                             \
+                    "   ins     %0, %1, 0, 2;"                                          \
+                    "   mtc0    %0, $2, 6;"                                             \
+                    "   ehb;"                                                           \
+                    : "+d" (_tc_schedule)                                               \
+                    : "d" (prio)                                                        \
+                    :                                                                   \
+                );                                                                      \
+            }                                                                           \
+            if (mt_mask != 0) {                                                         \
+                __asm__ __volatile__("emt; ehb;":::"memory");                           \
+            }                                                                           \
+        }                                                                               \
+        _ret;                                                                           \
+    })
+#else
+#define KAL_ITC_LOCK_TRY_DI_DMT_PRIO(lock, irq_maski, mt_mask, prio)                    \
+    ({                                                                                  \
+        kal_status _ret = 0;                                                            \
+        kal_uint32 _new_prio = KAL_ITC_GRP;                                             \
+        __asm__ __volatile__(                                                           \
+            "   .set    push;"                                                          \
+            "   .set    noreorder;"                                                     \
+            "   mfc0    %4, $2, 6;"                                                     \
+            "   move    %1, %4;"                                                        \
+            "   ins     %1, %6, 0, 2;"                                                  \
+            "   ext     %4, %4, 0, 2;"                                                  \
+            "   dmt     %3;"                                                            \
+            "   ehb;"                                                                   \
+            "   mtc0    %1, $2, 6;"                                                     \
+            "   ehb;"                                                                   \
+            "   di      %2;"                                                            \
+            "   ehb;"                                                                   \
+            "   ext     %3, %3, 15, 1;"                                                 \
+            "   ext     %2, %2, 0, 1;"                                                  \
+            "   ll      %1, %5;"                                                        \
+            "   bnez    %1, 1f;"                                                        \
+            "   li      %1, 0;"                                                         \
+            "   li      %1, 1;"                                                         \
+            "   sc      %1, %0;"                                                        \
+            "1: ;"                                                                      \
+            "   .set    pop;"                                                           \
+            : "=ZC" (lock), "+d" (_ret), "+d" (irq_mask), "+d" (mt_mask), "+d" (prio)   \
+            : "ZC" (lock), "d" (_new_prio)                                              \
+            : "memory"                                                                  \
+        );                                                                              \
+        if (_ret != 0) {                                                                \
+            _ret = KAL_SUCCESS;                                                         \
+        } else {                                                                        \
+            _ret = KAL_ERROR;                                                           \
+            if (irq_mask != 0) {                                                        \
+                __asm__ __volatile__("ei; ehb;":::"memory");                            \
+            }                                                                           \
+            if (prio != KAL_ITC_GRP) {                                                  \
+                kal_uint32 _tc_schedule = 0;                                            \
+                __asm__ __volatile__(                                                   \
+                    "   mfc0    %0, $2, 6;"                                             \
+                    "   ins     %0, %1, 0, 2;"                                          \
+                    "   mtc0    %0, $2, 6;"                                             \
+                    "   ehb;"                                                           \
+                    : "+d" (_tc_schedule)                                               \
+                    : "d" (prio)                                                        \
+                    :                                                                   \
+                );                                                                      \
+            }                                                                           \
+            if (mt_mask != 0) {                                                         \
+                __asm__ __volatile__("emt; ehb;":::"memory");                           \
+            }                                                                           \
+        }                                                                               \
+        _ret;                                                                           \
+    })
+#endif
+/* Primitive macro for trying the lock ticket based, return success or fail */
+#if defined(__mips16) || defined(__nanomips__)
+#define KAL_ITC_LOCK_TRY_FIFO(lock, ticket)                     \
+    ({                                                          \
+        kal_status _ret = 0;                                    \
+        __asm__ __volatile__(                                   \
+            "   ll      $a3, %2;"                               \
+            "   li      %0, %3;"                                \
+            "   bne     %1, $a3, 1f;"                           \
+            "   li      %0, %4;"                                \
+            "1: ;"                                              \
+            : "=d"(_ret), "+d"(ticket)                          \
+            : "ZC"(lock), "I"(KAL_ERROR), "I"(KAL_SUCCESS)      \
+            : "$a3", "memory");                                 \
+        _ret;                                                   \
+    })
+#else
+#define KAL_ITC_LOCK_TRY_FIFO(lock, ticket)                     \
+    ({                                                          \
+        kal_status _ret = 0;                                    \
+        __asm__ __volatile__(                                   \
+            "   .set    push;"                                  \
+            "   .set    noreorder;"                             \
+            "   ll      $a3, %2;"                               \
+            "   bne     %1, $a3, 1f;"                           \
+            "   li      %0, %3;"                                \
+            "   li      %0, %4;"                                \
+            "1: ;"                                              \
+            "   .set    pop;"                                   \
+            : "=d"(_ret), "+d"(ticket)                          \
+            : "ZC"(lock), "I"(KAL_ERROR), "I"(KAL_SUCCESS)      \
+            : "$a3", "memory");                                 \
+        _ret;                                                   \
+    })
+#endif
+
+/* Primitive macro for releasing the lock */
+#if defined(__mips16)
+#define KAL_ITC_LOCK_GIVE(lock)     \
+    do {                            \
+        __asm__ __volatile__(       \
+            "   sync    0x10;"      \
+            "   li      $a3, 0;"    \
+            "   sw      $a3, %0;"   \
+            : "=ZC"(lock)           \
+            :                       \
+            : "$a3", "memory");     \
+    } while (0)
+#else
+#define KAL_ITC_LOCK_GIVE(lock)     \
+    do {                            \
+        __asm__ __volatile__(       \
+            "   sync    0x10;"      \
+            "   sw      $zero, %0;" \
+            : "=ZC"(lock)           \
+            :                       \
+            : "memory");            \
+    } while (0)
+#endif
+
+/* Primitive macro for releasing the lock,
+ * does enable interrupts based on irq_mask*/
+#if defined(__mips16)
+#define KAL_ITC_LOCK_GIVE_EI(lock, irq_mask)                \
+    do {                                                    \
+        __asm__ __volatile__(                               \
+            "   sync    0x10;"                              \
+            "   li      $a3, 0;"                            \
+            "   sw      $a3, %0;"                           \
+            : "=ZC"(lock)                                   \
+            :                                               \
+            : "$a3", "memory");                             \
+        if (irq_mask != 0) {                                \
+            __asm__ __volatile__("ei; ehb;" ::: "memory");  \
+        }                                                   \
+    } while (0)
+#else
+#define KAL_ITC_LOCK_GIVE_EI(lock, irq_mask)                \
+    do {                                                    \
+        __asm__ __volatile__(                               \
+            "   sync    0x10;"                              \
+            "   sw      $zero, %0;"                         \
+            : "=ZC"(lock)                                   \
+            :                                               \
+            : "memory");                                    \
+        if (irq_mask != 0) {                                \
+            __asm__ __volatile__("ei; ehb;" ::: "memory");  \
+        }                                                   \
+    } while (0)
+#endif
+
+/* Primitive macro for releasing the lock,
+ * does enable interrupts based on irq_mask, and MT based on mt_mask*/
+#if defined(__mips16)
+#define KAL_ITC_LOCK_GIVE_EI_EMT(lock, irq_mask, mt_mask)                                   \
+    do {                                                                                    \
+        __asm__ __volatile__(                                                               \
+                "   sync    0x10;"                                                          \
+                "   li      $a3, 0;"                                                        \
+                "   sw      $a3, %0;"                                                       \
+                : "=ZC" (lock)                                                              \
+                :                                                                           \
+                : "$a3", "memory"                                                           \
+        );                                                                                  \
+        if (irq_mask != 0) {                                                                \
+            __asm__ __volatile__("ei; ehb;":::"memory");                                    \
+        }                                                                                   \
+        if (mt_mask != 0) {                                                                 \
+            __asm__ __volatile__("emt; ehb;":::"memory");                                   \
+        }                                                                                   \
+    } while(0)
+#else
+#define KAL_ITC_LOCK_GIVE_EI_EMT(lock, irq_mask, mt_mask)                                   \
+    do {                                                                                    \
+        __asm__ __volatile__(                                                               \
+            "   sync    0x10;"                                                              \
+            "   sw      $zero, %0;"                                                         \
+            : "=ZC" (lock)                                                                  \
+            :                                                                               \
+            : "memory"                                                                      \
+        );                                                                                  \
+        if (irq_mask != 0) {                                                                \
+            __asm__ __volatile__("ei; ehb;":::"memory");                                    \
+        }                                                                                   \
+        if (mt_mask != 0) {                                                                 \
+            __asm__ __volatile__("emt; ehb;":::"memory");                                   \
+        }                                                                                   \
+    } while(0)
+#endif
+
+/* Primitive macro for releasing the lock,
+ * does enable interrupts based on irq_mask, MT based on mt_mask, and TC priority based 
+ * on old_prio*/
+#if defined(__nanomips__)
+#define KAL_ITC_LOCK_GIVE_EI_EMT_PRIO(lock, irq_mask, mt_mask, old_prio)                    \
+    do {                                                                                    \
+        __asm__ __volatile__(                                                               \
+            "   sync    0x10;"                                                              \
+            "   sw      $zero, %0;"                                                         \
+            : "=ZC" (lock)                                                                  \
+            :                                                                               \
+            : "memory"                                                                      \
+        );                                                                                  \
+        if (irq_mask != 0) {                                                                \
+            __asm__ __volatile__("ei; ehb;":::"memory");                                    \
+        }                                                                                   \
+        if (old_prio != KAL_ITC_GRP) {                                                      \
+            kal_uint32 _tc_schedule = 0;                                                    \
+            __asm__ __volatile__(                                                           \
+                "   mfc0    %0, $2, 6;"                                                     \
+                "   ins     %0, %1, 2, 2;"                                                  \
+                "   mtc0    %0, $2, 6;"                                                     \
+                "   ehb;"                                                                   \
+                : "+d" (_tc_schedule)                                                       \
+                : "d" (old_prio)                                                            \
+                :                                                                           \
+            );                                                                              \
+        }                                                                                   \
+        if (mt_mask != 0) {                                                                 \
+            __asm__ __volatile__("emt; ehb;":::"memory");                                   \
+        }                                                                                   \
+    } while(0)
+#elif defined(__mips16)
+#define KAL_ITC_LOCK_GIVE_EI_EMT_PRIO(lock, irq_mask, mt_mask, old_prio)                    \
+    do {                                                                                    \
+        __asm__ __volatile__(                                                               \
+                "   sync    0x10;"                                                          \
+                "   li      $a3, 0;"                                                        \
+                "   sw      $a3, %0;"                                                       \
+                : "=ZC" (lock)                                                              \
+                :                                                                           \
+                : "$a3", "memory"                                                           \
+        );                                                                                  \
+        if (irq_mask != 0) {                                                                \
+            __asm__ __volatile__("ei; ehb;":::"memory");                                    \
+        }                                                                                   \
+        if (old_prio != KAL_ITC_GRP) {                                                      \
+            kal_uint32 _tc_schedule = 0;                                                    \
+            __asm__ __volatile__(                                                           \
+                "   mfc0    %0, $2, 6;"                                                     \
+                "   ins     %0, %1, 0, 2;"                                                  \
+                "   mtc0    %0, $2, 6;"                                                     \
+                "   ehb;"                                                                   \
+                : "+d" (_tc_schedule)                                                       \
+                : "d" (old_prio)                                                            \
+                :                                                                           \
+            );                                                                              \
+        }                                                                                   \
+        if (mt_mask != 0) {                                                                 \
+            __asm__ __volatile__("emt; ehb;":::"memory");                                   \
+        }                                                                                   \
+    } while(0)
+#else
+#define KAL_ITC_LOCK_GIVE_EI_EMT_PRIO(lock, irq_mask, mt_mask, old_prio)                    \
+    do {                                                                                    \
+        __asm__ __volatile__(                                                               \
+            "   sync    0x10;"                                                              \
+            "   sw      $zero, %0;"                                                         \
+            : "=ZC" (lock)                                                                  \
+            :                                                                               \
+            : "memory"                                                                      \
+        );                                                                                  \
+        if (irq_mask != 0) {                                                                \
+            __asm__ __volatile__("ei; ehb;":::"memory");                                    \
+        }                                                                                   \
+        if (old_prio != KAL_ITC_GRP) {                                                      \
+            kal_uint32 _tc_schedule = 0;                                                    \
+            __asm__ __volatile__(                                                           \
+                "   mfc0    %0, $2, 6;"                                                     \
+                "   ins     %0, %1, 0, 2;"                                                  \
+                "   mtc0    %0, $2, 6;"                                                     \
+                "   ehb;"                                                                   \
+                : "+d" (_tc_schedule)                                                       \
+                : "d" (old_prio)                                                            \
+                :                                                                           \
+            );                                                                              \
+        }                                                                                   \
+        if (mt_mask != 0) {                                                                 \
+            __asm__ __volatile__("emt; ehb;":::"memory");                                   \
+        }                                                                                   \
+    } while(0)
+#endif
+
+/* Primitive macro for releasing the lock ticket based */
+#define KAL_ITC_LOCK_GIVE_FIFO(lock)                     \
+    do {                                                 \
+        __asm__ __volatile__("sync 0x10;" ::: "memory"); \
+        (lock)++;                                        \
+    } while (0)
+
+#define KAL_ITC_PAUSE()                              \
+    do {                                             \
+        __asm__ __volatile__("pause;" ::: "memory"); \
+    } while (0)
+
+/*******************************************************************************
+ * Types
+ *******************************************************************************/
+typedef struct kal_itc_node_struct {
+    struct kal_itc_node_struct *next;
+    struct kal_itc_node_struct *prev;
+} kal_itc_node_s;
+
+typedef struct {
+    kal_itc_node_s lock_node;
+    kal_uint32     lock_id;
+    kal_uint32     lock;
+    kal_uint32     interrupt_mask;
+    kal_char       name[KAL_ITC_MAX_NAME];
+    void *         owner_context;
+    kal_uint32     nesting_level;
+#if defined(DEBUG_KAL)
+    kal_uint32 lock_start_time;
+    kal_uint32 lock_taker;
+    kal_uint32 max_lock_hold_time;
+    kal_uint32 max_lock_taker;
+#endif
+} kal_itc_lock_s;
+
+/*******************************************************************************
+ * Variables
+ *******************************************************************************/
+extern kal_itc_lock_s *kal_itc_tbl[KAL_ITC_NUM];
+extern kal_uint32 kal_tc_prio_count[SYS_MCU_NUM_TC];
+extern kal_uint32 kal_tc_prio_save[SYS_MCU_NUM_TC];
+
+#endif //_KAL_ITC_H
diff --git a/mcu/interface/service/kal/kal_public_api.h b/mcu/interface/service/kal/kal_public_api.h
new file mode 100644
index 0000000..f41102e
--- /dev/null
+++ b/mcu/interface/service/kal/kal_public_api.h
@@ -0,0 +1,5008 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   kal_public_api.h
+ *
+ * Project:
+ * --------
+ *   Maui_Software
+ *
+ * Description:
+ * ------------
+ *   This file provides KAL public API prototypes
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ ****************************************************************************/
+
+#ifndef _KAL_PUBLIC_API_H
+#define _KAL_PUBLIC_API_H
+
+/*******************************************************************************
+ * Common Header File Include
+ *******************************************************************************/
+#ifndef GEN_FOR_PC
+#include <stdio.h>
+#include <string.h>
+#endif
+
+#include "kal_general_types.h"
+#include "kal_public_defs.h"
+#include "kal_atomic_api.h"
+#include "mips_ia_utils_public.h"
+#include "kal_inline_api.h"
+
+#if defined(__DHL_MODULE__)
+#include "dhl_trace.h"
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+#if defined(KAL_ON_OSCAR)
+#define kal_snprintf _snprintf
+#else
+#define kal_snprintf snprintf
+#endif
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  sprintf
+ * DESCRIPTION
+ *  sprintf accepts a series of arguments, applies to each a format specifier from *format,
+ *  and writes the formatted data to buffer str, and a terminating NUL is output.
+ * PARAMETERS
+ *  str:             [IN] destination buffer
+ *  format:          [IN] specify the arguments output format
+ *  ...:             [IN] variable-parameter, a series of arguments
+ * NOTE
+ *  number of variable-parameters must be less than or equal to 20, if more paramters are checked, will assert.
+ *  this limitation is also apply to all sprintf/sscanf family functions, that is sprintf/snprintf/vsprintf/vsnprintf/sscanf/vsscanf
+ * RETURN VALUES
+ *  the number of bytes in the output string, except the concluding NUL is not counted.  
+ ******************************************************************************/
+#define kal_sprintf sprintf
+
+extern kal_char *kal_strtok_r(kal_char *string, const kal_char *seperators,
+                              kal_char **ppLast);
+
+#define kal_toWCHAR(asciiString) L##asciiString
+
+/*************************************************************************
+* FUNCTION
+*  kal_itoa
+*
+* DESCRIPTION
+*  converts integers to string in various radixes
+*
+* PARAMETERS
+*  value	-  integer need to convert
+*  str      -  buffer to save convert result
+*  radix	-  the base of the integer, like 2,10,16
+* RETURNS
+*  return the str buffer address
+*
+*************************************************************************/
+extern char *kal_itoa(int value, char *str, int radix);
+
+/*
+ * 16bits string operations
+ */
+extern int kal_wstrlen(const WCHAR *wstr);
+extern WCHAR *kal_wstrcpy(WCHAR *to, const WCHAR *from);
+extern WCHAR *kal_wstrncpy(WCHAR *to, const WCHAR *from, int n);
+extern int kal_wstrcmp(const WCHAR *s1, const WCHAR *s2);
+extern int kal_wstrncmp(const WCHAR *s1, const WCHAR *s2, int n);
+extern WCHAR *kal_wstrcat(WCHAR *s1, const WCHAR *s2);
+extern WCHAR *kal_wstrncat(WCHAR *s1, const WCHAR *s2, int n);
+extern WCHAR *kal_wstrchr(const WCHAR *s, int c);
+extern WCHAR *kal_wstrrchr(const WCHAR *str, int ch);
+
+/*
+ * dual 8bits string operations
+ */
+extern int kal_dchar_strlen(const char *wstr);
+extern char *kal_dchar_strcpy(char *to, const char *from);
+extern char *kal_dchar_strncpy(char *to, const char *from, int n);
+extern int kal_dchar_strcmp(const char *s1, const char *s2);
+extern int kal_dchar_strncmp(const char *s1, const char *s2, int n);
+extern char *kal_dchar_strcat(char *s1, const char *s2);
+extern char *kal_dchar_strncat(char *s1, const char *s2, int n);
+extern char *kal_dchar_strchr(const char *s, int c);
+extern char *kal_dchar_strrchr(const char *str, int ch);
+extern void kal_dchar2char(WCHAR *outstr, char *tostr);
+extern void kal_wsprintf(WCHAR *outstr, char *fmt, ...);
+
+
+#if !defined(GEN_FOR_PC)
+
+/*************************************************************************
+* FUNCTION
+*  time
+*
+* DESCRIPTION
+*  time() return current calendar time as a value of type time_t .It stores the same value at 
+*  parameter t unless the argument is NULL.  The value represents the number of seconds 
+*  since 00:00 hours, Jan 1, 1970 UTC   (i.e., the current unix timestamp).
+*
+* PARAMETERS
+*  t	-  pointer to an object of type time_t to store the current time.
+*         You can just input NULL, the function still return a value of type time_t with the result.
+*
+* RETURNS
+*  The current calendar time as a value of type time_t .
+*
+* NOTE
+*  Only be supported in limited projects. If it is not supported, build fail is happened.
+*
+*************************************************************************/
+extern time_t time(time_t *t);
+
+/*************************************************************************
+* FUNCTION
+*  time_ms_us
+*
+* DESCRIPTION
+*  time_ms_us() return current calendar time as a value of type wall_clock .It stores the same value at 
+*  parameter t unless the argument is NULL.  The value represents the number of milli-seconds and micro-seconds
+*  since 00:00 hours, Jan 1, 1970 UTC   (i.e., the current unix timestamp).
+*
+* PARAMETERS
+*  t	-  pointer to an object of type wall_clock to store the current time.
+*         You can just input NULL, the function still return a value of type wall_clock with the result.
+*
+* RETURNS
+*  The current calendar time as a value of type wall_clock .
+*
+* NOTE
+*  Only be supported in limited projects. If it is not supported, build fail is happened.
+*
+*************************************************************************/
+extern wall_clock time_ms_us(wall_clock *t);
+
+/*************************************************************************
+* FUNCTION
+*  gmtime_r
+*
+* DESCRIPTION
+*  Uses the value pointed by tim_p to fill the tm structure pointed by res with the values 
+*  that represent the corresponding time, expressed as UTC time (i.e., the time at the 
+*  GMT timezone). If tim_p or res is NULL, NULL will be returned and the content of res
+*  will not be changed.
+*
+* PARAMETERS
+*  tim_p - pointer to an object of type time_t that contains a time value.
+*  res    - pointer to an object of type tm to store the result converted by gmtime_r
+*
+* RETURNS
+*  A pointer to inputted tm structure res with its members filled with the values that 
+*  correspond to the UTC time representation of tim_p.
+*  Return NULL if tim_p or res is NULL.
+*
+* NOTE
+*  Only be supported in limited projects. If it is not supported, build fail is happened.
+*
+* SEE ALSO
+*  time, localtime_r
+*
+*************************************************************************/
+extern struct tm *gmtime_r(const time_t *tim_p, struct tm *res);
+
+
+/*************************************************************************
+* FUNCTION
+*  localtime_r
+*
+* DESCRIPTION
+*  Uses the value pointed by tim_p to fill the tm structure pointed by res with the values that 
+*  represent the corresponding time, expressed for the local timezone.
+*  Note that localtime() may not available due to timezone is not updated within bootup 10 
+*  seconds. If it is happened, the result of localtime_r() is equal to gmtime_r(). (i.e. the returned
+*  tm structure represents the corresponding UTC time.
+*
+* PARAMETERS
+*  tim_p - pointer to an object of type time_t that contains a time value.
+*  res    - pointer to an object of type tm to store the result converted by localtime_r()
+*
+* RETURNS
+*  A pointer to inputted tm structure res with its members filled with the values that 
+*  correspond to the local time representation of tim_p if localtime_r() is available. If localtime_r()
+*  is not available, the tm structure represents the corresponding UTC time.
+*  Return NULL if tim_p or res is NULL.
+*
+* NOTE
+*   Only be supported in limited projects. If it is not supported, build fail is happened.
+*
+* SEE ALSO
+*  time, gmtime_r
+*
+*************************************************************************/
+struct tm *localtime_r(const time_t *tim_p, struct tm *res);
+
+
+/*************************************************************************
+* FUNCTION
+*  asctime_r
+*
+* DESCRIPTION
+*  Interprets the contents of the tm structure pointed by tim_p as a calendar time and 
+*  converts it to a C-string containing a human-readable version of the corresponding 
+*  date and time. The returned string has the following format:
+*       Www Mmm dd hh:mm:ss yyyy
+*  Where Www is the weekday, Mmm the month (in letters), dd the day of the month, 
+*  hh:mm:ss the time, and yyyy the year. The string is followed by a new-line character 
+*  ('\n') and terminated with a null-character.
+*  If tim_p or res is NULL, NULL will be returned and the content of res will not be changed.
+*
+* PARAMETERS
+*  tim_p - pointer to a tm structure that contains a calendar time broken down into its 
+*              components (see struct tm).
+*  res    - a pointer to the string for containing result converted by asctime_r.
+*             The length of the string should larger than 26.
+*
+* RETURNS
+*  A pointer to inputted string res containing the date and time information in a 
+*  human-readable format.
+*  Return NULL if tim_p or res is NULL.
+*
+* NOTE
+*  Only be supported in limited projects. If it is not supported, build fail is happened.
+*
+* SEE ALSO
+*  time, gmtime_r, localtime_r, ctime_r
+*
+*************************************************************************/
+char *asctime_r(const struct tm *tim_p, char *res);
+
+
+/*************************************************************************
+* FUNCTION
+*  ctime_r
+*
+* DESCRIPTION
+*  Interprets the contents of the tm structure pointed by tim_p as a calendar time and
+*  converts it to a C-string containing a human-readable version of the corresponding
+*  date and time, in terms of local time. The returned string has the following format:
+*       Www Mmm dd hh:mm:ss yyyy
+*  Where Www is the weekday, Mmm the month (in letters), dd the day of the month, 
+*  hh:mm:ss the time, and yyyy the year. The string is followed by a new-line character 
+*  ('\n') and terminated with a null-character.
+*  Note that ctime_r() may not available due to timezone is not updated within bootup 10 
+*  seconds. If it is happened, the result of ctime_r(), asctime_r(localtime_r()), is equal to 
+*  asctime_r(gmtime_r()).
+* 
+* PARAMETERS
+*  tim_p - pointer to a tm structure that contains a calendar time broken down into its 
+*              components (see struct tm).
+*  res    - a pointer to the string for containing result converted by ctime_r.
+*             The length of the string should larger than 26.
+*
+* RETURNS
+*  A pointer to inputted string res containing the date and time information in a 
+*  human-readable format.
+*  Return NULL if tim_p or res is NULL.
+*
+* NOTE
+*  Only be supported in limited projects. If it is not supported, build fail is happened.
+*
+* SEE ALSO
+*  time, gmtime_r, localtime_r, asctime_r
+*
+*************************************************************************/
+char *ctime_r(const time_t *tim_p, char *res);
+
+#endif /* !defined(GEN_FOR_PC) */
+#if defined(__MTK_TARGET__)
+/*KAL_CC_SPINLOCK*/
+extern void *kal_cc_md1_dsp_spinlock;
+
+kal_status MD1_DSP_kal_cc_take_spinlock(void *        cc_spinlock_p,
+                                        kal_wait_mode wait_mode);
+void MD1_DSP_kal_cc_give_spinlock(void *cc_spinlock_p);
+#endif
+/*******************************************************************************
+ * Category 2 : Query Functions for Initialize and States
+ *******************************************************************************/
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_query_systemInit
+ * DESCRIPTION
+ *  query whether the system is in initialization phase.
+ * PARAMETERS
+ *  N/A
+ * RETURN VALUES
+ *  KAL_TRUE: system is in initialization phase.
+ *  KAL_FALSE: system is not in initialization phase.
+ ******************************************************************************/
+extern kal_bool kal_query_systemInit(void);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_curent_domain
+ * DESCRIPTION
+ *  return current domain
+ * RETURNS
+ *  enum kal_domain: KAL_DOMAIN_NORMAL/KAL_DOMAIN_HRT/KAL_DOMAIN_CHRT
+ ******************************************************************************/
+#if defined(__MTK_TARGET__)
+#if !defined(__kal_get_current_domain__)
+#define __kal_get_current_domain__
+#if defined(__MIPS_I7200__)
+#define kal_get_current_domain() (miu_mfc0(MIU_C0_KSCRATCH4) & 0x3)
+#endif /* defined(__MIPS_I7200__) */
+#endif /* __kal_get_current_domain__ */
+#else  /* __MTK_TARGET__ */
+#define kal_get_current_domain() 0
+#endif /* __MTK_TARGET__ */
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_if_hrt_domain
+ * DESCRIPTION
+ *  Identify if current VPE is HRT domain
+ * PARAMETERS
+ *  VPE ID
+ * RETURNS
+ *  KAL_TRUE if current VPE is HRT domain
+ ******************************************************************************/
+#if !defined(__MTK_TARGET__)
+#define kal_get_domain(vpe_id) 0
+#define kal_if_hrt_domain(vpe_id) 0
+#endif /* __MTK_TARGET__ */
+
+/*************************************************************************
+* FUNCTION
+*  kal_runtime_affinity_set
+* DESCRIPTION
+*  set current task's or current hisr's affinity attribute
+* PARAMETERS
+*  affinity[IN]: VPE0_Group, VPE2_Group, SMP_NORMAL_Group
+* RETURNS
+*  KAL_TRUE or KAL_FALSE
+*************************************************************************/
+kal_bool kal_runtime_affinity_set(kal_affinity_group affinity);
+
+/*************************************************************************
+* FUNCTION
+*  kal_runtime_affinity_resume
+* DESCRIPTION
+*  resume current task's or current hisr's affinity attribute to original config value
+* PARAMETERS
+*  NONE
+* RETURNS
+*  KAL_TRUE or KAL_FALSE
+*************************************************************************/
+kal_bool kal_runtime_affinity_resume(void);
+
+/*************************************************************************
+* FUNCTION
+*  kal_runtime_affinity_to_current_vpe
+* DESCRIPTION
+*  Affines the calling task to current VPE.
+* PARAMETERS
+*  NONE
+* RETURNS
+*  KAL_TRUE
+*************************************************************************/
+kal_bool kal_runtime_affinity_to_current_vpe(void);
+
+/*************************************************************************
+* FUNCTION
+*  kal_runtime_group_affinity_set
+* DESCRIPTION
+*  Sets the affinity of all tasks in given group. All tasks must be in some
+*  of KAL_SUSPEND states or the whole operation will fail.
+* PARAMETERS
+*  group_id[IN]: Group ID
+*  affinity[IN]: affinity mask
+* RETURNS
+*  KAL_TRUE if affinity set was successful
+*  KAL_FALSE if affinity set failed (e.g. because one or more tasks were �n 
+*  non-suspended state
+*************************************************************************/
+
+kal_bool kal_runtime_group_affinity_set(kal_task_group_id  group_id,
+                                        kal_affinity_group affinity);
+
+/* DOM-NOT_FOR_SDK-END */
+
+/*******************************************************************************
+ * Category 3 : LISR, HISR and TASK functions
+ *******************************************************************************/
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_current_thread_ID
+ * DESCRIPTION
+ *  get current thread identity, which is a unique pointer for each thread.
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  current thread identity.
+ * NOTE
+ *  thread is defined as task or HISR.
+ ******************************************************************************/
+void *kal_get_current_thread_ID(void);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_current_lisr_ID
+ * DESCRIPTION
+ *  get current lisr identity.
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  current lisr identity.
+ ******************************************************************************/
+kal_uint32 kal_get_current_lisr_ID(void);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_sleep_task
+ * DESCRIPTION
+ *  put the task into sleep for a specified duration which is expressed in terms
+ *  of system tick.
+ * PARAMETERS
+ *  time_in_ticks: [IN] how many system ticks to sleep.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  N/A
+ * SEE ALSO
+ *  KAL_MILLISECS_PER_TICK
+ ******************************************************************************/
+void kal_sleep_task(kal_uint32 time_in_ticks);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_current_task
+ * DESCRIPTION
+ *  get current task identity.
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  current task identity.
+ * SEE ALSO
+ *  kal_get_current_task_index
+ ******************************************************************************/
+kal_taskid kal_get_current_task(void);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_current_hisr
+ * DESCRIPTION
+ *  get current hisr identity.
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  current hisr identity.
+ * SEE ALSO
+ *  kal_get_current_hisr_index
+ ******************************************************************************/
+kal_hisrid kal_get_current_hisr(void);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_current_task_priority
+ * DESCRIPTION
+ *  get current task priority.
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  current task priority.
+ ******************************************************************************/
+kal_uint32 kal_get_current_task_priority(void);
+
+/*************************************************************************
+ * FUNCTION
+ *	 kal_get_task_status
+ *
+ * DESCRIPTION
+ *	 This routine is to get the task's status.
+ *
+ * PARAMETERS
+ *	 taskid : task id(pointer points to task control block
+ *
+ * RETURNS
+ *	 task's current status
+ *
+ * GLOBALS AFFECTED
+ *
+ *************************************************************************/
+kal_task_status kal_get_task_status(kal_taskid taskid);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_set_active_module_id
+ * DESCRIPTION
+ *  set active module in current task.
+ * PARAMETERS
+ *  module_id: [IN] active module in current task.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  (1)This API must be called before kal_get_active_module_id(). So, the recommended place to call it
+ *     is in task main function, immediately after get a ILM message.
+ * SEE ALSO
+ *  kal_get_active_module_id
+ ******************************************************************************/
+extern void kal_set_active_module_id(module_type module_id);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_active_module_id
+ * DESCRIPTION
+ *  get active module in current task.
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  active module in current task.
+ * NOTE
+ *  (1)This API return the last value set by kal_set_active_module_id().
+ * SEE ALSO
+ *  kal_set_active_module_id
+ ******************************************************************************/
+extern module_type kal_get_active_module_id(void);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_lisr_module_id
+ * DESCRIPTION
+ *  This routine is to get the irq's module id.
+ * PARAMETERS
+ *  irq_id: [IN] IRQ Code ID.
+ * RETURNS
+ *  irq's module id.
+ * SEE ALSO
+ * 
+ ******************************************************************************/
+extern module_type kal_get_lisr_module_id(kal_uint32 irq_id);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_task_by_moduleID
+ * DESCRIPTION
+ *  get taskid from task index.
+ * PARAMETERS
+ *  index: [IN] target task index.
+ * RETURNS
+ *  Return corresponding taskid. If the target task doesn't exist, return NULL.
+ * SEE ALSO
+ *  kal_get_task_index
+ ******************************************************************************/
+extern kal_taskid kal_get_task_by_moduleID(module_type modele_id);
+
+/*************************************************************************
+* <GROUP Functions>
+*
+* FUNCTION
+*  kal_task_mod_remap (Only for NL1 Build Load)
+* DESCRIPTION
+*  This function will remap module to new task.
+* PARAMETERS
+*  module_type: [IN] destination module Id
+*  module_type: [IN] source module Id
+* RETURNS
+*  None
+* GLOBALS AFFECTED
+*  mod_task_g
+* NOTE
+*  This Function is Only for NL1 Build Load.
+* SEE ALSO
+*  kal_update_task_mod
+*************************************************************************/
+extern void kal_task_mod_remap(module_type dst_mod_id, module_type src_mod_id);
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_task_total_number
+ * DESCRIPTION
+ *  query total task index number.
+ * PARAMETERS
+ *  NA.
+ * RETURNS
+ *  Return total task index number.
+ ******************************************************************************/
+extern kal_uint32 kal_get_task_total_number(void);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_send_msg_module_id_total_number
+ * DESCRIPTION
+ *  query total module id number that can send message.
+ * PARAMETERS
+ *  NA.
+ * RETURNS
+ *  Return total module id number that can send message.
+ ******************************************************************************/
+extern kal_uint32 kal_get_send_msg_module_id_total_number(void);
+/* DOM-NOT_FOR_SDK-END */
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_current_hisr_index
+ * DESCRIPTION
+ *  get current HISR index.
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  current HISR index.
+ * NOTE
+ *  (1)This API must be called from HISR.
+ ******************************************************************************/
+extern kal_uint32 kal_get_current_hisr_index(void);
+
+/*************************************************************************
+* <GROUP Functions>
+*
+* FUNCTION
+*  kal_check_stack
+*
+* DESCRIPTION
+*   This routine is to check whether the start of current thread stack is corrupted.
+*   If so, the system enter fatal error handling.
+*
+* PARAMETERS
+*  N/A
+* RETURNS
+*
+* GLOBALS AFFECTED
+*
+*************************************************************************/
+extern void kal_check_stack(void);
+
+ /*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_activate_hisr_index
+ * DESCRIPTION
+ *  activate specified HISR.
+ * PARAMETERS
+ *  ext_hisr: [IN] HISR index.
+ * RETURNS
+ *  N/A
+ ******************************************************************************/
+extern void kal_activate_hisr_index(kal_hisr ext_hisr);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_if_hisr
+ * DESCRIPTION
+ *  Identify if the current execution unit is a HISR.
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  KAL_FALSE if the current execution unit is a task, and KAL_TRUE if the current execution unit is a HISR.
+ * SEE ALSO
+ *  kal_if_lisr
+ ******************************************************************************/
+extern kal_bool kal_if_hisr(void);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_if_lisr
+ * DESCRIPTION
+ *  Identify if the current execution unit is a LISR.
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  KAL_FALSE if the current execution unit is a task or HISR, and KAL_TRUE if the current execution unit is a LISR.
+ * SEE ALSO
+ *  kal_if_hisr
+ ******************************************************************************/
+#if defined(__MTK_TARGET__)
+#if !defined(__kal_if_lisr__)
+#define __kal_if_lisr__
+#define kal_if_lisr() (miu_mfc0(MIU_C0_USERLOCAL) > 0)
+#endif
+#else
+extern kal_bool kal_if_lisr(void);
+#endif
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_task_affinity_by_moduleID
+ * DESCRIPTION
+ *  Query the hard affinity attribute of a certain task by its MOD ID.
+ * PARAMETERS
+ *  mod:            [IN] the module id of the task wanting to query its affinity
+ *  returnAffinity: [IN] the pointer to store the affinity query result
+ *                  the content will be kal_affinity_group enum
+ * RETURNS
+ *  KAL_ERROR if the MOD ID is invalid or the task is not created. KAL_SUCCESS if the query is succeed.
+ * SEE ALSO
+ * 
+ ******************************************************************************/
+kal_status kal_get_task_affinity_by_moduleID(module_type         mod,
+                                             kal_affinity_group *returnAffinity);
+
+
+/*************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+*  kal_get_current_context
+* DESCRIPTION
+*   This function return current context we are running.   
+* PARAMETERS
+*  N/A
+* RETURNS
+*    kal_sw_context_type
+*
+*************************************************************************/
+kal_sw_context_type kal_get_current_context(void);
+
+/* DOM_NOT_FOR_SDK-END */
+
+/*******************************************************************************
+ * Category 4 : Message Passing and Queue
+ *******************************************************************************/
+/* DOM-NOT_FOR_SDK-BEGIN */
+
+extern void *construct_int_local_para(kal_uint16      local_para_size,
+                                      kal_uint32      auto_reset,
+                                      const kal_char *file_ptr, kal_uint32 line);
+extern kal_bool free_int_local_para(local_para_struct *local_para_ptr,
+                                    const kal_char *file, kal_uint32 line);
+#define free_int_local_para_r free_int_local_para
+extern void *construct_int_peer_buff(kal_uint16 pdu_len, kal_uint16 header_len,
+                                     kal_uint16      tail_len,
+                                     const kal_char *file_name_ptr, kal_uint32 line);
+extern kal_bool free_int_peer_buff(peer_buff_struct *pdu_ptr, const kal_char *file,
+                                   kal_uint32 line);
+#define free_int_peer_buff_r free_int_peer_buff
+extern void destroy_int_ilm(ilm_struct *ilm_ptr, const kal_char *file_name,
+                            kal_uint32 line);
+
+#if defined(DEBUG_KAL) && defined(DEBUG_BUF2)
+#define __construct_local_para(local_para_size, direction)                         \
+    construct_int_local_para(                                                      \
+        local_para_size, ((kal_uint32)(direction) & (kal_uint32)TD_RESET) ? 1 : 0, \
+        __FILE__, __LINE__)
+#define __free_local_para(local_para) \
+    free_int_local_para(local_para, __FILE__, __LINE__)
+#define __construct_peer_buff(pdu_len, header_len, tail_len, direction) \
+    construct_int_peer_buff(pdu_len, header_len, tail_len, __FILE__, __LINE__)
+#define __free_peer_buff(peer_buff) free_int_peer_buff(peer_buff, __FILE__, __LINE__)
+#else /* !DEBUG_KAL || !DEBUG_BUF2 */
+#define __construct_local_para(local_para_size, direction)                         \
+    construct_int_local_para(                                                      \
+        local_para_size, ((kal_uint32)(direction) & (kal_uint32)TD_RESET) ? 1 : 0, \
+        NULL, 0)
+#define __free_local_para(local_para) free_int_local_para(local_para, NULL, 0)
+#define __construct_peer_buff(pdu_len, header_len, tail_len, direction) \
+    construct_int_peer_buff(pdu_len, header_len, tail_len, NULL, 0)
+#define __free_peer_buff(peer_buff) free_int_peer_buff(peer_buff, NULL, 0)
+#endif
+/* DOM-NOT_FOR_SDK-END */
+/* DOM-NOT_FOR_SDK-BEGIN */
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  construct_local_para
+ * DESCRIPTION
+ *  allocate a local_para structure which has local_para_size bytes including LOCAL_PARA_HDR.
+ * PARAMETERS
+ *  local_para_size: [IN] local_para structure size, this size includes LOCAL_PARA_HDR header,
+ *                   so the minimum size is sizeof(LOCAL_PARA_HDR) which imply the pdu part is 0 byte.
+ *  direction: [IN] a bitmask, each bit is defined as following values:
+ *             0 - nothing.
+ *             TD_RESET - to zero-initialize the pdu in this local_para structure.
+ * RETURNS
+ *  a local_para structure pointer. System enter fatal error handling if no enough memory.
+ * NOTE
+ *  (1) the prototype of this API is:
+ *       void* construct_local_para(kal_uint16 local_para_size, transfer_direction direction);
+ *  (2) local_para structure is a user-defined structure has a predefined header LOCAL_PARA_HDR
+ *      embedded in front of it:
+ *          struct bt_connected_info {
+ *              LOCAL_PARA_HDR; // this field must be the first elements in structure
+ *              // user-defined fields follows, pdu of this local_para structure
+ *          };
+ *      LOCAL_PARA_HDR is defined as:
+ *          #define LOCAL_PARA_HDR       kal_uint8  ref_count; kal_uint8 lp_reserved; kal_uint16  msg_len;
+ *      where msg_len is used to record the length of total structure including LOCAL_PARA_HDR,
+ *      ref_count is used to record how many pointers reference to this structure, you must
+ *      hold it on saving a private copy and free it after clear the private copy.
+ *  (3) The initial reference count in local_para structure is 1. It is a common error to
+ *      memset the whole structure to 0, if you want to zero-initialize pdu, pass TD_RESET
+ *      in direction to do that.
+ * SEE ALSO
+ *  free_local_para, hold_local_para, destroy_ilm, get_local_para_ptr
+ ******************************************************************************/
+#define construct_local_para(local_para_size, direction) \
+    __construct_local_para(local_para_size, direction)
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  free_local_para
+ * DESCRIPTION
+ *  decrease the local_para structure reference count, free the local_para if it reach 0.
+ * PARAMETERS
+ *  local_para        : [IN] local_para structure pointer.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1)The prototype of this API is:
+ *      void free_local_para(local_para_struct *local_para_ptr);
+ *  (2)To pass user-defined local_para structure pointer to it, you need an explicit type-cast:
+ *      free_local_para((local_para_struct *)ptr_to_bt_connected_info);
+ * SEE ALSO
+ *  construct_local_para, hold_local_para, destroy_ilm
+ ******************************************************************************/
+#define free_local_para(local_para) __free_local_para(local_para)
+#define free_local_para_set_null(local_para)                                \
+    do {                                                                    \
+        if (__free_local_para((local_para_struct *)local_para) == KAL_TRUE) \
+            local_para = NULL;                                              \
+    } while (0)
+#define free_local_para_r free_local_para
+#define free_local_para_r_set_null free_local_para_set_null
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  construct_peer_buff
+ * DESCRIPTION
+ *  allocate a peer_buff structure which has specified size in each part.
+ * PARAMETERS
+ *  pdu_len: [IN] pdu size.
+ *  header_len: [IN] reserve size in header.
+ *  tail_len: [IN] reserve size in tail.
+ *  direction: [IN] ignored, use 0.
+ * RETURNS
+ *  a peer_buff structure pointer. System enter fatal error handling if no enough memory.
+ * NOTE
+ *  (1) the prototype of this API is:
+ *       void* construct_peer_buff(kal_uint16 pdu_len, kal_uint16 header_len, kal_uint16 tail_len,
+ *                                  transfer_direction direction);
+ *  (2) peer_buff is a opaque type which has reference count. Please use related API to manipulate it.
+ *  (3) The initial reference count in peer_buff structure is 1.
+ *  (4) It will use the size (pdu_len + header_len + tail_len + 8) to allocate buffer from control buffer pool.
+ * SEE ALSO
+ *  free_peer_buff, hold_peer_buff, destroy_ilm, get_peer_buff_pdu, append_to_peer_buff,
+ *  prepend_to_peer_buff, remove_head_of_peer_buff, remove_tail_of_peer_buff, update_peer_buff_header
+ ******************************************************************************/
+#define construct_peer_buff(pdu_len, header_len, tail_len, direction) \
+    __construct_peer_buff(pdu_len, header_len, tail_len, direction)
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  free_peer_buff
+ * DESCRIPTION
+ *  decrease the peer_buff structure reference count, free the peer_buff if it reach 0.
+ * PARAMETERS
+ *  peer_buff        : [IN] peer_buff structure pointer.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1)The prototype of this API is:
+ *      void free_peer_buff(peer_buff_struct *peer_buff_ptr);
+ * SEE ALSO
+ *  construct_peer_buff, hold_peer_buff, destroy_ilm, get_peer_buff_pdu, append_to_peer_buff,
+ *  prepend_to_peer_buff, remove_head_of_peer_buff, remove_tail_of_peer_buff, update_peer_buff_header
+ ******************************************************************************/
+#define free_peer_buff(peer_buff) __free_peer_buff(peer_buff)
+#define free_peer_buff_set_null(peer_buff)           \
+    do {                                             \
+        if (__free_peer_buff(peer_buff) == KAL_TRUE) \
+            peer_buff = NULL;                        \
+    } while (0)
+#define free_peer_buff_r free_peer_buff
+#define free_peer_buff_r_set_null free_peer_buff_set_null
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  hold_local_para
+ * DESCRIPTION
+ *  If local_para_ptr is not NULL, increment its reference counter by 1.
+ * PARAMETERS
+ *  local_para_ptr        : [IN] local_para structure pointer.
+ * RETURN VALUES
+ *  KAL_TRUE if local_para_ptr is not NULL pointer, otherwise, KAL_FALSE.
+ * NOTE
+ *  (1) To pass user-defined local_para structure pointer to it, you need an explicit type-cast:
+ *      hold_local_para((local_para_struct *)ptr_to_bt_connected_info);
+ * SEE ALSO
+ *  construct_local_para, free_local_para, destroy_ilm
+ ******************************************************************************/
+extern kal_bool hold_local_para(local_para_struct *local_para_ptr);
+#define hold_local_para_r hold_local_para
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  get_local_para_ptr
+ * DESCRIPTION
+ *  retrieving start address & length of user-defined local_para structure.
+ * PARAMETERS
+ *  local_para_ptr        : [IN] local_para structure pointer.
+ *  local_para_len_ptr    : [OUT] to store length. If it is NULL, the length is not stored.
+ * RETURN VALUES
+ *  start address of user-defined local_para structure, It's equal to local_para_ptr.
+ * NOTE
+ *  (1)To pass user-defined local_para structure pointer to it, you need an explicit type-cast:
+ *      get_local_para_ptr((local_para_struct *)ptr_to_bt_connected_info, &len);
+ * SEE ALSO
+ *  construct_local_para
+ ******************************************************************************/
+void *get_local_para_ptr(local_para_struct *local_para_ptr,
+                         kal_uint16 *       local_para_len_ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  hold_peer_buff
+ * DESCRIPTION
+ *  If peer_buff_ptr is not NULL, increment its reference counter by 1.
+ * PARAMETERS
+ *  peer_buff_ptr        : [IN] peer_buff structure pointer.
+ * RETURN VALUES
+ *  KAL_TRUE if peer_buff_ptr is not NULL pointer, otherwise, KAL_FALSE.
+ * NOTE
+ *  N/A
+ * SEE ALSO
+ *  construct_peer_buff, free_peer_buff, destroy_ilm
+ ******************************************************************************/
+extern kal_bool hold_peer_buff(peer_buff_struct *peer_buff_ptr);
+#define hold_peer_buff_r hold_peer_buff
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  get_peer_buff_pdu
+ * DESCRIPTION
+ *  retrieving start address & length of pdu in peer buffer.
+ * PARAMETERS
+ *  peer_buff_ptr        : [IN] peer_buff structure pointer.
+ *  length_ptr           : [OUT] to store pdu's length. If it is NULL, the length is not stored.
+ * RETURN VALUES
+ *  start address of pdu in peer buffer.
+ * SEE ALSO
+ *  construct_peer_buff, free_peer_buff, hold_peer_buff, destroy_ilm, append_to_peer_buff,
+ *  prepend_to_peer_buff, remove_head_of_peer_buff, remove_tail_of_peer_buff, update_peer_buff_header
+ ******************************************************************************/
+void *get_peer_buff_pdu(peer_buff_struct *peer_buff_ptr, kal_uint16 *length_ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  prepend_to_peer_buff
+ * DESCRIPTION
+ *  prepend data to head of peer_buff. On success, pdu length increases header_len bytes,
+ *  and free space at head decreases header_len bytes.
+ * PARAMETERS
+ *  peer_buff_ptr        : [IN] peer_buff structure pointer.
+ *  header_data_ptr      : [IN] data appended.
+ *  header_len           : [IN] length of data appended.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  If the free head room is smaller than header_len, system enter fatal error handling.
+ * SEE ALSO
+ *  construct_peer_buff, free_peer_buff, hold_peer_buff, destroy_ilm, get_peer_buff_pdu,
+ *  append_to_peer_buff, remove_head_of_peer_buff, remove_tail_of_peer_buff, update_peer_buff_header
+ ******************************************************************************/
+extern void prepend_to_peer_buff(peer_buff_struct *peer_buff_ptr,
+                                 void *header_data_ptr, kal_uint16 header_len);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  append_to_peer_buff
+ * DESCRIPTION
+ *  append data to tail of peer_buff, On success, pdu length increases tail_len bytes,
+ *  and free space at tail decreases tail_len bytes.
+ * PARAMETERS
+ *  peer_buff_ptr        : [IN] peer_buff structure pointer.
+ *  tail_data_ptr        : [IN] data appended.
+ *  tail_len             : [IN] length of data appended.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  If the free tail room is smaller than tail_len, system enter fatal error handling.
+ * SEE ALSO
+ *  construct_peer_buff, free_peer_buff, hold_peer_buff, destroy_ilm, get_peer_buff_pdu,
+ *  prepend_to_peer_buff, remove_head_of_peer_buff, remove_tail_of_peer_buff, update_peer_buff_header
+ ******************************************************************************/
+extern void append_to_peer_buff(peer_buff_struct *peer_buff_ptr, void *tail_data_ptr,
+                                kal_uint16 tail_len);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  remove_head_of_peer_buff
+ * DESCRIPTION
+ *  remove data at head of peer_buff. On success, pdu length decreases head_len bytes,
+ *  and free space at head increases head_len bytes.
+ * PARAMETERS
+ *  peer_buff_ptr        : [IN] peer_buff structure pointer.
+ *  head_len             : [IN] length of data to remove.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1)If the pdu size is smaller than head_len, system enter fatal error handling.
+ *  (2)This API replaces remove_hdr_of_peer_buff(). And remove_hdr_of_peer_buff() is deprecated,
+ *     it will be removed from next release.
+ * SEE ALSO
+ *  construct_peer_buff, free_peer_buff, hold_peer_buff, destroy_ilm, get_peer_buff_pdu,
+ *  prepend_to_peer_buff, append_to_peer_buff, remove_tail_of_peer_buff, update_peer_buff_header
+ ******************************************************************************/
+extern void remove_head_of_peer_buff(peer_buff_struct *peer_buff_ptr,
+                                     kal_uint16        head_len);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  remove_tail_of_peer_buff
+ * DESCRIPTION
+ *  remove data at tail of peer_buff. On success, pdu length decreases tail_len bytes,
+ *  and free space at tail increases tail_len bytes.
+ * PARAMETERS
+ *  peer_buff_ptr        : [IN] peer_buff structure pointer.
+ *  tail_len             : [IN] length of data to remove.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  If the pdu size is smaller than tail_len, system enter fatal error handling.
+ * SEE ALSO
+ *  construct_peer_buff, free_peer_buff, hold_peer_buff, destroy_ilm, get_peer_buff_pdu,
+ *  prepend_to_peer_buff, append_to_peer_buff, remove_head_of_peer_buff, update_peer_buff_header
+ ******************************************************************************/
+extern void remove_tail_of_peer_buff(peer_buff_struct *peer_buff_ptr,
+                                     kal_uint16        tail_len);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  update_peer_buff_header
+ * DESCRIPTION
+ *  Reinitialize peer buffer, reset size of free header space, pdu, free tail space to new values.
+ * PARAMETERS
+ *  peer_buff_ptr        : [IN] peer_buff structure pointer.
+ *  new_head_len         : [IN] new head size after update.
+ *  new_pdu_len          : [IN] new pdu size after update.
+ *  new_tail_len         : [IN] new tail size after update.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1)If total size is bigger than original size, system enter fatal error handling.
+ * SEE ALSO
+ *  construct_peer_buff, free_peer_buff, hold_peer_buff, destroy_ilm, get_peer_buff_pdu,
+ *  prepend_to_peer_buff, append_to_peer_buff, remove_head_of_peer_buff, remove_tail_of_peer_buff
+ ******************************************************************************/
+extern void update_peer_buff_header(peer_buff_struct *peer_buff_ptr,
+                                    kal_uint16 new_head_len, kal_uint16 new_pdu_len,
+                                    kal_uint16 new_tail_len);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_send_ext_queue
+ * DESCRIPTION
+ *  send a ILM message to tail of destination task's ext queue.
+ * PARAMETERS
+ *  ilm_ptr             : [IN] the ILM message to be sent.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) The ILM messages is appended to tail of the queue.
+ *  (2) If the destination queue is full, system enter fatal error handling.
+ *  (3) The use of allocate_ilm()/cancel_ilm() is deprecated,
+ *  (4) Recommend use msg_send() , msg_send6() series, use this function as 
+ *      last choice for special condition
+ * SEE ALSO
+ *  msg_send_to_head, msg_send6, msg_send_to_head6
+ ******************************************************************************/
+kal_bool msg_send_ext_queue(ilm_struct *ilm_ptr);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_send
+ * DESCRIPTION
+ *  send a ILM message to tail of destination task's queue.
+ *  Refer to NOTE about which queue (extq or intq) the message sent to.
+ * PARAMETERS
+ *  ilm_ptr             : [IN] the ILM message to be sent.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) This API select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
+ *           internal queue of the task is not NULL, the message is sent to internal queue.
+ *        b. Otherwise, the message is sent to external queue.
+ *  (2) The ILM messages is appended to tail of the queue.
+ *  (3) If the destination queue is full, system enter fatal error handling.
+ *  (4) The use of allocate_ilm()/cancel_ilm() is deprecated,
+ * SEE ALSO
+ *  msg_send_to_head, msg_send6, msg_send_to_head6
+ ******************************************************************************/
+kal_bool msg_send(ilm_struct *ilm_ptr);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_send_custom
+ * DESCRIPTION
+ *  send a ILM message to tail of destination task's queue.
+ *  Refer to NOTE about which queue (extq or intq) the message sent to.
+ *  Selectable custom DHL logging option.
+ * PARAMETERS
+ *  ilm_ptr             : [IN] the ILM message to be sent.
+ *  log_option          : [IN] the custom logging to be used.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) This API select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
+ *           internal queue of the task is not NULL, the message is sent to internal queue.
+ *        b. Otherwise, the message is sent to external queue.
+ *  (2) The ILM messages is appended to tail of the queue.
+ *  (3) If the destination queue is full, system enter fatal error handling.
+ *  (4) The use of allocate_ilm()/cancel_ilm() is deprecated,
+ *  (5) Only use this if custom DHL logging is needed for the ILM. Normally use msg_send
+ * SEE ALSO
+ *  msg_send_to_head, msg_send6, msg_send_to_head6
+ ******************************************************************************/
+#if defined(__DHL_MODULE__)
+kal_bool msg_send_custom(ilm_struct *ilm_ptr, e_custom_ilm_trace_option log_option);
+#else
+#define msg_send_custom(ip, lo) msg_send((ip))
+#endif
+
+/*******************************************************************************
+ * <GROUP Functions>
+ * 
+ * FUNCTION
+ *  msg_send_adt
+ * DESCRIPTION
+ *  send a ILM message to tail of destination task's queue. 
+ *  sender provide translator callback to translate user defined structure
+ *  in ILM local/peer parameter to ADT for logging.
+ *  sender provide free callback to free user defined structure in ILM 
+ *  local/peer parameter when the ILM is trapped during UT.
+ *  Refer to NOTE about which queue (extq or intq) the message sent to.
+ * PARAMETERS
+ *  ilm_ptr             : [IN] the ILM message to be sent.
+ *  translator_cb       : [IN] translator callback to translate user defined structure to ADT
+ *  free_cb             : [IN] free callback to free user defined structure
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) This API select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the 
+ *           internal queue of the task is not NULL, the message is sent to internal queue.
+ *        b. Otherwise, the message is sent to external queue.
+ *  (2) The ILM messages is appended to tail of the queue.
+ *  (3) If the destination queue is full, system enter fatal error handling.
+ *  (4) This API replaces msg_send_ext_queue/msg_send_int_queue(). 
+ *      They will be removed from next release.
+ *  (5) The use of allocate_ilm()/cancel_ilm() is deprecated, 
+ *      They will be removed from next release.
+ *  (6) If using the msg_send_adt has error, replace msg_send_adt with msg_send
+ *      and test again. If the msg_send is OK but msg_send_adt is not, please
+ *      contact the adt provider(TST/DHL module owner)
+ * SEE ALSO
+ *  msg_send_to_head, msg_send6, msg_send_to_head6
+ ******************************************************************************/
+#ifdef __TST_MODULE__
+kal_bool msg_send_adt(ilm_struct *                  ilm_ptr,
+                      translator_adt_enc_callback_t translator_cb,
+                      ilm_free_callback_t           free_cb);
+#else /* else of __TST_MODULE__ */
+#define msg_send_adt(ilm_ptr, translator_cb, free_cb) msg_send(ilm_ptr)
+#endif /* end of "else of __TST_MODULE__" */
+
+/******************************************************************************* 
+ * <GROUP Functions> 
+ * 
+ * FUNCTION 
+ *  msg_send_to_int_head 
+ * DESCRIPTION 
+ *  send a ILM message to head of destination task's internal queue. 
+ * PARAMETERS 
+ *  ilm_ptr             : [IN] the ILM message to be sent. 
+ * RETURN VALUES 
+ *  N/A 
+ * NOTE 
+ *  (1) If the ILM is sent to external queue, system enter fatal error handling.
+ *      It uses similar logic as msg_send to select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to different tasks, 
+ *           then enter error handling.
+ *        b. Otherwise, the message is sent to head of internal queue.
+ *  (2) If the destination queue is full, system enter fatal error handling.
+ * SEE ALSO 
+ *  msg_send_to_int_head6 
+ ******************************************************************************/
+kal_bool msg_send_to_int_head(ilm_struct *ilm_ptr);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_send_to_head
+ * DESCRIPTION
+ *  send a ILM message to head of destination task's external queue.
+ * PARAMETERS
+ *  ilm_ptr             : [IN] the ILM message to be sent.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) If the ILM is sent to internal queue, system enter fatal error handling.
+ *      It uses similar logic as msg_send to select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
+ *           internal queue of the task is not NULL, then enter error handling.
+ *        b. Otherwise, the message is sent to head of external queue.
+ *  (2) If the destination queue is full, system enter fatal error handling.
+ * SEE ALSO
+ *  msg_send, msg_send6, msg_send_to_head6
+ ******************************************************************************/
+kal_bool msg_send_to_head(ilm_struct *ilm_ptr);
+
+/******************************************************************************* 
+ * <GROUP Functions> 
+ * 
+ * FUNCTION 
+ *  msg_send_to_int_head6 
+ * DESCRIPTION 
+ *  send a ILM message to head of destination task's internal queue. 
+ *  this function is the same as msg_send_to_int_head except assigning content of ilm directly.
+ * PARAMETERS 
+ *  src_mod_id           : [IN] source module id. 
+ *  dest_mod_id          : [IN] destination module id. 
+ *  sap_id               : [IN] service access point id. 
+ *  msg_id               : [IN] message id. 
+ *  local_para_ptr       : [IN] local_para structure pointer. 
+ *  peer_buff_ptr        : [IN] peer_buff structure pointer. 
+ * RETURN VALUES 
+ *  N/A 
+ * NOTE
+ * SEE ALSO 
+ *  msg_send_to_int_head 
+ ******************************************************************************/
+kal_bool msg_send_to_int_head6(module_type _src_mod_id, module_type _dest_mod_id,
+                               sap_type _sap_id, msg_type _msg_id,
+                               local_para_struct *_local_para_ptr,
+                               peer_buff_struct * _peer_buff_ptr);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_send6
+ * DESCRIPTION
+ *  send a ILM message to tail of destination task's queue.
+ *  Refer to NOTE about which queue (extq or intq) the message sent to.
+ * PARAMETERS
+ *  src_mod_id           : [IN] source module id.
+ *  dest_mod_id          : [IN] destination module id.
+ *  sap_id               : [IN] service access point id.
+ *  msg_id               : [IN] message id.
+ *  local_para_ptr       : [IN] local_para structure pointer.
+ *  peer_buff_ptr        : [IN] peer_buff structure pointer.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) This API select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
+ *           internal queue of the task is not NULL, the message is sent to internal queue.
+ *        b. Otherwise, the message is sent to external queue.
+ *  (2) The ILM messages is appended to tail of the queue.
+ *  (3) If the destination queue is full, system enter fatal error handling.
+ *  (4) This API replaces msg_send_ext_queue/msg_send_int_queue().
+ *  (5) The use of allocate_ilm()/cancel_ilm() is deprecated,
+ * SEE ALSO
+ *  msg_send, msg_send4, msg_send5, msg_send_to_head, msg_send_to_head6
+ ******************************************************************************/
+kal_bool msg_send6(module_type _src_mod_id, module_type _dest_mod_id,
+                   sap_type _sap_id, msg_type _msg_id,
+                   local_para_struct *_local_para_ptr,
+                   peer_buff_struct * _peer_buff_ptr);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_send6_custom
+ * DESCRIPTION
+ *  send a ILM message to tail of destination task's queue.
+ *  Refer to NOTE about which queue (extq or intq) the message sent to.
+ *  Selectable custom DHL logging option.
+ * PARAMETERS
+ *  src_mod_id           : [IN] source module id.
+ *  dest_mod_id          : [IN] destination module id.
+ *  sap_id               : [IN] service access point id.
+ *  msg_id               : [IN] message id.
+ *  local_para_ptr       : [IN] local_para structure pointer.
+ *  peer_buff_ptr        : [IN] peer_buff structure pointer.
+ *  log_option          : [IN] the custom logging to be used.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) This API select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
+ *           internal queue of the task is not NULL, the message is sent to internal queue.
+ *        b. Otherwise, the message is sent to external queue.
+ *  (2) The ILM messages is appended to tail of the queue.
+ *  (3) If the destination queue is full, system enter fatal error handling.
+ *  (4) This API replaces msg_send_ext_queue/msg_send_int_queue().
+ *  (5) The use of allocate_ilm()/cancel_ilm() is deprecated,
+ *  (6) Only use this if custom DHL logging is needed for the ILM. Normally use msg_send
+ * SEE ALSO
+ *  msg_send, msg_send4, msg_send5, msg_send_to_head, msg_send_to_head6
+ ******************************************************************************/
+#if defined(__DHL_MODULE__)
+kal_bool msg_send6_custom(module_type _src_mod_id, module_type _dest_mod_id,
+                          sap_type _sap_id, msg_type _msg_id,
+                          local_para_struct *       _local_para_ptr,
+                          peer_buff_struct *        _peer_buff_ptr,
+                          e_custom_ilm_trace_option log_option);
+#else
+#define msg_send6_custom(sm, dm, si, mi, lp, pb, lo) \
+    msg_send6((sm), (dm), (si), (mi), (lp), (pb))
+#endif
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_send5
+ * DESCRIPTION
+ *  same with msg_send6 with _peer_buff_ptr = NULL.
+ * NOTE
+ * SEE ALSO
+ *  msg_send, msg_send4, msg_send6
+ ******************************************************************************/
+kal_bool msg_send5(module_type _src_mod_id, module_type _dest_mod_id,
+                   sap_type _sap_id, msg_type _msg_id,
+                   local_para_struct *_local_para_ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_send4
+ * DESCRIPTION
+ *  same with msg_send6 with _local_para_ptr = NULL & _peer_buff_ptr = NULL.
+ * SEE ALSO
+ *  msg_send, msg_send5, msg_send6
+ ******************************************************************************/
+kal_bool msg_send4(module_type _src_mod_id, module_type _dest_mod_id,
+                   sap_type _sap_id, msg_type _msg_id);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_send_to_head6
+ * DESCRIPTION
+ *  send a ILM message to head of destination task's queue.
+ * PARAMETERS
+ *  src_mod_id           : [IN] source module id.
+ *  dest_mod_id          : [IN] destination module id.
+ *  sap_id               : [IN] service access point id.
+ *  msg_id               : [IN] message id.
+ *  local_para_ptr       : [IN] local_para structure pointer.
+ *  peer_buff_ptr        : [IN] peer_buff structure pointer.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) If the ILM is sent to internal queue, system enter fatal error handling.
+ *      It uses same logic as msg_send to select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
+ *           internal queue of the task is not NULL, the message is sent to internal queue.
+ *        b. Otherwise, the message is sent to external queue.
+ *  (2) If the destination queue is full, system enter fatal error handling.
+ *  (3) This API replaces msg_send_ext_queue_to_head().
+ *  (4) The use of allocate_ilm()/cancel_ilm() is deprecated,
+ * SEE ALSO
+ *  msg_send, msg_send6, msg_send_to_head
+ ******************************************************************************/
+kal_bool msg_send_to_head6(module_type _src_mod_id, module_type _dest_mod_id,
+                           sap_type _sap_id, msg_type _msg_id,
+                           local_para_struct *_local_para_ptr,
+                           peer_buff_struct * _peer_buff_ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_send_to_head5
+ * DESCRIPTION
+ *  same with msg_send_to_head6 with _peer_buff_ptr = NULL.
+ * NOTE
+ * SEE ALSO
+ *  msg_send_to_head, msg_send_to_head4, msg_send_to_head6
+ ******************************************************************************/
+kal_bool msg_send_to_head5(module_type _src_mod_id, module_type _dest_mod_id,
+                           sap_type _sap_id, msg_type _msg_id,
+                           local_para_struct *_local_para_ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_send_to_head4
+ * DESCRIPTION
+ *  same with msg_send_to_head6 with _local_para_ptr = NULL & _peer_buff_ptr = NULL.
+ * NOTE
+ * SEE ALSO
+ *  msg_send_to_head, msg_send_to_head5, msg_send_to_head6
+ ******************************************************************************/
+kal_bool msg_send_to_head4(module_type _src_mod_id, module_type _dest_mod_id,
+                           sap_type _sap_id, msg_type _msg_id);
+
+/******************************************************************************
+*
+ * <GROUP Functions>
+ * 
+ * FUNCTION
+ *  msg_send_inline6
+ * DESCRIPTION
+ *  send a inline-ILM message to tail of destination task's queue. 
+ *  Refer to NOTE about which queue (extq or intq) the message sent to.
+ * PARAMETERS
+ *  src_mod_id           : [IN] source module id.
+ *  dest_mod_id          : [IN] destination module id.
+ *  sap_id               : [IN] service access point id.
+ *  msg_id               : [IN] message id.
+ *  data                 : [IN] data to be copy in inline-ILM. 
+ *  datalen              : [IN] data length, it's maximum value is MSG_INLINE_ILM_MAX_PAYLOAD.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) This API select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the 
+ *           internal queue of the task is not NULL, the message is sent to internal queue.
+ *        b. Otherwise, the message is sent to external queue.
+ *  (2) The ILM messages is appended to tail of the queue.
+ *  (3) If the destination queue is full, system enter fatal error handling.
+ *  (4) The inline data length specified by datalen is not recorded in destination ILM messages.
+ *      Its user's responsibility to know what the inline data is.
+ *  (5) The use of allocate_ilm()/cancel_ilm() is deprecated, 
+ * SEE ALSO
+ *  msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5, 
+ *	msg_is_inline, msg_get_inline_data
+ *  msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
+ *  msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
+ 
+******************************************************************************/
+kal_bool msg_send_inline6(module_type src_mod, module_type dest_mod, sap_type sap_id,
+                          msg_type msg_id, void *data, kal_uint32 datalen);
+
+/******************************************************************************
+*
+ * <GROUP Functions>
+ * 
+ * FUNCTION
+ *  msg_send_inline_to_head6
+ * DESCRIPTION
+ *  send a ILM message to head of destination task's queue. 
+ * PARAMETERS
+ *  src_mod_id           : [IN] source module id.
+ *  dest_mod_id          : [IN] destination module id.
+ *  sap_id               : [IN] service access point id.
+ *  msg_id               : [IN] message id.
+ *  data                 : [IN] data to be copy in inline-ILM. 
+ *  datalen              : [IN] data length, it's maximum value is MSG_INLINE_ILM_MAX_PAYLOAD.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) If the ILM is sent to internal queue, system enter fatal error handling.
+ *      It uses same logic as msg_send to select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the 
+ *           internal queue of the task is not NULL, the message is sent to internal queue.
+ *        b. Otherwise, the message is sent to external queue.
+ *  (2) If the destination queue is full, system enter fatal error handling.
+ *  (3) The inline data length specified by datalen is not recorded in destination ILM messages.
+ *      Its user's responsibility to know what the inline data is.
+ *  (4) The use of allocate_ilm()/cancel_ilm() is deprecated, 
+ * SEE ALSO
+ *  msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5, 
+ *	msg_is_inline, msg_get_inline_data
+ *  msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6,msg_send_8bytes_inline_to_head6
+ *  msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
+ 
+******************************************************************************/
+kal_bool msg_send_inline_to_head6(module_type src_mod, module_type dest_mod,
+                                  sap_type sap_id, msg_type msg_id, void *data,
+                                  kal_uint32 datalen);
+
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_send_inline5
+ * DESCRIPTION
+ *  send a inline-ILM message to tail of destination task's queue.
+ *  Refer to NOTE about which queue (extq or intq) the message sent to.
+ * PARAMETERS
+ *  src_mod_id           : [IN] source module id.
+ *  dest_mod_id          : [IN] destination module id.
+ *  msg_id               : [IN] message id.
+ *  data                 : [IN] data to be copy in inline-ILM.
+ *  datalen              : [IN] data length, it's maximum value is MSG_INLINE_ILM_MAX_PAYLOAD.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) This API select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
+ *           internal queue of the task is not NULL, the message is sent to internal queue.
+ *        b. Otherwise, the message is sent to external queue.
+ *  (2) The ILM messages is appended to tail of the queue.
+ *  (3) If the destination queue is full, system enter fatal error handling.
+ *  (4) The inline data length specified by datalen is not recorded in destination ILM messages.
+ *      Its user's responsibility to know what the inline data is.
+ *  (5) The use of allocate_ilm()/cancel_ilm() is deprecated,
+ * SEE ALSO
+ *  msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5, 
+ *	msg_is_inline, msg_get_inline_data
+ *  msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
+ *  msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
+ 
+******************************************************************************/
+#define msg_send_inline5(src_mod, dest_mod, msg_id, data, datalen) \
+    msg_send_inline6(src_mod, dest_mod, INLINE_ILM_SAP, msg_id, data, datalen)
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_send_inline_to_head5
+ * DESCRIPTION
+ *  send a ILM message to head of destination task's queue.
+ * PARAMETERS
+ *  src_mod_id           : [IN] source module id.
+ *  dest_mod_id          : [IN] destination module id.
+ *  msg_id               : [IN] message id.
+ *  data                 : [IN] data to be copy in inline-ILM.
+ *  datalen              : [IN] data length, it's maximum value is MSG_INLINE_ILM_MAX_PAYLOAD.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) If the ILM is sent to internal queue, system enter fatal error handling.
+ *      It uses same logic as msg_send to select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the
+ *           internal queue of the task is not NULL, the message is sent to internal queue.
+ *        b. Otherwise, the message is sent to external queue.
+ *  (2) If the destination queue is full, system enter fatal error handling.
+ *  (3) The inline data length specified by datalen is not recorded in destination ILM messages.
+ *      Its user's responsibility to know what the inline data is.
+ *  (4) The use of allocate_ilm()/cancel_ilm() is deprecated,
+ * SEE ALSO
+ *  msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5, 
+ *	msg_is_inline, msg_get_inline_data
+ *  msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
+ *  msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
+ 
+******************************************************************************/
+#define msg_send_inline_to_head5(src_mod, dest_mod, sap_id, msg_id, data, datalen) \
+    msg_send_inline_to_head6(src_mod, dest_mod, INLINE_ILM_SAP, msg_id, data,      \
+                             datalen)
+
+/******************************************************************************
+*
+ * <GROUP Functions>
+ * 
+ * FUNCTION
+ *  msg_send_8bytes_inline6
+ * DESCRIPTION
+ *  send a inline-ILM message to tail of destination task's queue. 
+ *  Refer to NOTE about which queue (extq or intq) the message sent to.
+ * PARAMETERS
+ *  src_mod_id           : [IN] source module id.
+ *  dest_mod_id          : [IN] destination module id.
+ *  sap_id               : [IN] service access point id.
+ *  msg_id               : [IN] message id.
+ *  data1                : [IN] first 4-byte data to be copy in inline-ILM. 
+ *  data2                : [IN] second 4-byte data to be copy in inline-ILM. 
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) This API select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the 
+ *           internal queue of the task is not NULL, the message is sent to internal queue.
+ *        b. Otherwise, the message is sent to external queue.
+ *  (2) The ILM messages is appended to tail of the queue.
+ *  (3) If the destination queue is full, system enter fatal error handling.
+ *  (4) The use of allocate_ilm()/cancel_ilm() is deprecated, 
+ *  (5) The inline data length is not recorded in destination ILM messages.
+ *      Its user's responsibility to know what the inline data is.
+ * SEE ALSO
+ *  msg_send, msg_send6, msg_send_to_head6, msg_send_inline5,msg_send_inline_tp_head5, 
+ *	msg_is_inline, msg_get_inline_data
+ *  msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
+ *  msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
+ 
+******************************************************************************/
+kal_bool msg_send_8bytes_inline6(module_type src_mod, module_type dest_mod,
+                                 sap_type sap_id, msg_type msg_id, kal_uint32 data1,
+                                 kal_uint32 data2);
+
+/******************************************************************************
+*
+ * <GROUP Functions>
+ * 
+ * FUNCTION
+ *  msg_send_8bytes_inline6_custom
+ * DESCRIPTION
+ *  send a inline-ILM message to tail of destination task's queue. 
+ *  Refer to NOTE about which queue (extq or intq) the message sent to.
+ *  Uses custom logging based on the logging option.
+ * PARAMETERS
+ *  src_mod_id           : [IN] source module id.
+ *  dest_mod_id          : [IN] destination module id.
+ *  sap_id               : [IN] service access point id.
+ *  msg_id               : [IN] message id.
+ *  data1                : [IN] first 4-byte data to be copy in inline-ILM. 
+ *  data2                : [IN] second 4-byte data to be copy in inline-ILM. 
+ *  log_option           : [IN] custom logging option
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) This API select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task, and the 
+ *           internal queue of the task is not NULL, the message is sent to internal queue.
+ *        b. Otherwise, the message is sent to external queue.
+ *  (2) The ILM messages is appended to tail of the queue.
+ *  (3) If the destination queue is full, system enter fatal error handling.
+ *  (4) The use of allocate_ilm()/cancel_ilm() is deprecated, 
+ *  (5) The inline data length is not recorded in destination ILM messages.
+ *      Its user's responsibility to know what the inline data is.
+ * SEE ALSO
+ *  msg_send, msg_send6, msg_send_to_head6, msg_send_inline5,msg_send_inline_tp_head5, 
+ *	msg_is_inline, msg_get_inline_data
+ *  msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
+ *  msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
+ 
+******************************************************************************/
+#if defined(__DHL_MODULE__)
+kal_bool msg_send_8bytes_inline6_custom(module_type src_mod, module_type dest_mod,
+                                        sap_type sap_id, msg_type msg_id,
+                                        kal_uint32 data1, kal_uint32 data2,
+                                        e_custom_ilm_trace_option log_option);
+#else
+#define msg_send_8bytes_inline6_custom(sm, dm, si, mi, d1, d2, lo) \
+    msg_send_8bytes_inline6((sm), (dm), (si), (mi), (d1), (d2))
+#endif
+
+
+/******************************************************************************
+*
+ * <GROUP Functions>
+ * 
+ * FUNCTION
+ *  msg_send_8bytes_inline_to_head6
+ * DESCRIPTION
+ *  send a ILM message to head of destination task's queue. 
+ * PARAMETERS
+ *  src_mod_id           : [IN] source module id.
+ *  dest_mod_id          : [IN] destination module id.
+ *  sap_id               : [IN] service access point id.
+ *  msg_id               : [IN] message id.
+ *  data1                : [IN] first 4-byte data to be copy in inline-ILM. 
+ *  data2                : [IN] second 4-byte data to be copy in inline-ILM. 
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) If the ILM is sent to internal queue, system enter fatal error handling.
+ *      It uses same logic as msg_send to select queue based on following criteria:
+ *        a. If src_mod_id and dest_mod_id in ilm_ptr mapped to same task,and the 
+ *           internal queue of the task is not NULL, the message is sent to internal queue.
+ *        b. Otherwise, the message is sent to external queue.
+ *  (2) If the destination queue is full, system enter fatal error handling.
+ *  (3) The use of allocate_ilm()/cancel_ilm() is deprecated, 
+ *  (4) The inline data length is not recorded in destination ILM messages.
+ *      Its user's responsibility to know what the inline data is.
+ * SEE ALSO
+ *  msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5, 
+ *	msg_is_inline, msg_get_inline_data
+ *  msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
+ *  msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
+  
+******************************************************************************/
+kal_bool msg_send_8bytes_inline_to_head6(module_type src_mod, module_type dest_mod,
+                                         sap_type sap_id, msg_type msg_id,
+                                         kal_uint32 data1, kal_uint32 data2);
+
+/******************************************************************************
+*
+ * <GROUP Functions>
+ * 
+ * FUNCTION
+ *  msg_get_inline_4bytes_data1
+ * DESCRIPTION
+ *  Get the inline first 4-byte data value in ILM message. 
+ * PARAMETERS
+ *  ilm_ptr              : [IN] ILM message pointer.
+ * RETURN VALUES
+ *  First 4-byte data value. If it's not an inline-ILM, system enter fatal error handling.
+ * NOTE
+ *  (1) Users must pass a inline-ILM to this function.
+ *  (2) The inline data length is not recorded in ILM messages.
+ *      Its user's responsibility to know what the inline data is.
+ *
+ * SEE ALSO
+ *  msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5, 
+ *	msg_is_inline, msg_get_inline_data
+ *  msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6,msg_send_8bytes_inline_to_head6
+ *  msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
+ 
+******************************************************************************/
+kal_uint32 msg_get_inline_4bytes_data1(ilm_struct *ilm_ptr);
+
+/******************************************************************************
+*
+ * <GROUP Functions>
+ * 
+ * FUNCTION
+ *  msg_get_inline_4bytes_data2
+ * DESCRIPTION
+ *  Get the inline second 4-byte data value in ILM message. 
+ * PARAMETERS
+ *  ilm_ptr              : [IN] ILM message pointer.
+ * RETURN VALUES
+ *  Second 4-byte data value. If it's not an inline-ILM, system enter fatal error handling.
+ * NOTE
+ *  (1) Users must pass a inline-ILM to this function.
+ *  (2) The inline data length is not recorded in ILM messages.
+ *      Its user's responsibility to know what the inline data is.
+ *
+ * SEE ALSO
+ *  msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5, 
+ *	msg_is_inline, msg_get_inline_data
+ *  msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
+ *  msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
+ 
+******************************************************************************/
+kal_uint32 msg_get_inline_4bytes_data2(ilm_struct *ilm_ptr);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_is_inline
+ * DESCRIPTION
+ *  judge whether is a inline-ILM or not.
+ * PARAMETERS
+ *  ilm_ptr              : [IN] ILM message pointer.
+ * RETURN VALUES
+ *  KAL_TRUE : this is a inline-ILM.
+ *  KAL_FALSE : this isn't a inline-ILM.
+ * NOTE
+ *  (1) The prototype of this API is:
+ *       kal_bool msg_is_inline(ilm_struct *ilm_ptr);
+ *  (2) inline-ILM is identified by sap_id, always use this API to do this, never use
+ *      sap_id comparison directly since this will change in future.
+ * SEE ALSO
+ *  msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5, 
+ *	msg_is_inline, msg_get_inline_data
+ *  msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
+ *  msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
+ 
+******************************************************************************/
+#define msg_is_inline(ilm_ptr)                                                \
+    (((ilm_ptr)->sap_id & (INLINE_ILM_FLAG_SAP | INLINE_CUSTOM_ILM_FLAG_SAP)) \
+         ? KAL_TRUE                                                           \
+         : KAL_FALSE)
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_get_inline_data
+ * DESCRIPTION
+ *  Get the inline data pointer in ILM message.
+ * PARAMETERS
+ *  ilm_ptr              : [IN] ILM message pointer.
+ * RETURN VALUES
+ *  inline data pointer. If it's not an inline-ILM, system enter fatal error handling.
+ * NOTE
+ *  (1) Users must pass a inline-ILM to this function.
+ *  (2) The inline data length is not recorded in ILM messages.
+ *      Its user's responsibility to know what the inline data is.
+ *
+ * SEE ALSO
+ *  msg_send, msg_send6, msg_send_to_head6, msg_send_inline5, msg_send_inline_tp_head5, 
+ *	msg_is_inline, msg_get_inline_data
+ *  msg_send_inline6, msg_send_inline_to_head6, msg_send_8bytes_inline6, msg_send_8bytes_inline_to_head6
+ *  msg_get_inline_4bytes_data1, msg_get_inline_4bytes_data2
+ ******************************************************************************/
+void *msg_get_inline_data(ilm_struct *ilm_ptr);
+
+
+#if defined(DEBUG_KAL) && defined(DEBUG_ITC)
+#define __destroy_ilm(ilm_ptr) \
+    destroy_int_ilm((ilm_ptr), (kal_char *)__FILE__, __LINE__);
+#else
+#define __destroy_ilm(ilm_ptr) destroy_int_ilm((ilm_ptr), NULL, 0);
+#endif
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  destroy_ilm
+ * DESCRIPTION
+ *  destroy an ILM. ref_count would minus 1 if buffer pointer is not NULL, buffer 
+ *  instance peer_buff_ptr or local_para_ptr will truly be released only if 
+ *  ref_count is zero.
+ * PARAMETERS
+ *  ilm_ptr        : [IN] ILM message pointer.
+ * RETURN VALUES
+ *  N/A
+ * NOTE
+ *  (1) The content pointed by ilm_ptr is not free.
+ *  (2) It will return immediately without destroy the ILM if
+ *      (2-A) the ILM is sent from timer (i.e. ilm_ptr->src_mod_id == MOD_TIMER)
+ *      (2-B) the ILM is an inline ILM (i.e. (ilm_ptr->sap_id & INLINE_ILM_FLAG_SAP) != 0)
+ *      If you want to replace this API by free_local_para[_r] or free_peer_buff[_r],
+ *      please remember to skip timer ILM or inline ILM
+ * SEE ALSO
+ *  msg_send, msg_receive_extq, msg_receive_intq, free_local_para, free_local_para_r
+ *  free_peer_buff, free_peer_buff_r
+ ******************************************************************************/
+#define destroy_ilm(ilm_ptr) __destroy_ilm(ilm_ptr)
+
+#define destroy_shared_ilm_r destroy_ilm
+#define free_shared_peer_buff_r free_peer_buff
+#define free_shared_local_para_r free_local_para
+
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_receive_extq
+ * DESCRIPTION
+ *  receive a ILM message from current task's external queue.
+ * PARAMETERS
+ *  ilm_ptr        : [OUT] ILM message pointer.
+ * RETURN VALUES
+ *  KAL_TRUE: to indicate this operation finish successfully.
+ * NOTE
+ *  (1) If the external queue is not empty, this API return immediately.
+ *      Otherwise, it will suspend to wait for the arrival of ILM message.
+ *  (2) This API replaces receive_msg_ext_q(). And receive_msg_ext_q() is deprecated,
+ *     it will be removed from next release.
+ * SEE ALSO
+ *  msg_send, msg_receive_intq, destroy_ilm
+ ******************************************************************************/
+kal_bool msg_receive_extq(ilm_struct *ilm_ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_receive_extq_for_stack
+ * DESCRIPTION
+ *  receive a ILM message from current task's external queue used for stack sharing.
+ * PARAMETERS
+ *  ilm_ptr        : [OUT] ILM message pointer.
+ * RETURN VALUES
+ *  KAL_TRUE: to indicate this operation finish successfully.
+ * NOTE
+ *  (1) If the external queue is not empty, this API return immediately. 
+ *      Otherwise, it will suspend to wait for the arrival of ILM message.
+ *  (2) This API replaces receive_msg_ext_q(). And receive_msg_ext_q() is deprecated,
+ *     it will be removed from next release.
+ * SEE ALSO
+ *  msg_send, msg_receive_intq, destroy_ilm
+ ******************************************************************************/
+kal_bool msg_receive_extq_for_stack(ilm_struct *ilm_ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_receive_intq
+ * DESCRIPTION
+ *  receive a ILM message from current task's internal queue.
+ * PARAMETERS
+ *  ilm_ptr        : [OUT] ILM message pointer.
+ * RETURN VALUES
+ *  KAL_TRUE: ILM fetched.
+ *  KAL_FALSE: internal queue is empty and no ILM is fetched.
+ * NOTE
+ *  This API replaces receive_msg_int_q(). And receive_msg_int_q() is deprecated,
+ *     it will be removed from next release.
+ * SEE ALSO
+ *  msg_send, msg_receive_extq, destroy_ilm
+ ******************************************************************************/
+kal_bool msg_receive_intq(ilm_struct *ilm_ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_receive_isrq
+ * DESCRIPTION
+ *  receive a ILM message from current ISR's queue.
+ * PARAMETERS
+ *  ilm_ptr        : [OUT] ILM message pointer.
+ * RETURN VALUES
+ *  KAL_TRUE: ILM fetched.
+ *  KAL_FALSE: internal queue is empty and no ILM is fetched.
+ * NOTE
+ *
+ * SEE ALSO
+ *  msg_send, msg_receive_intq, destroy_ilm
+ ******************************************************************************/
+kal_bool msg_receive_isrq(ilm_struct *ilm_ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_get_task_extq_messages
+ * DESCRIPTION
+ *  get messages count in external queue of specified task by task index.
+ * PARAMETERS
+ *  tindex        : [IN] task index.
+ * RETURN VALUES
+ *  messages count, -1 if error happens.
+ * NOTE
+ *  (1)This API replaces msg_get_ext_queue_info(). And msg_get_ext_queue_info() is deprecated,
+ *     it will be removed from next release.
+ * SEE ALSO
+ *  msg_get_extq_messages, msg_get_task_extq_capacity, msg_get_extq_capacity
+ ******************************************************************************/
+kal_int32 msg_get_task_extq_messages(module_type module_id);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_get_extq_messages
+ * DESCRIPTION
+ *  get messages count in external queue of current task.
+ * PARAMETERS
+ *  N/A
+ * RETURN VALUES
+ *  messages count, -1 if error happens.
+ * SEE ALSO
+ *  msg_get_task_extq_messages, msg_get_task_extq_capacity, msg_get_extq_capacity
+ ******************************************************************************/
+kal_int32 msg_get_extq_messages(void);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_get_task_extq_capacity
+ * DESCRIPTION
+ *  get capacity of external queue of specified task by task index.
+ * PARAMETERS
+ *  tindex        : [IN] task index.
+ * RETURN VALUES
+ *  capacity of target external queue, -1 if error happens.
+ * NOTE
+ *  (1)This API replaces msg_get_ext_queue_length(). And msg_get_ext_queue_length() is deprecated,
+ *     it will be removed from next release.
+ * SEE ALSO
+ *  msg_get_task_extq_messages, msg_get_extq_messages, msg_get_extq_capacity
+ ******************************************************************************/
+kal_int32 msg_get_task_extq_capacity(module_type tmod);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  msg_get_extq_capacity
+ * DESCRIPTION
+ *  get capacity of external queue of current task.
+ * PARAMETERS
+ *  N/A
+ * RETURN VALUES
+ *  capacity of current task external queue, -1 if error happens.
+ * SEE ALSO
+ *  msg_get_task_extq_messages, msg_get_extq_messages, msg_get_task_extq_capacity
+ ******************************************************************************/
+kal_int32 msg_get_extq_capacity(void);
+#if 0
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+/* under construction !*/
+#endif
+
+/*******************************************************************************
+ * Category 4.5 : Cross Core Message Passing and Queue
+ *******************************************************************************/
+#define construct_int_cc_cached_peer_buff construct_int_peer_buff
+#define construct_int_cc_non_cached_peer_buff construct_int_peer_buff
+#define construct_int_cc_cached_local_para construct_int_local_para
+#define construct_int_cc_non_cached_local_para construct_int_local_para
+
+#if defined(DEBUG_KAL) && defined(DEBUG_BUF2)
+#define __construct_int_cc_cached_local_para(local_para_size, direction)           \
+    construct_int_cc_cached_local_para(                                            \
+        local_para_size, ((kal_uint32)(direction) & (kal_uint32)TD_RESET) ? 1 : 0, \
+        __FILE__, __LINE__)
+#define __construct_int_cc_non_cached_local_para(local_para_size, direction)       \
+    construct_int_cc_non_cached_local_para(                                        \
+        local_para_size, ((kal_uint32)(direction) & (kal_uint32)TD_RESET) ? 1 : 0, \
+        __FILE__, __LINE__)
+
+#define __construct_int_cc_cached_peer_buff(pdu_len, header_len, tail_len,     \
+                                            direction)                         \
+    construct_int_cc_cached_peer_buff(pdu_len, header_len, tail_len, __FILE__, \
+                                      __LINE__)
+#define __construct_int_cc_non_cached_peer_buff(pdu_len, header_len, tail_len,     \
+                                                direction)                         \
+    construct_int_cc_non_cached_peer_buff(pdu_len, header_len, tail_len, __FILE__, \
+                                          __LINE__)
+
+#else /* !DEBUG_KAL || !DEBUG_BUF2 */
+#define __construct_int_cc_cached_local_para(local_para_size, direction)           \
+    construct_int_cc_cached_local_para(                                            \
+        local_para_size, ((kal_uint32)(direction) & (kal_uint32)TD_RESET) ? 1 : 0, \
+        NULL, 0)
+#define __construct_int_cc_non_cached_local_para(local_para_size, direction)       \
+    construct_int_cc_non_cached_local_para(                                        \
+        local_para_size, ((kal_uint32)(direction) & (kal_uint32)TD_RESET) ? 1 : 0, \
+        NULL, 0)
+
+#define __construct_int_cc_cached_peer_buff(pdu_len, header_len, tail_len, \
+                                            direction)                     \
+    construct_int_cc_cached_peer_buff(pdu_len, header_len, tail_len, NULL, 0)
+#define __construct_int_cc_non_cached_peer_buff(pdu_len, header_len, tail_len, \
+                                                direction)                     \
+    construct_int_cc_non_cached_peer_buff(pdu_len, header_len, tail_len, NULL, 0)
+
+#endif
+
+
+#define construct_cc_cached_local_para(local_para_size, direction) \
+    __construct_int_cc_cached_local_para(local_para_size, direction)
+#define construct_cc_non_cached_local_para(local_para_size, direction) \
+    __construct_int_cc_non_cached_local_para(local_para_size, direction)
+
+#define construct_cc_cached_peer_buff(pdu_len, header_len, tail_len, direction) \
+    __construct_int_cc_cached_peer_buff(pdu_len, header_len, tail_len, direction)
+#define construct_cc_non_cached_peer_buff(pdu_len, header_len, tail_len, direction) \
+    __construct_int_cc_non_cached_peer_buff(pdu_len, header_len, tail_len, direction)
+
+#define msg_send_cc msg_send
+#define msg_send6_cc msg_send6
+#define msg_send5_cc msg_send5
+#define msg_send4_cc msg_send4
+#define msg_send_to_head_cc msg_send_to_head
+#define msg_send_to_head6_cc msg_send_to_head6
+#define msg_send_to_head5_cc msg_send_to_head5
+#define msg_send_to_head4_cc msg_send_to_head4
+
+
+#define msg_send_inline6_cc msg_send_inline6
+#define msg_send_inline_to_head6_cc msg_send_inline_to_head6
+
+#define msg_send_inline5_cc(src_mod, dest_mod, msg_id, data, datalen) \
+    msg_send_inline6_cc(src_mod, dest_mod, INLINE_ILM_SAP, msg_id, data, datalen)
+
+
+#define msg_send_inline_to_head5_cc(src_mod, dest_mod, sap_id, msg_id, data,     \
+                                    datalen)                                     \
+    msg_send_inline_to_head6_cc(src_mod, dest_mod, INLINE_ILM_SAP, msg_id, data, \
+                                datalen)
+
+#define msg_send_8bytes_inline6_cc msg_send_8bytes_inline6
+
+#define msg_send_8bytes_inline_to_head6_cc msg_send_8bytes_inline_to_head6
+
+/* DOM-NOT_FOR_SDK-END */
+
+/*******************************************************************************
+ * Category 5 : Synchronous Mechanism : Mutex , Enhance Mutex , Semaphore,
+ * Event Group, Spinlock, HW ITC and atomic increment/decrement
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_create_mutex
+ * DESCRIPTION
+ *  create a mutex.
+ * PARAMETERS
+ *  mutex_name  : [IN] mutex name. it's used for debug only, and only the
+ *                first 8 characters retain.
+ * RETURNS
+ *  Success:        mutex pointer.
+ *  Error:          system enter fatal error handling.
+ * NOTE
+ *  It is strongly suggested to call this function only in system initialization
+ *  time, and the related data allocated for the mutex could not be freed
+ *  once it is created.
+ * SEE ALSO
+ *  kal_take_mutex kal_give_mutex
+ ******************************************************************************/
+kal_mutexid kal_create_mutex(kal_char *mutex_name);
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_take_mutex
+ * DESCRIPTION
+ *  Obtains an instance of the specified mutex. If the mutex is taken already
+ *  before this call, the function cannot be immediately satisfied, and caller
+ *  task will be suspended until other task give the ownership to caller task.
+ *  After the function returns, caller task is the only task held this mutex.
+ * PARAMETERS
+ *  mutex_ptr        : [IN] mutex pointer.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  (1)Mutex is not a recursive lock. If caller task already held this mutex,
+ *     then caller task will suspend forever because any task won^t and can^t
+ *     give up mutex^s ownership.
+ *  (2)Mutex is a FIFO queue. If multiple tasks are waiting on a mutex, the
+ *     first waiting task is selected to be the next owner.
+ * SEE ALSO
+ *  kal_create_mutex kal_give_mutex
+ ******************************************************************************/
+void kal_take_mutex(kal_mutexid mutex_ptr);
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_give_mutex
+ * DESCRIPTION
+ *  Give up mutex ownership. If any task is waiting on this mutex, the first
+ *  waiting task is selected to be the next owner.
+ * PARAMETERS
+ *  mutex_ptr        : [IN] mutex pointer.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  Mutex ownership is private to task. That means, give can be done at the same
+ *  task of take, otherwise fatal error handling takes place.
+ * SEE ALSO
+ *  kal_create_mutex kal_take_mutex
+ ******************************************************************************/
+void kal_give_mutex(kal_mutexid mutex_ptr);
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_mutex_waiting_count
+ * DESCRIPTION
+ *  This routine returns the numbers of task waiting on the mutex. 
+ * PARAMETERS
+ *  mutex_ptr        : [IN] mutex pointer.
+ *  waiting_count   : [OUT] waiting count.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  This function is not in any critical section, e.g disable/enable interrupt, user should guarantee the atomic.
+ * SEE ALSO
+ *  kal_create_mutex kal_take_mutex 
+ ******************************************************************************/
+void kal_mutex_waiting_count(kal_mutexid mutex_ptr, kal_uint32 *waiting_count);
+/*******************************************************************************
+ * <GROUP Synchronous>
+ * 
+ * FUNCTION
+ *  kal_create_enh_mutex
+ * DESCRIPTION
+ *  create an enhmutex which implements Priority Inheritance Protocol(PIP) to
+ *  avoid priority inversion.
+ * PARAMETERS
+ *  mutex_name  : [IN] enhmutex name. it's used for debug only, and only the
+ *                    first 8 characters retain.
+ * RETURNS
+ *  Success:        enhmutex pointer.
+ *  Error:          system enter fatal error handling.
+ * NOTE
+ *  It is strongly suggested to call this function only in system initialization
+ *  time, and the related data allocated for the enhmutex could not be freed
+ *  once it is created.
+ * SEE ALSO
+ *  kal_take_enh_mutex kal_give_enh_mutex
+ ******************************************************************************/
+kal_enhmutexid kal_create_enh_mutex(kal_char *mutex_name);
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_take_enh_mutex
+ * DESCRIPTION
+ *  Obtain an instance of the specified enhmutex. If the enhmutex is taken
+ *  already before this call, the function cannot be immediately satisfied,
+ *  caller task propogates its priority to the owner task if caller task has
+ *  higher priority than owner task, and caller task will be suspended until
+ *  other task give the ownership to caller task. After the function returns,
+ *  caller task is the only task held this enhmutex.
+ * PARAMETERS
+ *  mutex_ptr        : [IN] enhmutex pointer.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  (1)Enhmutex is not a recursive lock. If caller task already held this
+ *     enhmutex, then caller task will suspend forever because any task will not
+ *     give up ehnmutex's ownership.
+ *  (2)No promise of enhmutex's queue type. If multiple tasks is waiting on a
+ *     mutex, no promise made which task will selected to run first.
+ * SEE ALSO
+ *  kal_create_enh_mutex kal_give_enh_mutex
+ ******************************************************************************/
+void kal_take_enh_mutex(kal_enhmutexid mutex_ptr);
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_give_enh_mutex
+ * DESCRIPTION
+ *  Give up enhmutex ownership. If any task is waiting on this mutex, give the
+ *  ownership to any task based on its judge.
+ * PARAMETERS
+ *  mutex_ptr        : [IN] mutex pointer.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  Enhmutex ownership is private to task. That means, give can be done at the
+ *  same task of take, otherwise fatal error handling takes place.
+ * SEE ALSO
+ *  kal_create_enh_mutex kal_take_enh_mutex
+ ******************************************************************************/
+void kal_give_enh_mutex(kal_enhmutexid mutex_ptr);
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_create_sem
+ * DESCRIPTION
+ *  create a couting semaphore.
+ * PARAMETERS
+ *  sem_name  : [IN] semaphore name. it's used for debug only, and only the
+ *                    first 8 characters retain.
+ *  initial_count : [IN] semaphore initial count.
+ * RETURNS
+ *  Success:        semaphore pointer.
+ *  Error:          system enter fatal error handling.
+ * NOTE
+ *  (1)It is strongly suggested to call this function only in system initialization
+ *     time, and the related data allocated for the semaphore could not be freed
+ *     once it is created.
+ *  (2)Semaphore values can range from 0 through 4,294,967,294 (2^32 - 2).
+ * SEE ALSO
+ *  kal_take_sem kal_give_sem
+ ******************************************************************************/
+kal_semid kal_create_sem(kal_char *sem_name, kal_uint32 initial_count);
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_take_sem
+ * DESCRIPTION
+ *  Obtains an instance of the specified semaphore.
+ * PARAMETERS
+ *  sem_ptr        : [IN] semaphore pointer.
+ *  wait_mode      : [IN] wait mode, specify the behavior when the semaphore is
+ *                   not ready immediately, it can be one the the following values:
+ *                   KAL_NO_WAIT - don't wait for other task gives ownership to it
+ *                   KAL_INFINITE_WAIT - wait until ownership can be satisfied
+ * RETURN VALUES
+ *  KAL_SUCCESS    : the operation is done successfully
+ *  KAL_SEM_NOT_AVAILABLE : the semaphore is unavailable immediately
+ * NOTE
+ *  (1)Semaphore is a FIFO queue. If multiple tasks is waiting on a semaphore,
+ *     the first waiting task is selected to be the next owner.
+ * SEE ALSO
+ *  kal_create_sem kal_give_sem
+ ******************************************************************************/
+kal_status kal_take_sem(kal_semid sem_ptr, kal_wait_mode wait_mode);
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_give_sem
+ * DESCRIPTION
+ *  Give up 1 semaphore ownership. If any task is waiting on this semaphore,
+ *  give the ownership to first waiting task.
+ * PARAMETERS
+ *  sem_ptr        : [IN] semaphore pointer.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  N/A
+ * SEE ALSO
+ *  kal_create_sem kal_take_sem
+ ******************************************************************************/
+void kal_give_sem(kal_semid sem_ptr);
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_create_spinlock
+ * DESCRIPTION
+ *  creates a spinlock.
+ * PARAMETERS
+ *  spinlock_name  : [IN] spinlock name. it's used for debug only, and only the
+ *                    first 7 characters retain.
+ * RETURNS
+ *  Success:        spinlock pointer.
+ *  Error:          system enter fatal error handling.
+ * SEE ALSO
+ *  kal_delete_spinlock
+ ******************************************************************************/
+kal_spinlockid kal_create_spinlock(kal_char *spinlock_name);
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_take_spinlock
+ * DESCRIPTION
+ *  Obtains an instance of the specified spinlock.
+ * PARAMETERS
+ *  ext_spinlock_id_ptr : [IN] spinlock pointer.
+ *  wait_mode           : [IN] wait mode, specify the behavior when the semaphore is
+ *                        not ready immediately, it can be one the the following values:
+ *                        KAL_NO_WAIT - don't wait for other task gives ownership to it
+ *                        KAL_INFINITE_WAIT - wait until ownership can be satisfied
+ * RETURN VALUES
+ *  KAL_SUCCESS                : the operation is done successfully
+ *  KAL_SPINLOCK_NOT_AVAILABLE : the spinlock is unavailable immediately
+ * SEE ALSO
+ *  kal_give_spinlock
+ ******************************************************************************/
+kal_status kal_take_spinlock(kal_spinlockid ext_spinlock_id_ptr,
+                             kal_wait_mode  wait_mode);
+/*******************************************************************************
+ * <GROUP Synchronous>
+ *
+ * FUNCTION
+ *  kal_give_spinlock
+ * DESCRIPTION
+ *  Give up 1 spinlock ownership.
+ * PARAMETERS
+ *  ext_spinlock_id_ptr        : [IN] spinlock pointer.
+ * RETURNS
+ *  -
+ * SEE ALSO
+ *  kal_take_spinlock
+ ******************************************************************************/
+void kal_give_spinlock(kal_spinlockid ext_spinlock_id_ptr);
+/*******************************************************************************
+ * <GROUP Communication>
+ *
+ * FUNCTION
+ *  kal_create_event_group
+ * DESCRIPTION
+ *  create an event group.
+ * PARAMETERS
+ *  eventgrp_name  : [IN] event group name. it's used for debug only, and only
+ *                    the first 8 characters retain.
+ * RETURNS
+ *  Success:        event group pointer.
+ *  Error:          system enter fatal error handling.
+ * NOTE
+ *  (1)It is strongly suggested to call this function only in system initialization
+ *     time, and the related data allocated for the event group could not be freed
+ *     once it is created.
+ *  (2)Each event group contains 32 event flags, all event flags are initially
+ *     set to 0.
+ * SEE ALSO
+ *  kal_set_eg_events kal_retrieve_eg_events kal_retrieve_eg_events_timeout
+ ******************************************************************************/
+kal_eventgrpid kal_create_event_group(kal_char *eventgrp_name);
+/*******************************************************************************
+ * <GROUP Communication>
+ *
+ * FUNCTION
+ *  kal_set_eg_events
+ * DESCRIPTION
+ *  sets the specified event flags in the specified event group. Any task waiting
+ *  on the event group whose event flag request is satisfied by this service is resumed.
+ * PARAMETERS
+ *  eg_ptr  : [IN] event group pointer.
+ *  events  : [IN] event flags to be set.
+ *  operation : [IN] specify the operation, which can be one of following values:
+ *              KAL_AND - events in event group is AND with events argument,
+ *                     that is, mask out bits not set in events argument
+ *              KAL_OR - events in event group is OR with events argument
+ * RETURNS
+ *  Success:        return KAL_SUCCESS
+ *  Error:          system enter fatal error handling.
+ * NOTE
+ *  N/A
+ * SEE ALSO
+ *  kal_create_event_group kal_retrieve_eg_events kal_retrieve_eg_events_timeout
+ ******************************************************************************/
+kal_status kal_set_eg_events(kal_eventgrpid eg_ptr, kal_uint32 events,
+                             kal_uint8 operation);
+/*******************************************************************************
+ * <GROUP Communication>
+ *
+ * FUNCTION
+ *  kal_retrieve_eg_events
+ * DESCRIPTION
+ *  retrieves the specified event-flag combination from the specified event-flag group.
+ * PARAMETERS
+ *  eg_ptr  : [IN] event group pointer.
+ *  requested_events  : [IN] requested event flags
+ *  operation : [IN] specify the operation, which can be one of following values:
+ *              KAL_AND - all of the requested event flags are required
+ *              KAL_AND_CONSUME - all of requested event flags are required, and
+ *                                automatically clears the event flags present on a successful request
+ *              KAL_OR - one or more of the requested event flags is sufficient
+ *              KAL_OR_CONSUME - one or more of the requested event flags is sufficient, and
+ *                               automatically clears the event flags present on a successful request
+ *  retrieved_events: [OUT] actual events present in event group.
+ *  suspend:  [IN] whether to wait for the event flags set when they can be satisfied immediately,
+ *                 it can be one of following values:
+ *                 0: don't wait and return KAL_NOT_PRESENT
+ *                 KAL_SUSPEND: wait until they can be satisfied
+ * RETURN VALUES
+ *  KAL_SUCCESS:     the operation is done successfully
+ *  KAL_NOT_PRESENT: the request event flags are not present immediately
+ *  Error:          system enter fatal error handling.
+ * NOTE
+ *  N/A
+ * SEE ALSO
+ *  kal_create_event_group kal_set_eg_events kal_retrieve_eg_events_timeout
+ ******************************************************************************/
+kal_status kal_retrieve_eg_events(kal_eventgrpid eg_ptr, kal_uint32 requested_events,
+                                  kal_uint8 operation, kal_uint32 *retrieved_events,
+                                  kal_uint32 suspend);
+/*******************************************************************************
+ * <GROUP Communication>
+ *
+ * FUNCTION
+ *  kal_retrieve_eg_events_timeout
+ * DESCRIPTION
+ *  retrieves the specified event-flag combination from the specified event-flag group.
+ * PARAMETERS
+ *  eg_ptr  : [IN] event group pointer.
+ *  requested_events  : [IN] requested event flags
+ *  operation : [IN] specify the operation, which can be one of following values:
+ *              KAL_AND - all of the requested event flags are required
+ *              KAL_AND_CONSUME - all of requested event flags are required, and
+ *                                automatically clears the event flags present on a successful request
+ *              KAL_OR - one or more of the requested event flags is sufficient
+ *              KAL_OR_CONSUME - one or more of the requested event flags is sufficient, and
+ *                               automatically clears the event flags present on a successful request
+ *  retrieved_events: [OUT] actual events present in event group.
+ *  timeout:  [IN] how long to wait for the event flags set when they can be satisfied immediately,
+ *                 it can be one of following values:
+ *                 0 - don't wait and return KAL_NOT_PRESENT
+ *                 KAL_SUSPEND - wait until they can be satisfied
+ *                 other values - wait at most timeout ticks, return KAL_NOT_PRESENT if timeout happens
+ * RETURN VALUES
+ *  KAL_SUCCESS:     the operation is done successfully
+ *  KAL_NOT_PRESENT: the request event flags are not present immediately
+ *  Error:          system enter fatal error handling.
+ * NOTE
+ *  This API's availability is dependent on a macro HAS_KAL_RETRIEVE_EG_EVENTS_TIMEOUT.
+ *  If it's not defined, then this API is not available.
+ * SEE ALSO
+ *  kal_create_event_group kal_set_eg_events kal_retrieve_eg_events
+ ******************************************************************************/
+kal_status kal_retrieve_eg_events_timeout(kal_eventgrpid eg_ptr,
+                                          kal_uint32     requested_events,
+                                          kal_uint8      operation,
+                                          kal_uint32 *   retrieved_events,
+                                          kal_uint32     timeout);
+#define HAS_KAL_RETRIEVE_EG_EVENTS_TIMEOUT 1
+
+/*******************************************************************************
+ * Category 5.5 : Cross Core Event Group and RCU
+ *******************************************************************************/
+
+/*******************************************************************************
+ * <GROUP Communication>
+ *
+ * FUNCTION
+ *  kalcc_create_event_group
+ * DESCRIPTION
+ *  create a cross core event group.
+ * PARAMETERS
+ *  eg_id          : [IN] event group pointer, the memory should be allocated from
+ *                    shared memory
+ *  eventgrp_name  : [IN] event group name. it's used for debug only, and only
+ *                    the first 7 characters retain.
+ * RETURNS
+ *  KAL_SUCCESS:     create successfully
+ *  KAL_INIT_BEFORE: the event group has been init before
+ * NOTE
+ *  (1)It is strongly suggested to call this function only in system initialization
+ *     time, and the related data allocated for the event group could not be freed
+ *     once it's created.
+ *  (2)Each event group contains 32 event flags, all event flags are initially
+ *     set to 0.
+ * SEE ALSO
+ *  kalcc_set_eg_events kalcc_retrieve_eg_events
+ ******************************************************************************/
+kal_status kalcc_create_event_group(cc_eventgrpid *eg_id, kal_char *eventgrp_name);
+/*******************************************************************************
+ * <GROUP Communication>
+ *
+ * FUNCTION
+ *  kalcc_set_eg_events
+ * DESCRIPTION
+ *  sets the specified event flags in the specified event group. Any task waiting
+ *  on the event group whose event flag request is satisfied by this service is resumed.
+ * PARAMETERS
+ *  cc_eventgrpid : [IN] event group pointer.
+ *  events  : [IN] event flags to be set.
+ *  operation : [IN] specify the operation, which can be one of following values:
+ *              KAL_AND - events in event group is AND with events argument,
+ *                     that is, mask out bits not set in events argument
+ *              KAL_OR - events in event group is OR with events argument
+ * RETURNS
+ *  KAL_SUCCESS:     the operation is done successfully
+ *  Error:          system enter fatal error handling.
+ * NOTE
+ *  This function can not be called from hisr or system initialization; otherwise, assertion
+ * SEE ALSO
+ *  kalcc_create_event_group kalcc_retrieve_eg_events
+ ******************************************************************************/
+kal_status kalcc_set_eg_events(cc_eventgrpid *eg_id, kal_uint32 events,
+                               kal_uint8 operation);
+/*******************************************************************************
+ * <GROUP Communication>
+ *
+ * FUNCTION
+ *  kalcc_retrieve_eg_events
+ * DESCRIPTION
+ *  retrieves the specified event-flag combination from the specified event-flag group.
+ * PARAMETERS
+ *  eg_id  : [IN] event group pointer.
+ *  requested_events  : [IN] requested event flags
+ *  operation : [IN] specify the operation, which can be one of following values:
+ *              KAL_AND - all of the requested event flags are required
+ *              KAL_AND_CONSUME - all of requested event flags are required, and
+ *                                automatically clears the event flags present on a successful request
+ *              KAL_OR - one or more of the requested event flags is sufficient
+ *              KAL_OR_CONSUME - one or more of the requested event flags is sufficient, and
+ *                               automatically clears the event flags present on a successful request
+ *  retrieved_events: [OUT] actual events present in event group.
+ *  suspend:  [IN] whether to wait for the event flags set when they can be satisfied immediately,
+ *                 it can be one of following values:
+ *                 0: don't wait and return CC_NOT_PRESENT
+ *                 KAL_SUSPEND: wait until they can be satisfied
+ *                 otherwise: system enter fatal error handling.
+ * RETURN VALUES
+ *  KAL_SUCCESS:     the operation is done successfully
+ *  KAL_NOT_PRESENT: the request event flags are not present immediately
+ *  Error:          system enter fatal error handling.
+ * NOTE
+ *  N/A
+ * SEE ALSO
+ *  kalcc_create_event_group cc_set_eg_events
+ ******************************************************************************/
+kal_status kalcc_retrieve_eg_events(cc_eventgrpid *eg_id,
+                                    kal_uint32 requested_events, kal_uint8 operation,
+                                    kal_uint32 *retrieved_events,
+                                    kal_uint32  suspend);
+
+
+/* 1. creator*/
+kalcc_rcuid rcu_create(void *buff_addr, kal_uint32 allocated_buff_size,
+                       kal_uint32 buff_size, kal_uint32 reserved);
+/* 2. writer */
+void *rcu_get_free_buff(kalcc_rcuid id);
+kal_status rcu_commit_data(void *data);
+/* 3. reader */
+void *rcu_get_read_lock(kalcc_rcuid id);
+kal_status rcu_free_read_lock(void *data);
+
+
+/*******************************************************************************
+ * Category 6 : Application Memory Management  ADM , AFM
+ *******************************************************************************/
+
+extern KAL_ADM_ID(kal_adm_create)(void *mem_addr, kal_uint32 size,
+                                  kal_uint32 *subpool_size, kal_bool islogging);
+extern KAL_ADM_ID(kal_adm_create_and_profile)(void *mem_addr, kal_uint32 size,
+                                              kal_uint32 *subpool_size,
+                                              kal_bool    islogging);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_create2
+ * DESCRIPTION
+ *  Create a ADM pool.
+ * PARAMETERS
+ *  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.
+ *  size: [IN] total size in byte of the memory pool.
+ *  subpool_size: [IN] is an array, which describe size of each sub-pool.
+ *  flags: [IN] new ADM pool extra flags, which is a combination of following values
+ *         KAL_ADM_GUARDIAN_FLAG - RECOMMENDED! put a guard word before and after each user buffer to detect memory corruption
+ *                                 it also enable some other error detections on this ADM pool.
+ *         KAL_ADM_EXTHEADER_FLAG - has an extensible header immediate before each user buffer,
+ *                                  whose size is specified by extheader_size_in_word
+ *         KAL_ADM_CLEANDELETE_FLAG - on kal_adm_delete(), if any user buffer is not free yet,
+ *                                    system enter fatal error handling
+ *         KAL_ADM_REALLOCFAIL_FATAL_FLAG - if kal_adm_realloc() failed, system enter fatal error handling
+ *         KAL_ADM_REALLOCFAIL_FREE_FLAG - if kal_adm_realloc() failed, free old user buffer before return NULL
+ *  extheader_size_in_word: [IN] specified the extensible header size, only takes effect when KAL_ADM_EXTHEADER_FLAG is specified.
+ *                          this argument specified in unit of word, you can use KAL_ADM_EXTHEADER_WORDS(sizeof(struct A)) if you want
+ *                          to put a struct A in extensible header.
+ * RETURNS
+ *  ADM id. If memory is too small to create a ADM, return NULL.
+ * NOTE
+ *  (1)This API replaces kal_adm_create(). And kal_adm_create() is deprecated,
+ *     it will be removed from next release.
+ *  (2)subpool_size must be monotonic increasing and ends with {0xffffffff, 0}.
+ *     If it's NULL, the default subpool size setting is used: { 16, 32, 64, 128, 256, 512, 0xffffffff, 0 }.
+ *     Default subpool size has 7 subpools.
+ *  (3)The ADM overhead for control block is divided into 2 parts:
+ *     Static - that is (16*3+16*subpool_count}. subpool_count is element count in subpool_size except last element 0.
+ *     Dynamic - Each user block has an extra: (8+extheader_size_in_word*4)
+ * SEE ALSO
+ *  kal_adm_delete KAL_ADM_EXTHEADER_WORDS
+ ******************************************************************************/
+extern KAL_ADM_ID kal_adm_create2(void *mem_addr, kal_uint32 size,
+                                  kal_uint32 *subpool_size, kal_uint32 flags,
+                                  kal_int8 extheader_size_in_word);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_delete
+ * DESCRIPTION
+ *  delete a ADM pool.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ * RETURN VALUES
+ *  KAL_SUCCESS: the operation succeeded.
+ *  KAL_MEMORY_NOT_RELEASE: some user buffer is not free yet.
+ * NOTE
+ *  if KAL_ADM_CLEANDELETE_FLAG is specified on creation and any user buffer is not free yet,
+ *  system enter fatal error handling
+ * SEE ALSO
+ *  kal_adm_create2
+ ******************************************************************************/
+extern kal_status kal_adm_delete(KAL_ADM_ID adm_id);
+
+extern void *__kal_adm_alloc(KAL_ADM_ID adm_id, kal_uint32 size,
+                             kal_uint32 *actual_size, kal_uint32 opt, char *filename,
+                             kal_uint32 line);
+extern void *__kal_adm_alloc_nc(KAL_ADM_ID adm_id, kal_uint32 size,
+                                kal_uint32 *actual_size, kal_uint32 option,
+                                char *filename, kal_uint32 line);
+extern void *__kal_adm_alloc_c(KAL_ADM_ID adm_id, kal_uint32 size,
+                               kal_uint32 *actual_size, kal_uint32 option,
+                               char *filename, kal_uint32 line);
+
+extern void *__kal_adm_realloc(KAL_ADM_ID adm_id, void *ptr, kal_uint32 size,
+                               kal_uint32 *actual_size, kal_uint32 opt,
+                               char *filename, kal_uint32 line);
+extern void *__kal_adm_realloc_nc(KAL_ADM_ID adm_id, void *ptr, kal_uint32 size,
+                                  kal_uint32 *actual_size, kal_uint32 opt,
+                                  char *filename, kal_uint32 line);
+extern void *__kal_adm_realloc_c(KAL_ADM_ID adm_id, void *ptr, kal_uint32 size,
+                                 kal_uint32 *actual_size, kal_uint32 opt,
+                                 char *filename, kal_uint32 line);
+
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_alloc
+ * DESCRIPTION
+ *  allocate a memory buffer from ADM.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ *  size: [IN] request memory size.
+ * RETURNS
+ *  allocated memory buffer pointer. return NULL if no memory available.
+ * NOTE
+ *  the prototype of this API is:
+ *   void *kal_adm_alloc(KAL_ADM_ID adm_id, kal_uint32 size);
+ * SEE ALSO
+ *  kal_adm_create2 kal_adm_alloc_with_info kal_adm_free
+ ******************************************************************************/
+#define kal_adm_alloc(adm_id, size) \
+    __kal_adm_alloc((adm_id), (size), NULL, 0, __FILE__, __LINE__)
+#define kal_adm_alloc_dbg(adm_id, size, f, l) \
+    __kal_adm_alloc((adm_id), (size), NULL, 0, (f), (l))
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_alloc_with_info
+ * DESCRIPTION
+ *  allocate a memory buffer from ADM, return the actually size (including any ADM overhead) of this memory block also.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ *  size: [IN] request memory size.
+ *  actual_size: [OUT] return the actually size in it.
+ * RETURNS
+ *  allocated memory buffer pointer. return NULL if no memory available.
+ * NOTE
+ *  the prototype of this API is:
+ *   void *kal_adm_alloc_with_info(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 *actual_size);
+ * SEE ALSO
+ *  kal_adm_create2 kal_adm_alloc kal_adm_free
+ ******************************************************************************/
+#define kal_adm_alloc_with_info(adm_id, size, actual_size) \
+    __kal_adm_alloc((adm_id), (size), (actual_size), 0x0, __FILE__, __LINE__)
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_alloc_align
+ * DESCRIPTION
+ *  allocate a memory buffer which satisfy the alignment requirement from ADM.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ *  size: [IN] request memory size.
+ *  align: [IN] alignment requirement, which must be a multiple of 4.
+ * RETURNS
+ *  allocated memory buffer pointer. return NULL if no memory available.
+ * NOTE
+ *  the prototype of this API is:
+ *   void *kal_adm_alloc_align(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 alignment);
+ * SEE ALSO
+ *  kal_adm_create2 kal_adm_free
+ ******************************************************************************/
+#define kal_adm_alloc_align(adm_id, size, alignment)                               \
+    __kal_adm_alloc((adm_id), (size), NULL, (alignment) & ~ADM_OPT_MASK, __FILE__, \
+                    __LINE__)
+#define kal_adm_alloc_align_dbg(adm_id, size, alignment, f, l) \
+    __kal_adm_alloc((adm_id), (size), NULL, (alignment) & ~ADM_OPT_MASK, (f), (l))
+
+
+#if defined(__MTK_TARGET__) && \
+    (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
+#define __kal_adm_alloc_cacheable(adm_id, size, option) \
+    __kal_adm_alloc_c((adm_id), (size), NULL, 0, __FILE__, __LINE__)
+#define __kal_adm_alloc_cacheable_with_info(adm_id, size, option, actual_size) \
+    __kal_adm_alloc_c((adm_id), (size), (actual_size), 0x0, __FILE__, __LINE__)
+#define __kal_adm_alloc_cacheable_dbg(adm_id, size, option, f, l) \
+    __kal_adm_alloc_c((adm_id), (size), NULL, 0, (f), (l))
+#else
+#define __kal_adm_alloc_cacheable(adm_id, size, option) \
+    __kal_adm_alloc((adm_id), (size), NULL, 0, __FILE__, __LINE__)
+#define __kal_adm_alloc_cacheable_with_info(adm_id, size, option, actual_size) \
+    __kal_adm_alloc((adm_id), (size), (actual_size), 0x0, __FILE__, __LINE__)
+#define __kal_adm_alloc_cacheable_dbg(adm_id, size, option, f, l) \
+    __kal_adm_alloc((adm_id), (size), NULL, 0, (f), (l))
+#endif
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_alloc_cacheable
+ * DESCRIPTION
+ *  allocate a memory buffer which is cacheable from ADM.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ *  size: [IN] request memory size.
+ *  option_notused: [IN] useless, ignored.
+ * RETURNS
+ *  allocated memory buffer pointer. return NULL if no memory available.
+ * NOTE
+ *  (1)the prototype of this API is:
+ *   void *kal_adm_alloc_cacheable(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 option_notused);
+ *  (2)The pointer is cacheable only on platform that has ARM MMU (such as ARM9/ARM11 platform).
+ *     If not, the pointer is still noncacheable.
+ * SEE ALSO
+ *  kal_adm_create2 kal_adm_alloc_cacheable_with_info kal_adm_alloc_noncacheable kal_adm_free
+ ******************************************************************************/
+#define kal_adm_alloc_cacheable(adm_id, size, option_notused) \
+    __kal_adm_alloc_cacheable(adm_id, size, option_notused)
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_alloc_cacheable_with_info
+ * DESCRIPTION
+ *  allocate a memory buffer which is cacheable from ADM, return the actually size (including any ADM overhead) of this memory block also.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ *  size: [IN] request memory size.
+ *  option_notused: [IN] useless, ignored.
+ *  actual_size: [OUT] return the actually size in it.
+ * RETURNS
+ *  allocated memory buffer pointer. return NULL if no memory available.
+ * NOTE
+ *  (1)the prototype of this API is:
+ *   void *kal_adm_alloc_cacheable_with_info(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 option_notused, kal_uint32 *actual_size);
+ *  (2)The pointer is cacheable only on platform that has ARM MMU (such as ARM9/ARM11 platform).
+ *     If not, the pointer is still noncacheable.
+ * SEE ALSO
+ *  kal_adm_create2 kal_adm_alloc_cacheable kal_adm_alloc_noncacheable kal_adm_free
+ ******************************************************************************/
+#define kal_adm_alloc_cacheable_with_info(adm_id, size, option_notused, \
+                                          actual_size)                  \
+    __kal_adm_alloc_cacheable_with_info(adm_id, size, option_notused, actual_size)
+#define kal_adm_alloc_cacheable_dbg(adm_id, size, option_notused, f, l) \
+    __kal_adm_alloc_cacheable_dbg(adm_id, size, option_notused, f, l)
+
+#if defined(__MTK_TARGET__) && \
+    (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
+#define __kal_adm_alloc_noncacheable(adm_id, size, option) \
+    __kal_adm_alloc_nc((adm_id), (size), NULL, 0, __FILE__, __LINE__)
+#define __kal_adm_alloc_noncacheable_with_info(adm_id, size, option, actual_size) \
+    __kal_adm_alloc_nc((adm_id), (size), (actual_size), 0x0, __FILE__, __LINE__)
+#define __kal_adm_alloc_noncacheable_dbg(adm_id, size, option, f, l) \
+    __kal_adm_alloc_nc((adm_id), (size), NULL, 0, (f), (l))
+#else
+#define __kal_adm_alloc_noncacheable(adm_id, size, option) \
+    __kal_adm_alloc((adm_id), (size), NULL, 0, __FILE__, __LINE__)
+#define __kal_adm_alloc_noncacheable_with_info(adm_id, size, option, actual_size) \
+    __kal_adm_alloc((adm_id), (size), (actual_size), 0x0, __FILE__, __LINE__)
+#define __kal_adm_alloc_noncacheable_dbg(adm_id, size, option, f, l) \
+    __kal_adm_alloc((adm_id), (size), NULL, 0, (f), (l))
+#endif
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_alloc_noncacheable
+ * DESCRIPTION
+ *  allocate a memory buffer which is noncacheable from ADM.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ *  size: [IN] request memory size.
+ *  option_notused: [IN] useless, ignored.
+ * RETURNS
+ *  allocated memory buffer pointer. return NULL if no memory available.
+ * NOTE
+ *  (1)the prototype of this API is:
+ *   void *kal_adm_alloc_noncacheable(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 option_notused);
+ * SEE ALSO
+ *  kal_adm_create2 kal_adm_alloc_noncacheable_with_info kal_adm_alloc_cacheable kal_adm_free
+ ******************************************************************************/
+#define kal_adm_alloc_noncacheable(adm_id, size, option_notused) \
+    __kal_adm_alloc_noncacheable(adm_id, size, option_notused)
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_alloc_noncacheable_with_info
+ * DESCRIPTION
+ *  allocate a memory buffer which is noncacheable from ADM, return the actually size (including any ADM overhead) of this memory block also.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ *  size: [IN] request memory size.
+ *  option_notused: [IN] useless, ignored.
+ *  actual_size: [OUT] return the actually size in it.
+ * RETURNS
+ *  allocated memory buffer pointer. return NULL if no memory available.
+ * NOTE
+ *  (1)the prototype of this API is:
+ *   void *kal_adm_alloc_noncacheable_with_info(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 option_notused, kal_uint32 *actual_size);
+ * SEE ALSO
+ *  kal_adm_create2 kal_adm_alloc_noncacheable kal_adm_alloc_cacheable kal_adm_free
+ ******************************************************************************/
+#define kal_adm_alloc_noncacheable_with_info(adm_id, size, option_notused, \
+                                             actual_size)                  \
+    __kal_adm_alloc_noncacheable_with_info(adm_id, size, option_notused, actual_size)
+#define kal_adm_alloc_noncacheable_dbg(adm_id, size, option_notused, f, l) \
+    __kal_adm_alloc_noncacheable_dbg(adm_id, size, option_notused, f, l)
+
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_realloc
+ * DESCRIPTION
+ *  re-allocate a memory buffer from ADM.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ *  ptr: [IN] old memory buffer pointer.
+ *  size: [IN] request memory size.
+ * RETURNS
+ *  re-allocated memory buffer pointer. return NULL if no memory available.
+ * SEE ALSO
+ *  kal_adm_create2 kal_adm_free kal_adm_alloc KAL_ADM_REALLOCFAIL_FATAL_FLAG KAL_ADM_REALLOCFAIL_FREE_FLAG
+ ******************************************************************************/
+#define kal_adm_realloc(adm_id, ptr, size) \
+    __kal_adm_realloc((adm_id), (ptr), (size), NULL, 0, __FILE__, __LINE__)
+#define kal_adm_realloc_dbg(adm_id, ptr, size, f, l) \
+    __kal_adm_realloc((adm_id), (ptr), (size), NULL, 0, (f), (l))
+#if defined(__MTK_TARGET__) && defined(__DYNAMIC_SWITCH_CACHEABILITY__)
+#define __kal_adm_realloc_noncacheable(adm_id, ptr, size) \
+    __kal_adm_realloc_nc((adm_id), (ptr), (size), NULL, 0, __FILE__, __LINE__)
+#define __kal_adm_realloc_cacheable(adm_id, ptr, size) \
+    __kal_adm_realloc_c((adm_id), (ptr), (size), NULL, 0, __FILE__, __LINE__)
+#else
+#define __kal_adm_realloc_noncacheable(adm_id, ptr, size) \
+    kal_adm_realloc(adm_id, ptr, size)
+#define __kal_adm_realloc_cacheable(adm_id, ptr, size) \
+    kal_adm_realloc(adm_id, ptr, size)
+#endif
+
+#define kal_adm_realloc_cacheable(adm_id, ptr, size) \
+    __kal_adm_realloc_cacheable(adm_id, ptr, size)
+#define kal_adm_realloc_noncacheable(adm_id, ptr, size) \
+    __kal_adm_realloc_noncacheable(adm_id, ptr, size)
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_free
+ * DESCRIPTION
+ *  free a memory buffer to dedicated ADM.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ *  ptr: [IN] memory buffer pointer to be free. This pointer must be allocated from adm_id.
+ * RETURNS
+ *  N/A
+ * SEE ALSO
+ *  kal_adm_create2 kal_adm_alloc kal_adm_realloc
+ ******************************************************************************/
+extern void kal_adm_free(KAL_ADM_ID adm_id, void *ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_get_extheader
+ * DESCRIPTION
+ *  get the extensible header associated with ptr, which is immediate before ptr.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ *  ptr: [IN] memory buffer pointer to query. This pointer must be returned from kal_adm_alloc*() functions.
+ * RETURNS
+ *  associated extensible header pointer.
+ * NOTE
+ *  (1)This ADM pool must has KAL_ADM_EXTHEADER_FLAG on creation.
+ *  (2)The size of this extensible header is (extheader_size_in_word*4)
+ * SEE ALSO
+ *  kal_adm_create2 KAL_ADM_EXTHEADER_FLAG
+ ******************************************************************************/
+extern void *kal_adm_get_extheader(KAL_ADM_ID adm_id, void *ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_get_alloc_size
+ * DESCRIPTION
+ *  get the allocated memory size.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ *  ptr: [IN] memory buffer pointer to query. This pointer must be returned from kal_adm_alloc*() functions.
+ * RETURNS
+ *  get the allocated memory size.
+ * NOTE
+ *  N/A
+ * SEE ALSO
+ *  
+ ******************************************************************************/
+extern kal_uint32 kal_adm_get_alloc_size(KAL_ADM_ID adm_id, void *ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_get_max_alloc_size
+ * DESCRIPTION
+ *  get maximal available memory size to be allocated in a single kal_adm_alloc*().
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ * RETURNS
+ *  maximal available memory size to be allocated.
+ * NOTE
+ *  (1)This size is guaranteed to allocated without considering any other requirement.
+ *     For example, kal_adm_alloc(adm_id, kal_adm_get_max_alloc_size(adm_id)) can succeed.
+ *     But kal_adm_alloc_align() is not guaranteed to succeed.
+ * SEE ALSO
+ *  kal_adm_get_total_left_size
+ ******************************************************************************/
+extern kal_uint32 kal_adm_get_max_alloc_size(KAL_ADM_ID adm_id);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_get_total_left_size
+ * DESCRIPTION
+ *  get total un-allocated memory size.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ * RETURNS
+ *  get total un-allocated memory size.
+ * NOTE
+ *  (1)Total un-allocated memory size may be splitted in many blocks(fragmentation).
+ * SEE ALSO
+ *  kal_adm_get_max_alloc_size
+ ******************************************************************************/
+extern kal_uint32 kal_adm_get_total_left_size(KAL_ADM_ID adm_id);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_adm_check_integrity
+ * DESCRIPTION
+ *  Check the healthy of ADM pool.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ * RETURNS
+ *  return bad memory block first found. If the ADM pool is healthy, return NULL to indicate
+ *  nothing wrong.
+ ******************************************************************************/
+extern void *kal_adm_check_integrity(KAL_ADM_ID adm_id);
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+extern void kal_adm_print_log(KAL_ADM_ID adm_id);
+extern kal_uint32 kal_adm_calc_worst_alloc_size(KAL_ADM_ID adm_id, kal_uint32 size,
+                                                kal_uint32 option);
+extern void *kal_adm_get_prev_block_ptr(KAL_ADM_ID adm_id, void *mem_addr);
+extern void *kal_adm_get_next_block_ptr(KAL_ADM_ID adm_id, void *mem_addr);
+extern void *kal_adm_get_trans_ptr(KAL_ADM_ID adm_id, void *mem_addr);
+
+
+/*
+ * Function prototype: void *kal_adm_alloc_mtkL1_cacheable(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 option)
+ * Note: Allocate a MTKL1-cacheable memory block.
+ */
+#if defined(__MTK_TARGET__) && defined(__MTK_L1CACHEABLE__)
+#define kal_adm_alloc_mtkL1_cacheable(adm_id, size, option) \
+    __kal_adm_alloc_c((adm_id), (size), NULL, (option), __FILE__, __LINE__)
+#else /* __MTK_TARGET__ && __MTK_L1CACHEABLE__ */
+#define kal_adm_alloc_mtkL1_cacheable(adm_id, size, option) \
+    __kal_adm_alloc((adm_id), (size), NULL, 0, __FILE__, __LINE__)
+#endif /* __MTK_TARGET__ && __MTK_L1CACHEABLE__ */
+
+/*
+ * Function prototype: void *kal_adm_alloc_mtkL1_noncacheable(KAL_ADM_ID adm_id, kal_uint32 option)
+ * Note: Allocate a memory block. This is for RFU only.
+ */
+#define kal_adm_alloc_mtkL1_noncacheable(adm_id, size, option) \
+    __kal_adm_alloc((adm_id), (size), NULL, 0, __FILE__, __LINE__)
+
+/*
+ * Function prototype: void *kal_adm_alloc_nc_align(KAL_ADM_ID adm_id, kal_uint32 align_size)
+ * Note: Allocate a non-cacheable and aligned memory block.
+ */
+#if defined(__MTK_TARGET__) && \
+    (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
+#define kal_adm_alloc_nc_align(adm_id, size, a)                               \
+    __kal_adm_alloc_nc((adm_id), (size), NULL, (a) & ~ADM_OPT_MASK, __FILE__, \
+                       __LINE__)
+#define kal_adm_alloc_nc_align_dbg(adm_id, size, a, f, l) \
+    __kal_adm_alloc_nc((adm_id), (size), NULL, (a) & ~ADM_OPT_MASK, (f), (l))
+#else /* __MTK_TARGET__ && (__ARM9_MMU__ || __DYNAMIC_SWITCH_CACHEABILITY__) */
+#define kal_adm_alloc_nc_align(adm_id, size, a) \
+    __kal_adm_alloc((adm_id), (size), NULL, (a) & ~ADM_OPT_MASK, __FILE__, __LINE__)
+#define kal_adm_alloc_nc_align_dbg(adm_id, size, a, f, l) \
+    __kal_adm_alloc((adm_id), (size), NULL, (a) & ~ADM_OPT_MASK, (f), (l))
+#endif /* __MTK_TARGET__ && (__ARM9_MMU__ || __DYNAMIC_SWITCH_CACHEABILITY__) */
+
+/*
+ * Function prototype: void *kal_adm_alloc_topmost(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 align_size)
+ *                     void *kal_adm_alloc_topmost_dbg(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 align_size, kal_char *filename, kal_uint32 linenumber)
+ * Note: Allocate a memory block from the topmost address of the pool.
+ *       The start address of the allocated memory will be aligned to the input parameter align_size.
+ *       kal_adm_alloc_topmost_dbg() is the debug verion.
+ *       The input parameters filename and line will be used for logging if logging is enabled.
+ */
+#define kal_adm_alloc_topmost(adm_id, size, a)                               \
+    __kal_adm_alloc((adm_id), (size), NULL,                                  \
+                    ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, __FILE__, \
+                    __LINE__)
+#define kal_adm_alloc_topmost_dbg(adm_id, size, a, f, l) \
+    __kal_adm_alloc((adm_id), (size), NULL,              \
+                    ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, (f), (l))
+
+/*
+ * Function prototype: void *kal_adm_alloc_c_topmost(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 align_size)
+ *                     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)
+ * Note: Allocate a cacheable memory block from the topmost address of the pool.
+ *       The start address of the allocated memory will be aligned to the input parameter align_size.
+ */
+#if defined(__MTK_TARGET__) && \
+    (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
+#define kal_adm_alloc_c_topmost(adm_id, size, a)                               \
+    __kal_adm_alloc_c((adm_id), (size), NULL,                                  \
+                      ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, __FILE__, \
+                      __LINE__)
+#define kal_adm_alloc_c_topmost_dbg(adm_id, size, a, f, l) \
+    __kal_adm_alloc_c((adm_id), (size), NULL,              \
+                      ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, (f), (l))
+#else /* __MTK_TARGET__ && (__ARM9_MMU__ || __DYNAMIC_SWITCH_CACHEABILITY__)*/
+#define kal_adm_alloc_c_topmost(adm_id, size, a)                             \
+    __kal_adm_alloc((adm_id), (size), NULL,                                  \
+                    ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, __FILE__, \
+                    __LINE__)
+#define kal_adm_alloc_c_topmost_dbg(adm_id, size, a, f, l) \
+    __kal_adm_alloc((adm_id), (size), NULL,                \
+                    ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, (f), (l))
+#endif /* __MTK_TARGET__ && (__ARM9_MMU__ || __DYNAMIC_SWITCH_CACHEABILITY__)*/
+
+/*
+ * Function prototype: void *kal_adm_alloc_nc_topmost(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 align_size)
+ *                     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)
+ * Note: Allocate a non-cacheable memory block from the topmost address of the pool.
+ *       The start address of the allocated memory will be aligned to the input parameter align_size.
+ *       kal_adm_alloc_nc_topmost_dbg() is the debug version.
+ */
+#if defined(__MTK_TARGET__) && \
+    (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
+#define kal_adm_alloc_nc_topmost(adm_id, size, a)                               \
+    __kal_adm_alloc_nc((adm_id), (size), NULL,                                  \
+                       ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, __FILE__, \
+                       __LINE__)
+#define kal_adm_alloc_nc_topmost_dbg(adm_id, size, a, f, l) \
+    __kal_adm_alloc_nc((adm_id), (size), NULL,              \
+                       ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, (f), (l))
+#else /* __MTK_TARGET__ && (__ARM9_MMU__ || __DYNAMIC_SWITCH_CACHEABILITY__)*/
+#define kal_adm_alloc_nc_topmost(adm_id, size, a)                            \
+    __kal_adm_alloc((adm_id), (size), NULL,                                  \
+                    ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, __FILE__, \
+                    __LINE__)
+#define kal_adm_alloc_nc_topmost_dbg(adm_id, size, a, f, l) \
+    __kal_adm_alloc((adm_id), (size), NULL,                 \
+                    ((a) & ~ADM_OPT_MASK) | ADM_OPT_TOPMOST_ALLOC, (f), (l))
+#endif /* __MTK_TARGET__ && (__ARM9_MMU__ || __DYNAMIC_SWITCH_CACHEABILITY__)*/
+/* DOM-NOT_FOR_SDK-END */
+
+
+/*
+ * AFM Section
+ */
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_afm_create
+ * DESCRIPTION
+ *  Create a AFM pool.
+ * PARAMETERS
+ *  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.
+ *  size: [IN] total size in byte of the memory pool.
+ *  subpool_size: [IN] is an array, which describe size of each sub-pool.
+ *  subpool_nr: [IN] is an array, which describe element count of each sub-pool.
+ *  flags: [IN] new AFM pool extra flags, which is a combination of following values
+ *         AFM_OPT_ALIGN_ALLOC - user buffers in this AFM is aligned to CPU cache line (32 bytes)
+ *                               only available on platform which has a ARM MMU (ARM9+ chips).
+ *         AFM_OPT_NOFALLBACK_ALLOC - when search avaiable user buffer, don't try to search subpools bigger than fittest subpool.
+ *  left_mem: [OUT] get how many memory is not used by this AFM pool and can be used by app freely.
+ * RETURNS
+ *  AFM id. If memory is too small to create a AFM, system enters fatal error handling.
+ * NOTE
+ *  subpool_size must be monotonic increasing and ends with {0xffffffff, 0}.
+ *   subpool_nr must has same elements as subpool_size.
+ * SEE ALSO
+ *  kal_afm_delete
+ ******************************************************************************/
+extern KAL_AFM_ID kal_afm_create(void *mem_addr, kal_uint32 size,
+                                 kal_uint32 *subpool_size, kal_uint32 *subpool_nr,
+                                 kal_uint32 flags, kal_uint32 *left_mem);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_afm_delete
+ * DESCRIPTION
+ *  delete a AFM pool.
+ * PARAMETERS
+ *  afm_id: [IN] AFM pool identity.
+ * RETURN VALUES
+ *  KAL_SUCCESS: the operation succeeded.
+ *  KAL_MEMORY_NOT_RELEASE: some user buffer is not freed yet.
+ * SEE ALSO
+ *  kal_afm_create
+ ******************************************************************************/
+extern kal_status kal_afm_delete(KAL_AFM_ID afm_id);
+
+extern void *kal_afm_internal_alloc(KAL_AFM_ID afm_id, kal_uint32 size,
+                                    kal_uint32 *    actual_size,
+                                    const kal_char *filename, kal_uint32 line);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_afm_alloc
+ * DESCRIPTION
+ *  allocate a memory buffer from AFM.
+ * PARAMETERS
+ *  afm_id: [IN] AFM pool identity.
+ *  size: [IN] request memory size.
+ * RETURNS
+ *  allocated memory buffer pointer. return NULL if no memory available.
+ * NOTE
+ *  the prototype of this API is:
+ *   void *kal_afm_alloc(KAL_AFM_ID afm_id, kal_uint32 size);
+ * SEE ALSO
+ *  kal_afm_create kal_afm_free
+ ******************************************************************************/
+#define kal_afm_alloc(afm_id, size) \
+    kal_afm_internal_alloc(afm_id, size, NULL, __FILE__, __LINE__)
+#define kal_afm_alloc_dbg(afm_id, size, actual_size, filename, line) \
+    kal_afm_internal_alloc(afm_id, size, actual_size, filename, line)
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_afm_free
+ * DESCRIPTION
+ *  free a memory buffer to dedicated AFM.
+ * PARAMETERS
+ *  afm_id: [IN] AFM pool identity.
+ *  ptr: [IN] memory buffer pointer to be freed. This pointer must be allocated from afm_id.
+ * RETURNS
+ *  N/A
+ * SEE ALSO
+ *  kal_afm_create kal_afm_alloc
+ ******************************************************************************/
+extern void kal_afm_free(KAL_AFM_ID afm_id, void *ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_afm_check_integrity
+ * DESCRIPTION
+ *  Check the healthy of AFM pool.
+ * PARAMETERS
+ *  afm_id: [IN] AFM pool identity.
+ * RETURNS
+ *  return bad memory block first found. If the AFM pool is healthy, return NULL to indicate
+ *  nothing wrong found.
+ ******************************************************************************/
+extern kal_int32 kal_afm_check_integrity(KAL_AFM_ID afm_id);
+
+extern void *kal_afm_internal_alloc_cacheable(KAL_AFM_ID adm_id, kal_uint32 size,
+                                              kal_uint32 *    actual_size,
+                                              const kal_char *filename,
+                                              kal_uint32      line);
+#if defined(__MTK_TARGET__) && \
+    (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
+#define __kal_afm_alloc_cacheable(afm_id, size, option_notused) \
+    kal_afm_internal_alloc_cacheable(afm_id, size, NULL, __FILE__, __LINE__)
+#define __kal_afm_alloc_cacheable_dbg(afm_id, size, option_notused, actual_size, \
+                                      filename, line)                            \
+    kal_afm_internal_alloc_cacheable(afm_id, size, actual_size, filename, line)
+#else
+#define __kal_afm_alloc_cacheable(afm_id, size, option_notused) \
+    kal_afm_internal_alloc(afm_id, size, NULL, __FILE__, __LINE__)
+#define __kal_afm_alloc_cacheable_dbg(afm_id, size, option_notused, actual_size, \
+                                      filename, line)                            \
+    kal_afm_internal_alloc(afm_id, size, actual_size, filename, line)
+#endif
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_afm_alloc_cacheable
+ * DESCRIPTION
+ *  allocate a memory buffer which is cacheable from AFM.
+ * PARAMETERS
+ *  afm_id: [IN] AFM pool identity.
+ *  size: [IN] request memory size.
+ *  option_notused: [IN] useless, ignored.
+ * RETURNS
+ *  allocated memory buffer pointer. return NULL if no memory available.
+ * NOTE
+ *  (1)the prototype of this API is:
+ *   void *kal_afm_alloc_cacheable(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 option_notused);
+ *  (2)This AFM must be created using AFM_OPT_ALIGN_ALLOC in kal_afm_create.
+ *  (3)The pointer is cacheable only on platform that has ARM MMU (such as ARM9/ARM11 platform).
+ *     If not, the pointer is still noncacheable.
+ * SEE ALSO
+ *  kal_afm_create kal_afm_alloc_noncacheable kal_afm_free
+ ******************************************************************************/
+#define kal_afm_alloc_cacheable(afm_id, size, option_notused) \
+    __kal_afm_alloc_cacheable(afm_id, size, option_notused)
+#define kal_afm_alloc_cacheable_dbg(afm_id, size, option_notused, actual_size, \
+                                    filename, line)                            \
+    __kal_afm_alloc_cacheable_dbg(afm_id, size, option_notused, actual_size,   \
+                                  filename, line)
+
+extern void *kal_afm_internal_alloc_noncacheable(KAL_AFM_ID afm_id, kal_uint32 size,
+                                                 kal_uint32 *actual_size,
+                                                 char *filename, kal_uint32 line);
+#if defined(__MTK_TARGET__) && \
+    (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
+#define __kal_afm_alloc_noncacheable(afm_id, size, option_notused) \
+    kal_afm_internal_alloc_noncacheable(afm_id, size, NULL, __FILE__, __LINE__)
+#define __kal_afm_alloc_noncacheable_dbg(afm_id, size, option_notused, actual_size, \
+                                         filename, line)                            \
+    kal_afm_internal_alloc_noncacheable(afm_id, size, actual_size, filename, line)
+#else
+#define __kal_afm_alloc_noncacheable(afm_id, size, option_notused) \
+    kal_afm_internal_alloc(afm_id, size, NULL, __FILE__, __LINE__)
+#define __kal_afm_alloc_noncacheable_dbg(afm_id, size, option_notused, actual_size, \
+                                         filename, line)                            \
+    kal_afm_internal_alloc(afm_id, size, actual_size, filename, line)
+#endif
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_afm_alloc_noncacheable
+ * DESCRIPTION
+ *  allocate a memory buffer which is noncacheable from AFM.
+ * PARAMETERS
+ *  adm_id: [IN] ADM pool identity.
+ *  size: [IN] request memory size.
+ *  option_notused: [IN] useless, ignored.
+ * RETURNS
+ *  allocated memory buffer pointer. return NULL if no memory available.
+ * NOTE
+ *  (1)the prototype of this API is:
+ *   void *kal_afm_alloc_noncacheable(KAL_ADM_ID adm_id, kal_uint32 size, kal_uint32 option_notused);
+ *  (2)This AFM must be created using AFM_OPT_ALIGN_ALLOC in kal_afm_create.
+ * SEE ALSO
+ *  kal_afm_create kal_afm_alloc_cacheable kal_afm_free
+ ******************************************************************************/
+#define kal_afm_alloc_noncacheable(afm_id, size, option_notused) \
+    __kal_afm_alloc_noncacheable(afm_id, size, option_notused)
+#define kal_afm_alloc_noncacheable_dbg(afm_id, size, option_notused, actual_size, \
+                                       filename, line)                            \
+    __kal_afm_alloc_noncacheable_dbg(afm_id, size, option_notused, actual_size,   \
+                                     filename, line)
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+extern kal_int32 kal_afm_print_log(KAL_AFM_ID afm_id);
+extern kal_int32 kal_afm_get_subpool_num(KAL_AFM_ID afm_id);
+extern kal_int32 kal_afm_info_get(KAL_AFM_ID afm_id, kal_uint32 *option,
+                                  kal_uint32 *buff_size, kal_uint32 *buff_nr,
+                                  kal_uint32 *left_buf_nr,
+                                  kal_uint32 *total_left_mem_sz);
+extern kal_int32 kal_afm_custom_performance_info_get(
+    KAL_AFM_ID afm_id, kal_uint32 *option, kal_uint32 *buff_size,
+    kal_uint32 *buff_nr, kal_uint32 *alloc_cnt, kal_uint32 *min_left_buf_nr);
+extern kal_int32 kal_afm_set_cuslogging(KAL_AFM_ID afm_id, kal_uint32 cus_log_opt);
+extern kal_int32 kal_afm_get_cuslogging(KAL_AFM_ID afm_id, kal_uint32 *cus_log_opt);
+extern kal_int32 kal_afm_get_left_subpool_num(KAL_AFM_ID afm_id, kal_uint32 size);
+extern kal_uint32 kal_afm_get_buff_size(KAL_AFM_ID afm_id, void *user_addr);
+/* DOM-NOT_FOR_SDK-END */
+
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+/*******************************************************************************
+ * Category 7 : System and Modem Memory Management
+ *******************************************************************************/
+extern void *get_ctrl_buffer_ext(kal_uint32 size, const kal_char *file_name,
+                                 kal_uint32 line);
+extern void free_ctrl_buffer_ext(void *buff_ptr, const kal_char *file_name,
+                                 kal_uint32 line);
+extern kal_uint32 query_ctrl_buffer_ext(kal_uint32 size);
+
+#if defined(DEBUG_KAL) && defined(DEBUG_BUF2)
+#define __get_ctrl_buffer(size) get_ctrl_buffer_ext(size, __FILE__, __LINE__)
+#define __free_ctrl_buffer(ptr) free_ctrl_buffer_ext(ptr, __FILE__, __LINE__)
+#else /* DEBUG_KAL && DEBUG_BUF2 */
+#define __get_ctrl_buffer(size) get_ctrl_buffer_ext(size, NULL, 0)
+#define __free_ctrl_buffer(ptr) free_ctrl_buffer_ext(ptr, NULL, 0)
+#endif /* DEBUG_KAL && DEBUG_BUF2 */
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  get_ctrl_buffer
+ * DESCRIPTION
+ *  get a memory block at least size bytes from ctrl buffer.
+ * PARAMETERS
+ *  size: [IN] request memory block.
+ * RETURNS
+ *  memory block pointer. If all memory blocks used in corresponding ctrl buffer
+ *  used up, system enter fatal error handling.
+ * NOTE
+ *  (1)This API should be used in protocol stack only.
+ * SEE ALSO
+ *  free_ctrl_buffer
+ ******************************************************************************/
+#define get_ctrl_buffer(size) __get_ctrl_buffer(size)
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  free_ctrl_buffer
+ * DESCRIPTION
+ *  free a memory block allocated from ctrl buffer.
+ * PARAMETERS
+ *  ptr: [IN] memory block pointer.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  (1)This API should be used in protocol stack only.
+ * SEE ALSO
+ *  get_ctrl_buffer
+ ******************************************************************************/
+#define free_ctrl_buffer(ptr) __free_ctrl_buffer(ptr)
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  free_ctrl_buffer_set_null
+ * DESCRIPTION
+ *  free a memory block allocated from ctrl buffer. then set pointer as null
+ * PARAMETERS
+ *  ptr: [IN] memory block pointer.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  (1)This API should be used in protocol stack only.
+ * SEE ALSO
+ *  get_ctrl_buffer
+ ******************************************************************************/
+#define free_ctrl_buffer_set_null(ptr) \
+    do {                               \
+        __free_ctrl_buffer(ptr);       \
+        ptr = NULL;                    \
+    } while (0)
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  query_ctrl_buffer
+ * DESCRIPTION
+ *  query the avaiable memory blocks from ctrl buffer
+ * PARAMETERS
+ *  size: [IN] request memory block.
+ * RETURNS
+ *  the number of avaiable memory blocks 
+ * SEE ALSO
+ *  get_ctrl_buffer
+ ******************************************************************************/
+#define query_ctrl_buffer(size) query_ctrl_buffer_ext(size)
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *	kal_debug_cbs_leakage_check_start
+ * DESCRIPTION
+ *	enable control buffer leakage check.
+ * PARAMETERS
+ *	N/A
+ * RETURNS
+ *	N/A
+ * SEE ALSO
+ *	 
+ ******************************************************************************/
+void kal_debug_cbs_leakage_check_start(void);
+void kal_debug_cbs_leakage_check_stop(void);
+
+extern kal_bool kal_set_sensitive_buff_ext(void *buff_ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *	kal_set_sensitive_buff
+ * DESCRIPTION
+ *	set the buffer as a sensitive data buffer.
+ * PARAMETERS
+ *    buff_ptr: [IN] memory block pointer.
+ * RETURNS
+ *	N/A
+ * SEE ALSO
+ *	 
+ ******************************************************************************/
+#define kal_set_sensitive_buff(ptr) kal_set_sensitive_buff_ext(ptr)
+
+/* DOM-NOT_FOR_SDK-END */
+/*******************************************************************************
+ * Category 8 : Timer Service
+ *******************************************************************************/
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_systicks
+ * DESCRIPTION
+ *  return elapsed system ticks from boot up
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  elapsed system ticks from boot up
+ * NOTE
+ *  (1)Each tick is KAL_MILLISECS_PER_TICK miliseconds.
+ * SEE ALSO
+ *  KAL_MILLISECS_PER_TICK
+ ******************************************************************************/
+extern kal_uint32 kal_get_systicks(void);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_secs_to_ticks
+ * DESCRIPTION
+ *  convert seconds to system ticks
+ * PARAMETERS
+ *  secs : [IN] seconds
+ * RETURNS
+ *  corresponding system ticks
+ * NOTE
+ *  This functions is equvilent to (secs * 1000 / KAL_MILLISECS_PER_TICK).
+ *  It uses table lookup to avoid floating division to speed up.
+ * SEE ALSO
+ *  kal_milli_secs_to_ticks KAL_MILLISECS_PER_TICK
+ ******************************************************************************/
+extern kal_uint32 kal_secs_to_ticks(kal_uint32 secs);
+extern kal_uint32 kal_secs_to_ticks_real(kal_uint32 secs);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_milli_secs_to_ticks
+ * DESCRIPTION
+ *  convert milliseconds to system ticks
+ * PARAMETERS
+ *  milli_secs : [IN] milliseconds
+ * RETURNS
+ *  corresponding system ticks
+ * NOTE
+ *  This functions is equvilent to ( ( milli_secs + KAL_MILLISECS_PER_TICK / 2 ) / KAL_MILLISECS_PER_TICK).
+ *  It uses table lookup to avoid floating division to speed up.
+ * SEE ALSO
+ *  kal_milli_secs_to_ticks KAL_MILLISECS_PER_TICK
+ ******************************************************************************/
+extern kal_uint32 kal_milli_secs_to_ticks(kal_uint32 milli_secs);
+extern kal_uint32 kal_milli_secs_to_ticks_real(kal_uint32 milli_secs);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_ticks_to_secs
+ * DESCRIPTION
+ *  convert system ticks to seconds
+ * PARAMETERS
+ *  ticks : [IN] ticks count
+ * RETURNS
+ *  corresponding seconds
+ * NOTE
+ *  This functions is equvilent to (ticks * KAL_MILLISECS_PER_TICK / 1000).
+ *  It uses table lookup to avoid floating multiplication to speed up.
+ * SEE ALSO
+ *  kal_ticks_to_milli_secs KAL_MILLISECS_PER_TICK
+ ******************************************************************************/
+extern kal_uint32 kal_ticks_to_secs(kal_uint32 ticks);
+extern kal_uint32 kal_ticks_to_secs_real(kal_uint32 ticks);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_ticks_to_milli_secs
+ * DESCRIPTION
+ *  convert system ticks to milliseconds
+ * PARAMETERS
+ *  ticks : [IN] ticks count
+ * RETURNS
+ *  corresponding milliseconds
+ * NOTE
+ *  This functions is equvilent to (ticks * KAL_MILLISECS_PER_TICK).
+ *  It uses table lookup to avoid floating multiplication to speed up.
+ * SEE ALSO
+ *  kal_ticks_to_secs KAL_MILLISECS_PER_TICK
+ ******************************************************************************/
+extern kal_uint32 kal_ticks_to_milli_secs(kal_uint32 ticks);
+extern kal_uint32 kal_ticks_to_milli_secs_real(kal_uint32 ticks);
+
+/*******************************************************************************
+ * Category 8 : Timer Service
+ *******************************************************************************/
+/*************************************************************************
+ * Exported Function Prototypes for KAL timer
+ *************************************************************************/
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_create_timer
+ * DESCRIPTION
+ *  create a kal timer.
+ * PARAMETERS
+ *  timer_name : [IN] timer name. It's used for debug only, and only the
+ *                first 8 characters retain.
+ * RETURNS
+ *  Success:        timer pointer.
+ *  Error:          system enter fatal error handling.
+ * NOTE
+ *  (1)It is strongly suggested to call this function only at system initialization stage,
+ *     and the related data allocated for the timer could not be freed once it is created.
+ *  (2)kal timer API is not thread safe and it's strongly suggested to use it
+ *     in single task/HISR only.
+ * SEE ALSO
+ *  kal_set_timer kal_cancel_timer kal_get_remaining_time kal_enable_delayed_timer kal_disable_delayed_timer
+ ******************************************************************************/
+kal_timerid kal_create_timer(kal_char *timer_name);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_set_timer
+ * DESCRIPTION
+ *  start a kal timer.
+ * PARAMETERS
+ *  timer_ptr : [IN] timer pointer.
+ *  handler_func_ptr: [IN] pointer of timeout handler, it will be called after
+ *                    timeout happens
+ *  handler_param_ptr: [IN] user supply argument for handler_func_ptr
+ *  delay: [IN] timeout duration in terms of time ticks, the maximum value is 0xFFFFFFFF
+ *  reschedule_time: [IN] reset delay to reschedule_time after timeout happens.
+ *                   If it's zero, no reschedule happens and the timer is one-shot.
+ *                   Otherwise, it's a periodic timer.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  kal_set_timer will cancel previous set timeout event on this timer, and
+ *  start a new one.
+ * SEE ALSO
+ *  kal_create_timer kal_cancel_timer kal_get_remaining_time kal_enable_delayed_timer kal_disable_delayed_timer
+ ******************************************************************************/
+void kal_set_timer(kal_timerid timer_ptr, kal_timer_func_ptr handler_func_ptr,
+                   void *handler_param_ptr, kal_uint32 delay,
+                   kal_uint32 reschedule_time);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_cancel_timer
+ * DESCRIPTION
+ *  cancel a kal timer.
+ * PARAMETERS
+ *  timer_ptr : [IN] timer pointer.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  Please note that canceling timer inside HISR may cancel a timer which is
+ *  in expired stage but the callback function not yet been serviced.
+ * SEE ALSO
+ *  kal_create_timer kal_set_timer kal_get_remaining_time kal_enable_delayed_timer kal_disable_delayed_timer
+ ******************************************************************************/
+void kal_cancel_timer(kal_timerid timer_ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_get_remaining_time
+ * DESCRIPTION
+ *  retrieve the remaining timeout period in units of time ticks
+ * PARAMETERS
+ *  timer_ptr : [IN] timer pointer.
+ * RETURNS
+ *  N/A
+ * SEE ALSO
+ *  kal_create_timer kal_set_timer kal_cancel_timer kal_enable_delayed_timer kal_disable_delayed_timer
+ ******************************************************************************/
+kal_uint32 kal_get_remaining_time(kal_timerid timer_ptr);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_enable_delayed_timer
+ *
+ * DESCRIPTION
+ *  This routine implements to set the timer as an aligned timer, the max delay feature will be kept 
+ *  until kal_disable_delayed_timer() is invoked.
+ *      Application Scenario is listed below:
+ *          case 1: for target_API = [ kal_sleep_task(), kal_retrieve_eg_events_timeout() ]
+ *
+ *              --> status = kal_enable_delayed_timer(NULL, max_delay);
+ *
+ *              Attention:
+ *                  a. the API return value(status) must be checked: KAL_SUCCESS -> success, others -> fail
+ *                  b. max_delay is in ticks, not ms, if you want to set max delay time to (x ms), you
+ *                      should use this API like this:
+ *                      --> status = kal_enable_delayed_timer(NULL, kal_milli_secs_to_ticks(x));
+ *
+ *          case 2: for target_API = [ kal_set_timer() ]
+ *
+ *              --> status = kal_enable_delayed_timer(TIMER_ID, max_delay);
+ *
+ *              Attention:
+ *                  a. the API return value(status) must be checked: KAL_SUCCESS -> success, others -> fail
+ *                  b. max_delay is in ticks, not ms, if you want to set max delay time to (x ms), you
+ *                      should use this API like this:
+ *                      --> status = kal_enable_delayed_timer(TIMER_ID, kal_milli_secs_to_ticks(x));
+ *
+ * PARAMETERS
+ *  ext_timer: Id of the timer
+ *  max_delay	: max delay ticks
+ * RETURNS
+ *	KAL_SUCCESS --> success
+ *	KAL_TIMER_NON_TASK_CONTEXT --> invoked illegally in NON-Task context
+ *	KAL_TIMER_INVALID_TIMER_ID --> KAL timer ID is invalid
+ *    KAL_TIMER_MAX_DELAY_OUT_OF_RANGE --> max delay ticks is out of range
+ * SEE ALSO
+ *  kal_create_timer kal_set_timer kal_cancel_timer kal_get_remaining_time kal_disable_delayed_timer
+ ******************************************************************************/
+kal_status kal_enable_delayed_timer(kal_timerid ext_timer, kal_uint32 max_delay);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_disable_delayed_timer
+ *
+ * DESCRIPTION
+ *  This routine implements to set the timer as an unaligned timer. normally this API will be used with 
+ *  kal_enable_delayed_timer together.
+ *      Application Scenario is listed below:
+ *          case 1: for target_API = [ kal_sleep_task(), kal_retrieve_eg_events_timeout() ]
+ *
+ *              status = kal_disable_delayed_timer(NULL);
+ *
+ *          case 2: for target_API = [ kal_set_timer() ]
+ *
+ *              status = kal_disable_delayed_timer(TIMER_ID);
+ *
+ *      Attention: 
+ *          a. the API return value(status) must be checked: KAL_SUCCESS -> success, others -> fail
+ *          b. max delay feature will be kept unchanged if kal_disable_delayed_timer() isn't invoked.
+ *
+ * PARAMETERS
+ *  ext_timer: Id of the timer
+ * RETURNS
+ *  KAL_SUCCESS --> success
+ *  KAL_TIMER_NON_TASK_CONTEXT --> invoked illegally in NON-Task context
+ * SEE ALSO
+ *  kal_create_timer kal_set_timer kal_cancel_timer kal_get_remaining_time kal_enable_delayed_timer
+ ******************************************************************************/
+kal_status kal_disable_delayed_timer(kal_timerid ext_timer);
+
+/* DOM-NOT_FOR_SDK-END */
+
+/*************************************************************************
+ * Exported Function Prototypes for event scheduler
+ *************************************************************************/
+
+/*******************************************************************************
+ * <GROUP CallBackFunctions>
+ *
+ * FUNCTION
+ *  malloc_fp_t
+ * DESCRIPTION
+ *  pointer to a function that can allocation memory like malloc.
+ * PARAMETERS
+ *  size: [IN] request memory size in byte.
+ * RETURNS
+ *  Successful: memory pointer.
+ *  Fail:       NULL.
+ ******************************************************************************/
+typedef void *(*malloc_fp_t)(unsigned int size);
+/*******************************************************************************
+ * <GROUP CallBackFunctions>
+ *
+ * FUNCTION
+ *  realloc_fp_t
+ * DESCRIPTION
+ *  pointer to a function that can re-allocation memory like realloc.
+ * PARAMETERS
+ *  ptr: [IN] old pointer.
+ *  new_size: [IN] new request memory size in byte.
+ * RETURNS
+ *  Successful: memory pointer.
+ *  Fail:       NULL.
+ ******************************************************************************/
+typedef void *(*realloc_fp_t)(void *ptr, unsigned int new_size);
+/*******************************************************************************
+ * <GROUP CallBackFunctions>
+ *
+ * FUNCTION
+ *  free_fp_t
+ * DESCRIPTION
+ *  pointer to a function that can free memory like free.
+ * PARAMETERS
+ *  ptr: [IN] memory pointer to be free.
+ * RETURNS
+ *  N/A
+ ******************************************************************************/
+typedef void (*free_fp_t)(void *ptr);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  evshed_create
+ * DESCRIPTION
+ *  create a new event scheduler.
+ * PARAMETERS
+ *  timer_name: [IN] event scheduler name. it's used for debug only, and only the
+ *                    first 8 characters retain.
+ *  dest_mod_id: [IN] the module this event scheduler belongs to. When event scheduler
+ *              timeout happens, system sent timeout message to task of this module.
+ *  fuzz: [IN]
+ *      Timer inaccuracy in ticks that the event scheduler allow, regardless of sleep mode.
+ *      If set, the event may delay or prematurely timeout for maximum fuzz ticks.
+ *      If don't like it, just set it to 0.
+ *
+ *      Advantage -
+ *      Set this argument will save you a lot of CPU resource if the events are frequent and close to each other.
+ *
+ *  max_delay_ticks: [IN]
+ *      Behaviour -
+ *      Time inaccuracy in ticks the event scheduler allow, due to target enters sleep mode.
+ *      The event may delay for max max_delay_ticks tick if the target enters sleep mode,
+ *      so that the target can sleep longer. The event will suffer no delay if the target doesn't enter sleep mode.
+ *
+ *      Advantage -
+ *      Set this argument will save the target a lot of power. You are encouraged to set this value for the sake of power.
+ *
+ *      Note -
+ *      max_delay_ticks = 0 ~ (MAX_DELAY_UNLIMITED - 1) ticks, exact delay ticks
+ *      max_delay_ticks = MAX_DELAY_UNLIMITED ticks, won't wake up MCU from sleep (maximum save power).
+ *
+ * RETURNS
+ *  Successful: created event scheduler pointer.
+ *  Fail: system enter fatal error handling.
+ * NOTE
+ *  (1)This API replaces new_evshed(). And new_evshed() is deprecated,
+ *     it will be removed from next release.
+ *  (2)It is strongly suggested to call this function only at system initialization stage.
+ *     and There is no way to free the event schedule data structure once allocated.
+ *  (3)Event scheduler is not thread safe, if you want to share it in multi-task/hisr,
+ *     please use lock to protect it.
+ *  (4)To reduce power consumption, it's strongly suggested to set max_delay_ticks.
+ *  (5)The inaccuracy of event scheduler comes from
+ *       schedule delay -  Time lisr, Time HISR, the owner task may be preempted.
+ *       Task handling message delay - There may be many ILMs to handle before the event expired ILM gets handled
+ *       fuzz
+ *       max_delay_ticks
+ * SEE ALSO
+ *  evshed_set_event evshed_cancel_event evshed_timer_handler
+ ******************************************************************************/
+extern event_scheduler *evshed_create(kal_char *timer_name, module_type dest_mod_id,
+                                      kal_uint32 fuzz,
+                                      kal_uint32 max_delay_ticks);
+#define HAS_EVSHED_CREATE 1
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *      evshed_set_index
+ * DESCRIPTION
+ *      Set timer_index to distinguish many event schedulers.
+ *      The default timer index is 0.
+ * PARAMETERS
+ *      es_usr: [IN] event scheduler id returned by evshed_create
+ *      timer_index: [IN] timer index given by user
+ * RETURNS
+ *      None
+ ******************************************************************************/
+extern void evshed_set_index(event_scheduler *es, kal_uint16 timer_index);
+#define HAS_EVSHED_SET_INDEX 1
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *      evshed_get_index
+ * DESCRIPTION
+ *      Get the index set by evshed_set_index
+ * PARAMETERS
+ *      expired_ilm: [IN] The ilm sent by expired event and got from task queue
+ * RETURNS
+ *      Sucessful: The timer index of kal_uint32
+ *      Fail: Fatal error if wrong ilm input
+ ******************************************************************************/
+extern kal_uint16 evshed_get_index(ilm_struct *expired_ilm);
+#define HAS_EVSHED_GET_INDEX 1
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  evshed_set_event
+ * DESCRIPTION
+ *  set an event on event scheduler.
+ * PARAMETERS
+ *  es: [IN] event scheduler pointer.
+ *  event_hf: [IN] the callback function when event timeout.
+ *  event_hf_param: [IN] the user supplied argument for event_hf.
+ *  elapse_time: [IN] how many system ticks elapses before this event timeout.
+ * RETURNS
+ *  Successful: return set eventid.
+ *  Fail: return NULL.
+ * NOTE
+ *  System will allocate memory for event id, it will be freed automatically when
+ *      a. event is cancelled
+ *      b. event expired
+ *   It's not allowed to use the event id after above cases.
+ *   If the event id is saved, please be careful to reset it.
+ * SEE ALSO
+ *  evshed_create evshed_cancel_event evshed_timer_handler
+ ******************************************************************************/
+extern eventid evshed_set_event(event_scheduler *es, kal_timer_func_ptr event_hf,
+                                void *event_hf_param, kal_uint32 elapse_time);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  evshed_set_event_userid
+ * DESCRIPTION
+ *  set an event on event scheduler, and give this event an user id
+ * PARAMETERS
+ *  es: [IN] event scheduler pointer.
+ *  event_hf: [IN] the callback function when event timeout.
+ *  event_hf_param: [IN] the user supplied argument for event_hf.
+ *  elapse_time: [IN] how many system ticks elapses before this event timeout.
+ *  event_user_id: [IN] User can input an id to distinct the events.
+ * RETURNS
+ *  Successful: return set eventid.
+ *  Fail: return NULL.
+ * NOTE
+ *  System will allocate memory for event id, it will be freed automatically when
+ *      a. event is cancelled
+ *      b. event expired
+ *   It's not allowed to use the event id after above cases.
+ *   If the event id is saved, please be careful to reset it.
+ * SEE ALSO
+ *  evshed_create evshed_cancel_event evshed_timer_handler
+ ******************************************************************************/
+extern eventid evshed_set_event_userid(event_scheduler *es,
+                                       kal_timer_func_ptr event_hf,
+                                       void *event_hf_param, kal_uint32 elapse_time,
+                                       kal_uint32 event_user_id);
+#define HAS_EVSHED_SET_EVENT_USERID 1
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  evshed_get_event_userid
+ * DESCRIPTION
+ * Get the user id, inputted in evshed_set_event_userid
+ * PARAMETERS
+ *  user_eventid: [IN] eventid returned by evshed_set_event_userid
+ * RETURNS
+ *  Successful: returns kal_uint32
+ *  Fail: If user_eventid is NULL, fatal error
+ * SEE ALSO
+ *  evshed_create evshed_cancel_event evshed_timer_handler
+ ******************************************************************************/
+extern kal_uint32 evshed_get_event_userid(eventid user_eventid);
+#define HAS_EVSHED_GET_EVENT_USERID 1
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  evshed_cancel_event
+ * DESCRIPTION
+ *  cancel a event on event scheduler.
+ * PARAMETERS
+ *  es: [IN] event scheduler pointer.
+ *  eid: [IN,OUT] pointer to event id.
+ * RETURNS
+ *  Successful: remain ticks before this event expires.
+ *  Fail: -1.
+ * NOTE
+ *  (1)system would reset the event ID (eid) to NULL before returning; however,
+ *     caller should pay attention to its privately saved event id
+ * SEE ALSO
+ *  evshed_create evshed_set_event evshed_timer_handler evshed_delete_all_events
+ ******************************************************************************/
+extern kal_int32 evshed_cancel_event(event_scheduler *es, eventid *eid);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  evshed_get_remaining_time
+ * DESCRIPTION
+ *  get remain ticks before this event expires.
+ * PARAMETERS
+ *  es: [IN] event scheduler pointer.
+ *  eid: [IN] event id.
+ * RETURNS
+ *  Successful: remain ticks before this event expires.
+ ******************************************************************************/
+extern kal_uint32 evshed_get_remaining_time(event_scheduler *es, eventid eid);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  evshed_delete_all_events
+ * DESCRIPTION
+ *  delete and cancel all events on event scheduler.
+ * PARAMETERS
+ *  es: [IN] event scheduler pointer.
+ * RETURNS
+ *  N/A
+ * SEE ALSO
+ *  evshed_create evshed_set_event evshed_timer_handler evshed_delete_all_events
+ *****************************************************************************/
+extern void evshed_delete_all_events(event_scheduler *es);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  evshed_timer_handler
+ * DESCRIPTION
+ *  event scheduler main function. It will check all set events status, and call
+ *  the callback function if they are expired.
+ *
+ * PARAMETERS
+ *  es: [IN] event scheduler pointer.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  (1)it's not thread-safe. Don't use in parallel.
+ *  (2)If an event is expired, the eventid is freed automatically and don't use it any more.
+ *     In evshed_timer_handler(), system would execute event registered timeout callback function.
+ *     Caller should reset saved event id in registered timeout callback function,
+ *     or cause potential bug to cancel wrong timer event.
+ * SEE ALSO
+ *  evshed_create evshed_set_event evshed_cancel_event evshed_delete_all_events
+ *****************************************************************************/
+extern void evshed_timer_handler(event_scheduler *es);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  evshed_has_pending_events
+ * DESCRIPTION
+ *  query there is any event pending (not yet expired).
+ * PARAMETERS
+ *  es: [IN] event scheduler pointer.
+ * RETURNS
+ *  return KAL_TRUE or KAL_FALSE.
+ * NOTE
+ *****************************************************************************/
+extern kal_bool evshed_has_pending_events(event_scheduler *es);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  evshed_suspend_all_events
+ * DESCRIPTION
+ *  suspend all of the events set on an event scheduler.
+ * PARAMETERS
+ *  es: [IN] event scheduler pointer.
+ * RETURNS
+ *  N/A
+ * SEE ALSO
+ *  evshed_resume_all_events
+ *****************************************************************************/
+extern void evshed_suspend_all_events(event_scheduler *es);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  evshed_resume_all_events
+ * DESCRIPTION
+ *  resume all of the events set on an event scheduler.
+ * PARAMETERS
+ *  es: [IN] event scheduler pointer.
+ * RETURNS
+ *  N/A
+ * SEE ALSO
+ *  evshed_suspend_all_events
+ *****************************************************************************/
+extern void evshed_resume_all_events(event_scheduler *es);
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  evshed_enable_protect_property
+ * DESCRIPTION
+ *  using mutex to protect the operation of event seheduler to avoid race condition whiler it is 
+ *  shared by multi-task
+ * PARAMETERS
+ *  es: [IN] event scheduler pointer.
+ * RETURNS
+ *  N/A
+ * NOTE
+ *  (1) Event scheduler is not thread safe, if you want to share it in multi-task,
+ *      You can use lock to protect it while using operation of event scheduler.
+ *      This API is designed for it. Please call this function after calling evshed_create,
+ *      then event scheduler is thread safe without using lock.
+ *  (2) If this is called, the "expired" event could not be deleted by evshed_cancel_event()
+ * SEE ALSO
+ *  evshed_create
+ *****************************************************************************/
+extern void evshed_enable_protect_property(event_scheduler *es);
+
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+/*******************************************************************************
+ * Category 9 : Error Handling
+ *******************************************************************************/
+#include "kal_ex_api.h"
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+
+/*******************************************************************************
+ * Category 10 --- Profiling
+ *******************************************************************************/
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_profile_enable
+ * DESCRIPTION
+ *  enable cpu usage profile.
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  N/A
+ * SEE ALSO
+ *   kal_profile_get_cpu_usage
+ ******************************************************************************/
+void kal_profile_enable(void);
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_profile_get_cpu_usage
+ * DESCRIPTION
+ *  get cpu usage percentage, which is a float number at [0.0, 1.0].
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  cpu usage percentage.
+ * SEE ALSO
+ *   kal_profile_enable
+ ******************************************************************************/
+float kal_profile_get_cpu_usage(void);
+
+/* DOM-NOT_FOR_SDK-END */
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+/*******************************************************************************
+ * Category 11 : stack sharing
+ *******************************************************************************/
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_lock_current_stack
+ * DESCRIPTION
+  *  to lock current stack to avoid sharing its memory with other tasks.
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  KAL_SUCCESS.
+ * NOTE
+ *  this API is used when KAL_STACK_SHARING is enable,
+ ******************************************************************************/
+extern kal_uint32 kal_lock_current_stack();
+
+/*******************************************************************************
+ * <GROUP Functions>
+ *
+ * FUNCTION
+ *  kal_unlock_current_stack
+ * DESCRIPTION
+ *  to unlock current task's stack to sharing its memory with other tasks.
+ * PARAMETERS
+ *  N/A
+ * RETURNS
+ *  KAL_SUCCESS.
+ * NOTE
+ *  this API is used when KAL_STACK_SHARING is enable,
+ ******************************************************************************/
+extern kal_uint32 kal_unlock_current_stack();
+
+/*******************************************************************************
+ * Category Last ---
+ *******************************************************************************/
+
+/* DOM-NOT_FOR_SDK-END */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _KAL_PUBLIC_API_H */
diff --git a/mcu/interface/service/kal/kal_public_defs.h b/mcu/interface/service/kal/kal_public_defs.h
new file mode 100644
index 0000000..0c877e6
--- /dev/null
+++ b/mcu/interface/service/kal/kal_public_defs.h
@@ -0,0 +1,2445 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   kal_public_defs.h
+ *
+ * Project:
+ * --------
+ *   Maui_Software
+ *
+ * Description:
+ * ------------
+ *   This file provides public and common types definations.
+ *   Note this file will inhirit RTOS header file
+ *
+ *   Data type definitions in this file are visible for KAL Public Users.
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ ****************************************************************************/
+
+#ifndef _KAL_PUBLIC_DEFS_H
+#define _KAL_PUBLIC_DEFS_H
+
+#include "kal_general_types.h"
+#ifndef _DEBUG_MSG_SAP_
+#include "stack_config.h" /* module_type & task_indx_type */
+#endif
+#include "stack_msgs.h" /* sap_type & msg_type */
+#include "hisr_config_defs.h" /* kal_hisr */
+
+/*******************************************************************************
+ * Type Definitions
+ *******************************************************************************/
+
+/* opaque type for task identity */
+typedef struct {
+    kal_uint8 unused;
+} kal_taskid_s;
+typedef kal_taskid_s *kal_taskid;
+
+/* opaque type for hisr identity */
+typedef struct {
+    kal_uint8 unused;
+} kal_hisrid_s;
+typedef kal_hisrid_s *kal_hisrid;
+
+/* opaque type for semaphore identity */
+typedef struct {
+    kal_uint8 unused;
+} kal_semid_s;
+typedef kal_semid_s *kal_semid;
+
+/* opaque type for message queue identity */
+typedef struct {
+    kal_uint8 unused;
+} kal_msgqid_s;
+typedef kal_msgqid_s *kal_msgqid;
+
+/* contain message queue information */
+typedef struct {
+    /* current number of pending messages in message queue */
+    kal_uint32 pending_msgs;
+    /* maximum number of pending messages in message queue */
+    kal_uint32 max_msgs;
+} kal_msgq_info;
+
+/* opaque type for mutex identity */
+typedef struct {
+    kal_uint8 unused;
+} kal_mutexid_s;
+
+typedef kal_mutexid_s *kal_mutexid;
+
+/* opaque type for event group identity */
+typedef struct {
+    kal_uint8 unused;
+} kal_eventgrpid_s;
+typedef kal_eventgrpid_s *kal_eventgrpid;
+
+/* opaque type for spinlock identity */
+typedef struct {
+    kal_uint8 unused;
+} kal_spinlockid_s;
+typedef kal_spinlockid_s* kal_spinlockid;
+typedef kal_spinlockid_s* kal_lockid;
+
+/* NOTE: Atomic variables must be in cacheable memory */
+typedef kal_int32  kal_atomic_int32;
+typedef kal_uint32 kal_atomic_uint32;
+
+/* opaque type for partition memory pool identity */
+typedef struct {
+    kal_uint8 unused;
+} kal_poolid_s;
+
+typedef kal_poolid_s *kal_poolid;
+
+/* opaque type for Application Dynamic Memory identity */
+typedef struct {
+    kal_uint8 unused;
+} KAL_ADM_ID_s;
+typedef KAL_ADM_ID_s *KAL_ADM_ID;
+
+/* opaque type for Application Fix Memory identity */
+typedef struct {
+    kal_uint8 unused;
+} KAL_AFM_ID_s;
+typedef KAL_AFM_ID_s *KAL_AFM_ID;
+
+/* opaque type for First Level Memory Manager identity */
+typedef struct {
+    kal_uint8 unused;
+} KAL_FLMM_ID_s;
+typedef KAL_FLMM_ID_s *KAL_FLMM_ID;
+
+/* opaque type for Second Level Memory Manager identity */
+typedef struct {
+    kal_uint8 unused;
+} KAL_SLMM_ID_s;
+typedef KAL_SLMM_ID_s *KAL_SLMM_ID;
+
+/* opaque type for enhance mutex identity */
+typedef struct {
+    kal_uint8 unused;
+} kal_enhmutexid_s;
+typedef kal_enhmutexid_s *kal_enhmutexid;
+
+/* opaque type for kal timer identity */
+typedef struct {
+    kal_uint8 unused;
+} kal_timerid_s;
+
+typedef kal_timerid_s *kal_timerid;
+
+/* opaque type for event scheduler identity */
+typedef struct event_scheduler {
+    kal_uint8 unused;
+} event_scheduler;
+
+/* opaque type for event identity */
+typedef struct {
+    kal_uint8 unused;
+} eventid_s;
+
+typedef eventid_s *eventid;
+
+/* task entry function parameter */
+typedef struct task_entry_struct {
+    /* paremeter of task main entry*/
+    kal_uint32 parameter;
+} task_entry_struct;
+
+/* general function pointer prototype */
+typedef void (*kal_func_ptr)(void);
+/* task entry function prototype */
+typedef void (*kal_task_func_ptr)(task_entry_struct *task_entry_ptr);
+/* hisr entry function prototype */
+typedef void (*kal_hisr_func_ptr)(void);
+/* timer (kal timer, stack timer, event scheduler) callback function prototype */
+typedef void (*kal_timer_func_ptr)(void *param_ptr);
+/* IRQ ISR handler function prototype */
+typedef void (*irq_isr_hdlr_ptr)(kal_uint32);
+/* IRQ ISR handler function prototype */
+typedef void (*irq_init_func_ptr)(kal_uint32);
+/* task clean up handler function prototype */
+typedef void (*kal_task_clean_hdlr_ptr)(void);
+
+/*************************************************************************
+ * Type Definitions for ILM communication
+ *************************************************************************/
+
+/* transfer direction flags for local_para & peer_buff, only TD_RESET is meaningful now */
+typedef enum {
+    TD_UL    = 0x01 << 0, /* Uplink Direction, obsolete */
+    TD_DL    = 0x01 << 1, /* Downlink Direction, obsolete */
+    TD_CTRL  = 0x01 << 2, /* Control Plane. Both directions, obsolete */
+    TD_RESET = 0x01 << 3  /* Reset buffer content to 0 */
+} transfer_direction;
+
+#define LOCAL_PARA_HDR      \
+    kal_uint8  ref_count;   \
+    kal_uint8  lp_reserved; \
+    kal_uint16 msg_len;
+/*  common local_para header */
+typedef struct local_para_struct {
+    /* ref_count: reference count; 
+     * lp_reserved : reserved for future; 
+     * msg_len  : total length including this header.
+     */
+    LOCAL_PARA_HDR
+#ifdef __BUILD_DOM__
+        ;
+#endif
+} local_para_struct;
+
+#define PEER_BUFF_HDR             \
+    kal_uint16 pdu_len;           \
+    kal_uint8  ref_count;         \
+    kal_uint8  pb_resvered;       \
+    kal_uint16 free_header_space; \
+    kal_uint16 free_tail_space;
+/* peer buffer header, user should treat it as opaque type */
+typedef struct peer_buff_struct {
+    PEER_BUFF_HDR
+#ifdef __BUILD_DOM__
+        ;
+#endif
+} peer_buff_struct;
+
+typedef kal_uint16 interrupt_type;
+typedef kal_uint16 module_type;
+typedef kal_uint16 sap_type;
+typedef kal_uint16 msg_type;
+
+/* The Interlayer Message structure, which is exchaged between modules. */
+typedef struct ilm_struct {
+    module_type        src_mod_id;     /* Source module ID of the message. */
+    module_type        dest_mod_id;    /* Destination module ID of the message. */
+    sap_type           sap_id;         /* Service Access Pointer Identifier. */
+    msg_type           msg_id;         /* Message identifier */
+    local_para_struct *local_para_ptr; /* local_para pointer */
+    peer_buff_struct * peer_buff_ptr;  /* peer_buff pointer */
+} ilm_struct;
+
+/* The Interlayer Inline Message structure, which is exchaged between modules. */
+typedef struct
+{
+    module_type        src_mod_id;     /* Source module ID of the message. */
+    module_type        dest_mod_id;    /* Destination module ID of the message. */
+    sap_type           sap_id;         /* Service Access Pointer Identifier. */
+    msg_type           msg_id;         /* Message identifier */
+    kal_uint32         data[2];        /* Inline data */
+} inl_struct;
+
+/* Union wrapper type for ILM and inline (INL) structures */
+typedef union
+{
+    ilm_struct ilm;
+    inl_struct inl;
+} ilm_inl_u;
+
+/* maximum payload size in an inline-ILM message */
+#define MSG_INLINE_ILM_MAX_PAYLOAD \
+    (sizeof(local_para_struct *) + sizeof(peer_buff_struct *))
+
+typedef enum {
+    dummy_timer_status1,
+    dummy_timer_status2,
+} dummy_es_timer_status;
+
+typedef struct event_scheduler_dummy {
+    kal_uint32            reserved[4];
+    kal_uint8             reserved1[3];
+    kal_bool              reserved2;
+    kal_uint32            reserved3[2];
+    dummy_es_timer_status es_timer_status;
+    module_type           dest_mod_id;
+    kal_uint16            es_user_index;
+    kal_uint32            reserved4[2];
+} event_scheduler_dummy;
+
+typedef event_scheduler_dummy timer_expiry_struct;
+
+#if defined KAL_ON_OSCAR
+#ifdef DEBUG_BUF2
+typedef struct {
+    void *     start_address;
+    kal_char   file_name[32];
+    kal_uint32 line;
+    kal_uint32 alloc_id;
+    kal_uint32 size;
+    kal_uint32 ticks_alloc;
+    kal_uint32 reserved;
+} kal_ctrl_buff_stats;
+#endif /* DEBUG_BUF2 */
+#endif
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+/*******************************************************************************
+ * Constant definition
+ *******************************************************************************/
+#if defined(KAL_ON_OSCAR)
+
+#define KAL_CONSUME 0x4 //OSC_ACTION_CLS
+#define KAL_AND 0x1     //OSC_ACTION_FULL_SET
+#define KAL_AND_CONSUME \
+    (KAL_AND | KAL_CONSUME)                   //OSC_ACTION_FULL_SET | OSC_ACTION_CLS
+#define KAL_OR 0x2                            //OSC_ACTION_PART_SET
+#define KAL_OR_CONSUME (KAL_OR | KAL_CONSUME) //OSC_ACTION_PART_SET | OSC_ACTION_CLS
+#define KAL_NO_SUSPEND 0                      //OSC_TIMEOUT_NONE
+#define KAL_SUSPEND 0xFFFFFFFF                //OSC_TIMEOUT_FOREVER
+
+#elif defined(KAL_ON_OSABS)
+
+typedef enum {
+    KAL_CONSUME,
+    KAL_AND,
+    KAL_AND_CONSUME,
+    KAL_OR,
+    KAL_OR_CONSUME,
+    KAL_NO_SUSPEND,
+    KAL_SUSPEND
+};
+
+#elif defined(KAL_ON_MERTOS)
+
+#define KAL_CONSUME           0x10
+#define KAL_AND               0x02
+#define KAL_AND_CONSUME       0x12
+#define KAL_OR                0x01
+#define KAL_OR_CONSUME        0x11
+#define KAL_NO_SUSPEND        0
+#define KAL_SUSPEND           0xFFFFFFFFUL
+
+#endif
+
+#define KAL_NILTASK_ID (kal_taskid) NULL
+#define KAL_NILHISR_ID (kal_hisrid) NULL
+#define KAL_NILTIMER_ID (kal_timerid) NULL
+#define KAL_NILPOOL_ID (kal_poolid) NULL
+#define KAL_NILMUTEX_ID (kal_mutexid) NULL
+#define KAL_NILEVENTGRP_ID (kal_eventgrpid) NULL
+#define KAL_NILSEM_ID (kal_semid) NULL
+#define KAL_NILQ_ID (kal_msgqid) NULL
+#define KAL_NILSEC (kal_uint32)0xffffffff
+#define KAL_NILMSEC (kal_uint16)0xffff
+#define KAL_NILTICK (kal_uint32)0xffffffff
+#define KAL_NILSPINLOCK_ID (kal_spinlockid) NULL
+/* DOM-NOT_FOR_SDK-END */
+
+/*******************************************************************************
+ * Constant definition Referenced By Public APIs
+ *******************************************************************************/
+typedef enum {
+    KAL_SW_CONTEXT_INIT,
+    KAL_SW_CONTEXT_TASK,
+    KAL_SW_CONTEXT_LISR,
+    KAL_SW_CONTEXT_HISR,
+    KAL_SW_CONTEXT_EXCP,
+    KAL_SW_CONTEXT_TYPE_END
+} kal_sw_context_type;
+
+/* boot mode enumeration */
+typedef enum {
+    /* factory mode, system boot up to communicate with factory tools */
+    FACTORY_BOOT = 0,
+    /* normal mode */
+    NORMAL_BOOT = 1,
+    /* USB mode, system boot up when USB charger connect */
+    USBMS_BOOT = 2,
+    /* Firmware Update Engine mode, system run inside FUE */
+    FUE_BOOT = 3,
+    /* number of known boot mode */
+    NUM_OF_BOOT_MODE,
+    /* unknown mode */
+    UNKNOWN_BOOT_MODE = 0xff
+} boot_mode_type;
+
+/* adm feature option used in kal_adm_create2 */
+/* DOM-NOT_FOR_SDK-BEGIN */
+#define KAL_ADM_OLD_ISLOGGING_FLAG 0x1
+#define KAL_ADM_PROFILE_FLAG 0x2
+/* DOM-NOT_FOR_SDK-END */
+/* put a guard word before and after each user buffer to detect memory corruption */
+#define KAL_ADM_GUARDIAN_FLAG 0x4
+/* has an extensible header immediate before each user buffer */
+#define KAL_ADM_EXTHEADER_FLAG 0x8
+/* on kal_adm_delete(), if any user buffer is not free yet, system enter fatal error handling */
+#define KAL_ADM_CLEANDELETE_FLAG 0x10
+/* if kal_adm_realloc() failed, system enter fatal error handling */
+#define KAL_ADM_REALLOCFAIL_FATAL_FLAG 0x20
+/* if kal_adm_realloc() failed, free old user buffer before return NULL */
+#define KAL_ADM_REALLOCFAIL_FREE_FLAG 0x40
+#define KAL_ADM_LIGHTCHECK_FREEPATTERN_FLAG 0x80
+#define KAL_ADM_FREEPATTERN_FLAG 0x100
+#define KAL_ADM_PROFILE_USER 0x200
+#define KAL_ADM_CONCURRENT_FLAG 0x400
+/* DOM-NOT_FOR_SDK-BEGIN */
+/* OR of all KAL_ADM_*_FLAG, should not used by users */
+#define KAL_ADM_VALID_FLAG 0x7ff
+/* DOM-NOT_FOR_SDK-END */
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+/* ADM allocation options */
+#define ADM_OPT_ALIGN_ALLOC (0x01 << 16)
+#define ADM_CACHE_1_CHANNEL_COVER (0x02 << 16)
+#define ADM_CACHE_ALL_CHANNEL_COVER (0x04 << 16)
+#define ADM_OPT_TOPMOST_ALLOC (0x08 << 16)
+/* allocate from the bottom(lower address)*/
+#define ADM_OPT_BOTTOMMOST_ALLOC (0x10 << 16)
+/* the highest bit is reserved to avoid signed overflow warning */
+#define ADM_OPT_MASK (0x7fff << 16)
+/* DOM-NOT_FOR_SDK-END */
+/* Calculate how many words needed for an extheader (argument of extheader_size_in_word in kal_adm_create2) */
+#define KAL_ADM_EXTHEADER_WORDS(x) \
+    (((x) + 3) / sizeof(kal_uint32) * sizeof(kal_uint32))
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+/* ADM POOL SIZE CALCULATE MACROS BEGIN */
+/* NOTE:															*/
+/* following sizes are hard size for ADM structure, user must not 	*/
+/* use it directly. and it must be sync with kal_adm.h when ADM 	*/
+/* structure has been changed.										*/
+/* macros internal begin */
+#define ADM_CB_SIZE 20
+#define ADM_BL_SIZE 16
+#define ADM_MB_MINI_HEAD_SIZE 8
+#define ADM_MB_HEAD_SIZE 16
+#define ADM_MB_HEADGUARD_SIZE 4
+#define ADM_MB_FOOTGUARD_SIZE 4
+#define ADM_MB_OLDLOGGING_EXTHEADER_SIZE 8
+/* macros internal end */
+
+/* macros external begin */
+#define ADM_DEFAULT_BL_NUM 7
+#define ADM_MB_OVERHEAD(flags, extheader_size_in_word)       \
+    (ADM_MB_MINI_HEAD_SIZE +                                 \
+     ((flags)&KAL_ADM_OLD_ISLOGGING_FLAG                     \
+          ? (ADM_MB_HEADGUARD_SIZE + ADM_MB_FOOTGUARD_SIZE + \
+             ADM_MB_OLDLOGGING_EXTHEADER_SIZE)               \
+          : 0) +                                             \
+     ((flags)&KAL_ADM_GUARDIAN_FLAG                          \
+          ? (ADM_MB_HEADGUARD_SIZE + ADM_MB_FOOTGUARD_SIZE)  \
+          : 0) +                                             \
+     ((flags)&KAL_ADM_EXTHEADER_FLAG ? (extheader_size_in_word)*4 : 0))
+
+#define ADM_POOLSIZE_CALC(bl_num, user_pool_size)                            \
+    (ADM_CB_SIZE + ADM_BL_SIZE * (bl_num) + ADM_MB_MINI_HEAD_SIZE +          \
+     ADM_MB_HEADGUARD_SIZE + ADM_MB_FOOTGUARD_SIZE + ADM_MB_MINI_HEAD_SIZE + \
+     ADM_MB_HEADGUARD_SIZE + ADM_MB_FOOTGUARD_SIZE + (user_pool_size))
+/* macros external end */
+/* ADM POOL SIZE CALCULATE MACROS END */
+/* DOM-NOT_FOR_SDK-END */
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+/* AFM allocation options */
+#define AFM_OPT_NONE 0x0000
+/* user buffers in this AFM is aligned to CPU cache line (32 bytes) */
+#define AFM_OPT_ALIGN_ALLOC 0x0001
+#define AFM_OPT_DBG 0x0002
+#define AFM_OPT_CUSLOG 0x0004
+/* when search avaiable user buffer, don't try to search subpools bigger than fittest subpool */
+#define AFM_OPT_NOFALLBACK_ALLOC 0x0008
+#define AFM_OPT_DBG_FREEPATTERN 0x0010
+#define AFM_OPT_CONCURRENT 0x0020
+#define AFM_OPT_PROFILE_USER 0x0040
+#define AFM_OPT_VALID 0x7F /* OR of all AFM_OPT_*, should not used by users */
+
+#define AFM_LOG_PAUSE 0x01
+#define AFM_LOG_CLEAR 0x02
+#define AFM_LOG_CLR AFM_LOG_CLEAR /* for compatible only */
+#define AFM_LOG_START 0x04
+#define AFM_LOG_STR AFM_LOG_START /* for compatible only */
+/* DOM-NOT_FOR_SDK-END */
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+/* AFM POOL SIZE CALCULATE MACROS BEGIN*/
+/* NOTE:															*/
+/* following sizes are hard size for AFM structure, user MUST NOT 	*/
+/* use it directly. and it must be sync with kal_afm.h when AFM 	*/
+/* structure has been changed.										*/
+/* macros internal begin*/
+#define AFM_CB_T_SIZE 20
+#define AFM_POOL_CB_T_SIZE 20
+#define AFM_POOL_CUSLOG_T_SIZE 4
+#define AFM_MB_HEAD_T_SIZE 8
+#define AFM_MB_HEADGUD_T_SIZE 16
+#define AFM_MB_FOOTGUD_T_SIZE 4
+#define ALIGNTO4(sz) (((sz) + 3) & ~3)
+#define ALIGNTOCACHELINE(sz) \
+    (((sz) + CPU_CACHE_LINE_SIZE - 1) & ~(CPU_CACHE_LINE_SIZE - 1))
+/* macros internal end*/
+
+/* macros external begin*/
+#define AFM_MB_OVERHEAD(option) \
+    (AFM_MB_HEAD_T_SIZE +       \
+     (option & AFM_OPT_DBG ? AFM_MB_HEADGUD_T_SIZE + AFM_MB_FOOTGUD_T_SIZE : 0))
+#if defined(__MTK_TARGET__) && \
+    (defined(__ARM9_MMU__) || defined(__DYNAMIC_SWITCH_CACHEABILITY__))
+#define AFM_POOL_OVERHEAD(option, subpool_count)                                  \
+    (AFM_CB_T_SIZE + AFM_POOL_CB_T_SIZE * subpool_count +                         \
+     (((option)&AFM_OPT_CUSLOG) ? AFM_POOL_CUSLOG_T_SIZE * (subpool_count) : 0) + \
+     4 + (((option)&AFM_OPT_ALIGN_ALLOC) ? CPU_CACHE_LINE_SIZE : 0))
+#define AFM_SUBPOOL_OVERHEAD(option, sz, nr)                                      \
+    (option & AFM_OPT_ALIGN_ALLOC                                                 \
+         ? (nr) *                                                                 \
+               (ALIGNTOCACHELINE(sz) + ALIGNTOCACHELINE(AFM_MB_OVERHEAD(option))) \
+         : (nr) * (ALIGNTO4(sz) + AFM_MB_OVERHEAD(option)))
+#else
+#define AFM_POOL_OVERHEAD(option, subpool_count)                                   \
+    AFM_CB_T_SIZE + AFM_POOL_CB_T_SIZE *(subpool_count) +                          \
+        ((option & AFM_OPT_CUSLOG) ? AFM_POOL_CUSLOG_T_SIZE * subpool_count : 0) + \
+        4
+#define AFM_SUBPOOL_OVERHEAD(option, sz, nr) \
+    (nr) * (ALIGNTO4(sz) + AFM_MB_OVERHEAD(option))
+#endif
+/* macros external end*/
+/* AFM POOL SIZE CALCULATE MACROS END*/
+#define AFM_SUBPOOL_END_PATTERN 0xFFFFFFFF
+/* DOM-NOT_FOR_SDK-END */
+
+#if defined(__MTK_TARGET__) && defined(__KAL_STACK_ISOLATION__)
+
+#define KAL_VM_PAGESIZE (4096) /* KAL VM page size */
+
+#ifdef __ARM9_MMU__
+#define KAL_VM_STACK_PAGESIZE 1024
+#else //!__ARM9_MMU__
+#define KAL_VM_STACK_PAGESIZE 4096
+#endif //__ARM9_MMU__
+#define KAL_VM_STACK_UPALIGN(x)                                  \
+    (((x) + KAL_VM_STACK_PAGESIZE - 1) / KAL_VM_STACK_PAGESIZE * \
+     KAL_VM_STACK_PAGESIZE)
+#define KAL_VM_STACK_ALIGNED(x) ((x) & ~(KAL_VM_STACK_PAGESIZE - 1) == 0)
+#define kal_vm_stack_begin() (custom_get_FLMM_STACKSPACE_Base())
+#define kal_vm_stack_end() (custom_get_FLMM_STACKSPACE_End())
+
+/* is KAL VM page size aligned */
+#define KAL_VM_PAGE_ALIGNED(x) (!(((kal_uint32)(x)) & (KAL_VM_PAGESIZE - 1)))
+/* align to next KAL VM page size */
+#define KAL_VM_PAGE_UPALIGN(x) \
+    ((((kal_uint32)(x)) + KAL_VM_PAGESIZE - 1) & ~(KAL_VM_PAGESIZE - 1))
+/* align to KAL VM page size */
+#define KAL_VM_PAGE_DOWNALIGN(x) (((kal_uint32)(x)) & ~(KAL_VM_PAGESIZE - 1))
+/* how many bytes needed to align to next KAL VM page size */
+#define KAL_VM_PAGE_MARGIN(x) (KAL_VM_PAGE_UPALIGN(x) - (x))
+
+#endif /* #if defined(__MTK_TARGET__) && defined(__KAL_STACK_ISOLATION__) */
+
+/* define maximum memory region number can be dump via catcher on EXT_ASSERT_DUMP */
+#define ASSERT_DUMP_PARAM_MAX 10
+
+/* memory regions dump via catcher */
+typedef struct ASSERT_DUMP_PARAM {
+    kal_uint32 addr[ASSERT_DUMP_PARAM_MAX]; /* start address of this memory region */
+    kal_uint32 len[ASSERT_DUMP_PARAM_MAX];  /* length of this memory region */
+} ASSERT_DUMP_PARAM_T;
+
+#if defined(__nanomips__)
+/* Cited from MIPS's ticket 106287
+Below are the reserved code and usages from our experts' information. 
+There are 2 codes for TRAP, 0 for BREAK and optional 1 for SYSCALL in baremetal environment.
+As it stands we have two trap codes with bare metal programs which are 0x7 for divide by zero 
+and also 0x0 which signals some unspecified form of error. 
+Because we guarantee to have TRAP instructions in nanoMIPS there are no reserved BREAK codes in bare metal environments, 
+the OS would be responsible for allocating those.
+We do have one reserved SYSCAL which is operation '1' and this is for our semi-hosting implementation for interacting with an RTOS, 
+simulators  or debuggers to produce output on a terminal or other device; it gets handled by our example exception handlers and converted to an SDBBP 1 if it is being sent to a debugger. 
+Even though we reserve this it is only reserved if opting in to the semihosting support so MTK can still reuse it as you may not need to use our form of semi-hosting support.
+
+TEQ 0x7:
+In interAptiv, mips32 use TEQ 0x7 to detect divide by zero and mips16 use BREAK 0x7.
+We saw that nanoMips also use TEQ 0x7.
+Traps for div by zero (TEQ 0x7) are disabled by default for -Os for code size reasons. 
+You can control this behavior with -m[no-]check-zero-division.
+*/
+
+/*
+BREAK[32] has 19 bits for code field
+BREAK[16] has only 3 bits 
+*/
+
+typedef enum
+{
+    BREAK_USERBP                = 0, /* can be used for sw break points */
+
+    KAL_FATAL_ERROR             = 1,
+    ASSERT_LINE                 = 2, /* Should be the ASSERT category first one for range checking */
+    ASSERT_EXT1                 = 3,
+    ASSERT_EXT2                 = 4,
+    ASSERT_EXT3                 = 5,
+    ASSERT_CUS_MODID            = 6,
+    ASSERT_CUS_ADDR             = 7,
+    /* code larger than 7 will become 32-bit length instruction.
+       should be only for low frequency usage for footprint*/
+    ASSERT_EXL                  = 8,
+    ASSERT_NATIVE               = 9,
+    ASSERT_EXT_DUMP             = 10,
+    ASSERT_CUS_MODID_EXT1       = 11,
+    ASSERT_CUS_MODID_EXT2       = 12,
+    ASSERT_CUS_MODID_EXT3       = 13,
+    ASSERT_CUS_ADDR_EXT1        = 14,
+    ASSERT_CUS_ADDR_EXT2        = 15,
+    ASSERT_CUS_ADDR_EXT3        = 16,
+    ASSERT_CUS_MOFID            = 17,
+    ASSERT_CUS_MOFID_EXT1       = 18,
+    ASSERT_CUS_MOFID_EXT2       = 19,
+    ASSERT_CUS_MOFID_EXT3       = 20,
+    ASSERT_LAST_TYPE            = ASSERT_CUS_MOFID_EXT3, /* Should be the ASSERT category last one for range checking */
+    MAX_NANOMIPS_BREAK_CODE       = 524287,
+} break_codes;
+
+/* TRAP only used in TEQ instruction,
+and TEQ[32] has 5 bits code field */
+
+typedef enum
+{
+    TRAP_IMGTEK_USED      = 0, /* Reserved for MIPS */
+    TRAP_RESERVED1        = 1,
+    TRAP_RESERVED2        = 2,
+    TRAP_RESERVED3        = 3,
+    TRAP_RESERVED4        = 4,
+    TRAP_RESERVED5        = 5,
+    TRAP_RESERVED6        = 6, 
+    TRAP_DIVIDE_BY_ZERO   = 7, /* from compiler generated checks */
+    TRAP_RESERVED8        = 8, 
+    TRAP_RESERVED9        = 9,
+    TRAP_RESERVED10       = 10,
+    TRAP_RESERVED11       = 11,
+    TRAP_RESERVED12       = 12,
+    TRAP_RESERVED13       = 13,
+    TRAP_RESERVED14       = 14,
+    TRAP_RESERVED15       = 15,
+
+    MAX_TRAP_CODE         = 31,
+} trap_codes;
+
+/*
+SYSCALL[32] has 18 bits code field,
+SYSCALL[16] has 2 bits only */
+
+typedef enum
+{
+    SYSCALL_USERBP              = 0, /* can be used for sw break points */
+    SYSCALL_IMGTEK_USED         = 1, /* Reserved for MIPS */
+    SYSCALL_RESERVED2           = 2,
+    /* if pc goes out of spram area, the fetched SPRAM cotent would be syscall 0x3.
+    information provided by CPU owner */
+    SYSCALL_EXEC_OUT_OF_SPRAM   = 3,
+
+
+    MAX_SYSCALL_CODE            = 262143,
+} syscall_codes;
+
+
+
+#else
+/* break instruction codes. The first 16 codes are reserved and those might be used
+ * by compiler, OS, or by debuggers. */
+typedef enum {
+    BREAK_USERBP         = 0, /* can be used for sw break points */
+    BREAK_RESERVED1      = 1,
+    BREAK_RESERVED2      = 2,
+    BREAK_RESERVED3      = 3,
+    BREAK_RESERVED4      = 4,
+    BREAK_SSTEPBP        = 5,
+    BREAK_OVERFLOW       = 6, /* from compiler generated checks */
+    BREAK_DIVIDE_BY_ZERO = 7, /* from compiler generated checks */
+    BREAK_RANGE          = 8, /* from compiler generated checks */
+    BREAK_RESERVED9      = 9,
+    BREAK_RESERVED10     = 10,
+    BREAK_RESERVED11     = 11,
+    BREAK_BUG            = 12,
+    BREAK_RESERVED13     = 13,
+    BREAK_RESERVED14     = 14,
+    BREAK_RESERVED15     = 15,
+
+    /* MTK allocated break codes */
+    ASSERT_LINE           = 16,
+    ASSERT_EXT1           = 17,
+    ASSERT_EXT2           = 18,
+    ASSERT_EXT3           = 19,
+    ASSERT_EXT_DUMP       = 20,
+    ASSERT_EXL            = 21,
+    ASSERT_NATIVE         = 22,
+    ASSERT_CUS_MODID      = 23,
+    ASSERT_CUS_MODID_EXT1 = 24,
+    ASSERT_CUS_MODID_EXT2 = 25,
+    ASSERT_CUS_MODID_EXT3 = 26,
+    ASSERT_CUS_ADDR       = 27,
+    ASSERT_CUS_ADDR_EXT1  = 28,
+    ASSERT_CUS_ADDR_EXT2  = 29,
+    ASSERT_CUS_ADDR_EXT3  = 30,
+    KAL_FATAL_ERROR       = 31,
+
+
+    /* These codes are used in mips16 
+       if pc goes out of spram area */
+    BREAK_EXEC_OUT_OF_SPRAM3 = 60,
+    BREAK_EXEC_OUT_OF_SPRAM2 = 61,
+    BREAK_EXEC_OUT_OF_SPRAM0 = 62,
+    BREAK_EXEC_OUT_OF_SPRAM1 = 63,
+
+    /* codes from 24 to 63 are free to use */
+
+    /* in mips16, break instruction code field is 6 bits. With mips32 break instruction, 
+     * the code field is 20 bits but to keep code compatible use only first 64 codes */
+    MAX_MIPS16_BREAK_CODE = 64,
+} break_codes;
+
+typedef enum {
+    TRAP_USERBP         = 0, /* can be used for sw break points */
+    TRAP_RESERVED1      = 1,
+    TRAP_RESERVED2      = 2,
+    TRAP_RESERVED3      = 3,
+    TRAP_RESERVED4      = 4,
+    TRAP_SSTEPBP        = 5,
+    TRAP_OVERFLOW       = 6, /* from compiler generated checks */
+    TRAP_DIVIDE_BY_ZERO = 7, /* from compiler generated checks */
+    TRAP_RANGE          = 8, /* from compiler generated checks */
+    TRAP_RESERVED9      = 9,
+    TRAP_RESERVED10     = 10,
+    TRAP_RESERVED11     = 11,
+    TRAP_BUG            = 12,
+    TRAP_RESERVED13     = 13,
+    TRAP_RESERVED14     = 14,
+    TRAP_RESERVED15     = 15,
+
+    /* codes from 23 to 63 are free to use */
+
+    MAX_TRAP_CODE = 1023,
+} trap_codes;
+#endif
+
+typedef enum {
+    THREAD_UNDERFLOW               = 0,
+    THREAD_OVERFLOW                = 1,
+    THREAD_INVALID_YIELD_QUALIFIER = 2,
+    THREAD_GATING_STORAGE          = 3,
+    THREAD_YIELD_SCHEDULER         = 4,
+    THREAD_GS_SCHEDULER            = 5,
+    THREAD_RESERVED6               = 6,
+    THREAD_RESERVED7               = 7,
+} thread_exception_codes;
+
+/* callback function of ASSERT_SPECIFIC_CALLBACK */
+typedef void (*Assert_Specific_Callback)(void *para_ptr);
+
+
+/* define wait mode */
+typedef enum {
+    /* don't wait if the condition is not satisfied and return error code */
+    KAL_NO_WAIT = 0,
+    /* wait until the condition is satisfied */
+    KAL_INFINITE_WAIT,
+} kal_wait_mode;
+
+/* define kal status */
+typedef enum {
+    KAL_SUCCESS,            /* the operation is succeeded */
+    KAL_ERROR,              /* general error */
+    KAL_Q_FULL,             /* queue is full */
+    KAL_Q_EMPTY,            /* queue is empty */
+    KAL_SEM_NOT_AVAILABLE,  /* semaphore is not available at the moment */
+    KAL_WOULD_BLOCK,        /* the operation would block but requester don't want */
+    KAL_MESSAGE_TOO_BIG,    /* message is too big */
+    KAL_INVALID_ID,         /* an invalid identity */
+    KAL_NOT_INITIALIZED,    /* the resource is not initialized */
+    KAL_INVALID_LENGHT,     /* an invalid length */
+    KAL_NULL_ADDRESS,       /* the address is NULL */
+    KAL_NOT_RECEIVE,        /* no receiver want this message */
+    KAL_NOT_SEND,           /* can't send this message out */
+    KAL_MEMORY_NOT_VALID,   /* memory is corrupted */
+    KAL_NOT_PRESENT,        /* the request resource is not present */
+    KAL_MEMORY_NOT_RELEASE, /* some memory is not released */
+    KAL_TIMEOUT,            /* the opearation time out */
+    KAL_INIT_BEFORE,        /* the resource has been init before*/
+    KAL_SPINLOCK_NOT_AVAILABLE, /* spinlock is not available at the moment */
+    KAL_ITC_NOT_AVAILABLE,      /* itc cell is not available at the moment */
+    KAL_TIMER_INVALID_TIMER_ID, /* KAL timer ID is invalid */
+    KAL_TIMER_NON_TASK_CONTEXT,  /* API is invoked in NON-Task context */
+    KAL_TIMER_MAX_DELAY_OUT_OF_RANGE,  /* max delay ticks is out of range */
+    KAL_BUFF_NOT_AVAILABLE  /* buffer is not available at the moment  */
+} kal_status;
+
+/* define kal task status */
+typedef enum {
+    /*------- error cases -------*/
+    KAL_ERROR_RESERVE1,   /**/
+    KAL_ERROR_RESERVE2,   /**/
+    KAL_ERROR_RESERVE3,   /**/
+    KAL_ERROR_TCB,        /* incorrect task control block */
+                          /*------- running case -------*/
+    KAL_SCHEDULED,        /* running */
+    KAL_READY,            /* ready to execute */
+                          /*------- suspend cases -------*/
+    KAL_SLEEP_SUSPEND,    /* waiting for sleep timeout */
+    KAL_SEMA_SUSPEND,     /* waiting for semaphore */
+    KAL_ENHMUTEX_SUSPEND, /* waiting for enhanced mutex */
+    KAL_OTHER_SUSPEND,    /* waiting for other resource */
+    KAL_EVENT_SUSPEND,    /* waiting for event */
+    KAL_QUEUE_SUSPEND,    /* waiting for queue */
+    KAL_RESERVE1_SUSPEND, /*  */
+    KAL_RESERVE2_SUSPEND, /*  */
+    KAL_RESERVE3_SUSPEND, /*  */
+                          /*------- end case -------*/
+    KAL_TERMINATED,       /* task is terminated */
+} kal_task_status;
+
+typedef enum {
+    MODULE_OUT_OF_RANGE,
+    MD1_MODULE,
+    MD2_MODULE,
+    MD3_MODULE,
+    PCORE_MODULE,
+} kal_module_core;
+
+#ifdef __STACK_ALIGN_MPU__
+#define KAL_TASK_STACK_ALIGN (__STACK_ALIGN_MPU__)
+#else
+#define KAL_TASK_STACK_ALIGN (8U)
+#endif
+#define KAL_TASK_STACK_ALIGNMASK (KAL_TASK_STACK_ALIGN - 1)
+#define KAL_STACK_ALIGN(SIZE)                                     \
+    (((SIZE + KAL_TASK_STACK_ALIGNMASK) / KAL_TASK_STACK_ALIGN) * \
+     KAL_TASK_STACK_ALIGN)
+
+#if defined(__MTK_TARGET__)
+/* define how many miliseconds per system tick represent */
+#ifdef OS_TICK_PERIOD_US
+/* the type of max delay is kal_uint16, thus max 65535*/
+#define MAX_DELAY_UNLIMITED 65535
+
+/* For FPGA, clock rate will be 26MHz (us counter used),
+   but L1 subframe tick is slowed down XXX times comparing to ASIC for Digital-I/Q test purpose */
+#if defined(__HAPS_FPGA_CLK_ADJUST__) && defined(__EVENT_BASED_TIMER__)
+#define KAL_CLOCK_RATIO_REAL 160 /* slowed down XXX times */
+#else
+#define KAL_CLOCK_RATIO_REAL 1
+#endif
+
+#ifdef __HAPS_FPGA_CLK_ADJUST__
+#define OST_TICK_UNIT OS_TICK_PERIOD_US
+#define KAL_MICROSECS_PER_TICK ((float)OST_TICK_UNIT / KAL_CLOCK_RATIO_REAL)
+#define KAL_MILLISECS_PER_TICK ((float)KAL_MICROSECS_PER_TICK / 1000)
+
+/* +(KAL_MICROSECS_PER_TICK/2)/KAL_MICROSECS_PER_TICK:
+ *    round the number to the nearest whole number
+ */
+/* 10 msec */
+#define KAL_TICKS_10_MSEC \
+    (((10000 + (OS_TICK_PERIOD_US / 2)) / OS_TICK_PERIOD_US) * KAL_CLOCK_RATIO_REAL)
+/* 50 msec */
+#define KAL_TICKS_50_MSEC \
+    (((50000 + (OS_TICK_PERIOD_US / 2)) / OS_TICK_PERIOD_US) * KAL_CLOCK_RATIO_REAL)
+/* 100 msec */
+#define KAL_TICKS_100_MSEC \
+    (((100000 + (OS_TICK_PERIOD_US / 2)) / OS_TICK_PERIOD_US) * KAL_CLOCK_RATIO_REAL)
+/* 500 msec */
+#define KAL_TICKS_500_MSEC \
+    (((500000 + (OS_TICK_PERIOD_US / 2)) / OS_TICK_PERIOD_US) * KAL_CLOCK_RATIO_REAL)
+/* 1024 msec */
+#define KAL_TICKS_1024_MSEC                                      \
+    (((1024000 + (OS_TICK_PERIOD_US / 2)) / OS_TICK_PERIOD_US) * \
+     KAL_CLOCK_RATIO_REAL)
+/* 1 sec */
+#define KAL_TICKS_1_SEC                                          \
+    (((1000000 + (OS_TICK_PERIOD_US / 2)) / OS_TICK_PERIOD_US) * \
+     KAL_CLOCK_RATIO_REAL)
+/* 2 sec */
+#define KAL_TICKS_2_SEC                                          \
+    (((2000000 + (OS_TICK_PERIOD_US / 2)) / OS_TICK_PERIOD_US) * \
+     KAL_CLOCK_RATIO_REAL)
+/* 3 sec */
+#define KAL_TICKS_3_SEC                                          \
+    (((3000000 + (OS_TICK_PERIOD_US / 2)) / OS_TICK_PERIOD_US) * \
+     KAL_CLOCK_RATIO_REAL)
+/* 5 sec */
+#define KAL_TICKS_5_SEC                                          \
+    (((5000000 + (OS_TICK_PERIOD_US / 2)) / OS_TICK_PERIOD_US) * \
+     KAL_CLOCK_RATIO_REAL)
+/* 30 sec */
+#define KAL_TICKS_30_SEC                                          \
+    (((30000000 + (OS_TICK_PERIOD_US / 2)) / OS_TICK_PERIOD_US) * \
+     KAL_CLOCK_RATIO_REAL)
+/* 1 min */
+#define KAL_TICKS_1_MIN                                           \
+    (((60000000 + (OS_TICK_PERIOD_US / 2)) / OS_TICK_PERIOD_US) * \
+     KAL_CLOCK_RATIO_REAL)
+/* 64 ticks */
+#define KAL_MSEC_64_TICKS \
+    (((float)OS_TICK_PERIOD_US * 64 + (1000 / 2)) / 1000) / KAL_CLOCK_RATIO_REAL
+/* 256 ticks */
+#define KAL_MSEC_256_TICKS \
+    (((float)OS_TICK_PERIOD_US * 256 + (1000 / 2)) / 1000) / KAL_CLOCK_RATIO_REAL
+#else /* __HAPS_FPGA_CLK_ADJUST__ */
+#define KAL_MICROSECS_PER_TICK OS_TICK_PERIOD_US
+#define KAL_MILLISECS_PER_TICK ((float)KAL_MICROSECS_PER_TICK / 1000)
+
+#define KAL_TICKS_10_MSEC \
+    ((10000 + (KAL_MICROSECS_PER_TICK / 2)) / KAL_MICROSECS_PER_TICK) /* 10 msec */
+#define KAL_TICKS_50_MSEC \
+    ((50000 + (KAL_MICROSECS_PER_TICK / 2)) / KAL_MICROSECS_PER_TICK) /* 50 msec */
+#define KAL_TICKS_100_MSEC \
+    ((100000 + (KAL_MICROSECS_PER_TICK / 2)) / KAL_MICROSECS_PER_TICK) /* 100 msec */
+#define KAL_TICKS_500_MSEC \
+    ((500000 + (KAL_MICROSECS_PER_TICK / 2)) / KAL_MICROSECS_PER_TICK) /* 500 msec */
+#define KAL_TICKS_1024_MSEC                     \
+    ((1024000 + (KAL_MICROSECS_PER_TICK / 2)) / \
+     KAL_MICROSECS_PER_TICK) /* 1024 msec */
+#define KAL_TICKS_1_SEC \
+    ((1000000 + (KAL_MICROSECS_PER_TICK / 2)) / KAL_MICROSECS_PER_TICK) /* 1 sec */
+#define KAL_TICKS_2_SEC \
+    ((2000000 + (KAL_MICROSECS_PER_TICK / 2)) / KAL_MICROSECS_PER_TICK) /* 2 sec */
+#define KAL_TICKS_3_SEC \
+    ((3000000 + (KAL_MICROSECS_PER_TICK / 2)) / KAL_MICROSECS_PER_TICK) /* 3 sec */
+#define KAL_TICKS_5_SEC \
+    ((5000000 + (KAL_MICROSECS_PER_TICK / 2)) / KAL_MICROSECS_PER_TICK) /* 5 sec */
+#define KAL_TICKS_30_SEC \
+    ((30000000 + (KAL_MICROSECS_PER_TICK / 2)) / KAL_MICROSECS_PER_TICK) /* 30 sec */
+#define KAL_TICKS_1_MIN \
+    ((60000000 + (KAL_MICROSECS_PER_TICK / 2)) / KAL_MICROSECS_PER_TICK) /* 1 min */
+#define KAL_MSEC_64_TICKS \
+    ((KAL_MICROSECS_PER_TICK * 64 + (1000 / 2)) / 1000) /* 64 ticks */
+#define KAL_MSEC_256_TICKS \
+    ((KAL_MICROSECS_PER_TICK * 256 + (1000 / 2)) / 1000) /* 256 ticks */
+#endif /* __HAPS_FPGA_CLK_ADJUST__ */
+
+
+#define KAL_MICROSECS_PER_TICK_REAL OS_TICK_PERIOD_US
+#define KAL_MILLISECS_PER_TICK_REAL ((float)KAL_MICROSECS_PER_TICK_REAL / 1000)
+
+/* 10 msec */
+#define KAL_TICKS_10_MSEC_REAL \
+    ((10000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 50 msec */
+#define KAL_TICKS_50_MSEC_REAL \
+    ((50000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 100 msec */
+#define KAL_TICKS_100_MSEC_REAL \
+    ((100000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 500 msec */
+#define KAL_TICKS_500_MSEC_REAL \
+    ((500000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 1024 msec */
+#define KAL_TICKS_1024_MSEC_REAL \
+    ((1024000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 1 sec */
+#define KAL_TICKS_1_SEC_REAL \
+    ((1000000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 2 sec */
+#define KAL_TICKS_2_SEC_REAL \
+    ((2000000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 3 sec */
+#define KAL_TICKS_3_SEC_REAL \
+    ((3000000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 5 sec */
+#define KAL_TICKS_5_SEC_REAL \
+    ((5000000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 30 sec */
+#define KAL_TICKS_30_SEC_REAL \
+    ((30000000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 1 min */
+#define KAL_TICKS_1_MIN_REAL \
+    ((60000000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 64 ticks */
+#define KAL_MSEC_64_TICKS_REAL \
+    ((KAL_MICROSECS_PER_TICK_REAL * 64 + (1000 / 2)) / 1000)
+/* 256 ticks */
+#define KAL_MSEC_256_TICKS_REAL \
+    ((KAL_MICROSECS_PER_TICK_REAL * 256 + (1000 / 2)) / 1000)
+
+
+#else /* else of OS_TICK_PERIOD_US */
+#define KAL_MICROSECS_PER_TICK 4615
+#define KAL_MILLISECS_PER_TICK 4.615
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+/* Following defines are internal to the KAL */
+#define KAL_TICKS_10_MSEC (2)     /* 10 msec */
+#define KAL_TICKS_50_MSEC (10)    /* 50 msec */
+#define KAL_TICKS_100_MSEC (21)   /* 100 msec */
+#define KAL_TICKS_500_MSEC (108)  /* 500 msec */
+#define KAL_TICKS_1024_MSEC (221) /* 1024 msec */
+#define KAL_TICKS_1_SEC (216)     /* 1 sec */
+#define KAL_TICKS_2_SEC (433)     /* 2 sec */
+#define KAL_TICKS_3_SEC (650)     /* 3 sec */
+#define KAL_TICKS_5_SEC (1083)    /* 5 sec */
+#define KAL_TICKS_30_SEC (6500)   /* 30 sec */
+#define KAL_TICKS_1_MIN (13000)   /* 1 min */
+#define KAL_MSEC_64_TICKS (295)   /* 64 ticks */
+#define KAL_MSEC_256_TICKS (1181) /* 256 ticks */
+/* DOM-NOT_FOR_SDK-END */
+
+
+#endif /* end of "else of OS_TICK_PERIOD_US" */
+#endif 
+
+
+#ifdef KAL_ON_OSCAR
+/* define how many miliseconds per system tick represent */
+#define KAL_MILLISECS_PER_TICK 1
+#define KAL_MICROSECS_PER_TICK 1000
+#define MAX_DELAY_UNLIMITED 65535
+
+/* DOM-NOT_FOR_SDK-BEGIN */
+/* Following defines are internal to the KAL */
+#define KAL_SIM_MSECS_PER_TICK KAL_MILLISECS_PER_TICK
+#define KAL_TICKS_10_MSEC (10 / KAL_SIM_MSECS_PER_TICK)     /* 10 msec */
+#define KAL_TICKS_50_MSEC (50 / KAL_SIM_MSECS_PER_TICK)     /* 50 msec */
+#define KAL_TICKS_100_MSEC (100 / KAL_SIM_MSECS_PER_TICK)   /* 100 msec */
+#define KAL_TICKS_500_MSEC (500 / KAL_SIM_MSECS_PER_TICK)   /* 500 msec */
+#define KAL_TICKS_1024_MSEC (1024 / KAL_SIM_MSECS_PER_TICK) /* 1024 msec */
+#define KAL_TICKS_1_SEC (1000 / KAL_SIM_MSECS_PER_TICK)     /* 1 sec */
+#define KAL_TICKS_2_SEC (2000 / KAL_SIM_MSECS_PER_TICK)     /* 2 sec */
+#define KAL_TICKS_3_SEC (3000 / KAL_SIM_MSECS_PER_TICK)     /* 3 sec */
+#define KAL_TICKS_5_SEC (5000 / KAL_SIM_MSECS_PER_TICK)     /* 5 sec */
+#define KAL_TICKS_30_SEC (30000 / KAL_SIM_MSECS_PER_TICK)   /* 30 sec */
+#define KAL_TICKS_1_MIN (60000 / KAL_SIM_MSECS_PER_TICK)    /* 1 min */
+#define KAL_MSEC_64_TICKS (64 * KAL_SIM_MSECS_PER_TICK)     /* 64 ticks */
+#define KAL_MSEC_256_TICKS (256 * KAL_SIM_MSECS_PER_TICK)   /* 256 ticks */
+/* DOM-NOT_FOR_SDK-END */
+
+#define KAL_CLOCK_RATIO_REAL 1
+#define KAL_MICROSECS_PER_TICK_REAL OS_TICK_PERIOD_US
+#define KAL_MILLISECS_PER_TICK_REAL ((float)KAL_MICROSECS_PER_TICK_REAL / 1000)
+
+/* 10 msec */
+#define KAL_TICKS_10_MSEC_REAL \
+    ((10000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 50 msec */
+#define KAL_TICKS_50_MSEC_REAL \
+    ((50000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 100 msec */
+#define KAL_TICKS_100_MSEC_REAL \
+    ((100000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 500 msec */
+#define KAL_TICKS_500_MSEC_REAL \
+    ((500000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 1024 msec */
+#define KAL_TICKS_1024_MSEC_REAL \
+    ((1024000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 1 sec */
+#define KAL_TICKS_1_SEC_REAL \
+    ((1000000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 2 sec */
+#define KAL_TICKS_2_SEC_REAL \
+    ((2000000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 3 sec */
+#define KAL_TICKS_3_SEC_REAL \
+    ((3000000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 5 sec */
+#define KAL_TICKS_5_SEC_REAL \
+    ((5000000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 30 sec */
+#define KAL_TICKS_30_SEC_REAL \
+    ((30000000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 1 min */
+#define KAL_TICKS_1_MIN_REAL \
+    ((60000000 + (KAL_MICROSECS_PER_TICK_REAL / 2)) / KAL_MICROSECS_PER_TICK_REAL)
+/* 64 ticks */
+#define KAL_MSEC_64_TICKS_REAL \
+    ((KAL_MICROSECS_PER_TICK_REAL * 64 + (1000 / 2)) / 1000)
+/* 256 ticks */
+#define KAL_MSEC_256_TICKS_REAL \
+    ((KAL_MICROSECS_PER_TICK_REAL * 256 + (1000 / 2)) / 1000)
+#endif /* KAL_ON_OSCAR */
+
+#if defined(KAL_ON_OSABS)
+#define KAL_TICKS_10_MSEC (2)     /* 10 msec */
+#define KAL_TICKS_50_MSEC (10)    /* 50 msec */
+#define KAL_TICKS_100_MSEC (21)   /* 100 msec */
+#define KAL_TICKS_500_MSEC (108)  /* 500 msec */
+#define KAL_TICKS_1024_MSEC (221) /* 1024 msec */
+#define KAL_TICKS_1_SEC (216)     /* 1 sec */
+#define KAL_TICKS_5_SEC (1083)    /* 5 sec */
+#define KAL_TICKS_30_SEC (6500)   /* 30 sec */
+#define KAL_TICKS_1_MIN (13001)   /* 1 min */
+#define KAL_MSEC_64_TICKS (295)   /* 64 ticks */
+#define KAL_MSEC_256_TICKS (1181) /* 256 ticks */
+#endif
+
+#if defined(__ARMCC_VERSION)
+#define INLINE __inline
+#define INLINE_MODIFIER extern
+#define INLINE_ALWAYS
+#elif defined(__GNUC__) && !defined(__MINGW32__)
+#define INLINE inline
+#define INLINE_MODIFIER
+#define INLINE_ALWAYS __attribute__((always_inline))
+#elif defined(_MSC_VER) || defined(__MINGW32__)
+#define INLINE __inline
+#define INLINE_MODIFIER static
+#define INLINE_ALWAYS
+#endif /* Cross RVCT/GCC/VC9 Compiler marco definition */
+
+
+#if defined(__ARMCC_VERSION)
+#define GET_RETURN_ADDRESS(a) a = __return_address()
+#elif defined(__GNUC__)
+#define GET_RETURN_ADDRESS(a) a = (kal_uint32)__builtin_return_address(0)
+#elif defined(_MSC_VER)
+#define GET_RETURN_ADDRESS(a) a = (kal_uint32)_ReturnAddress()
+#endif /* Cross RVCT/GCC/VC9 Compiler marco definition */
+#if defined(__ARMCC_VERSION)
+#define GET_STACK_POINTER(a) a = __current_sp()
+#elif defined(__GNUC__)
+#define GET_STACK_POINTER(a) a = (kal_uint32)__builtin_frame_address(0)
+#elif defined(_MSC_VER)
+#define GET_STACK_POINTER(a) __asm mov a, ESP
+#endif /* Cross RVCT/GCC/VC9 Compiler marco definition */
+
+#if defined(__ARMCC_VERSION) && defined(__MTK_TARGET__)
+#define PRAGMA_BEGIN_COMPILER_OPTIMIZE_DISABLE _Pragma("push") _Pragma("O0")
+#define PRAGMA_END_COMPILER_OPTIMIZE_DISABLE _Pragma("pop")
+#define PRAGMA_BEGIN_COMPILER_OPTIMIZE_TIME _Pragma("push") _Pragma("Otime")
+#define PRAGMA_END_COMPILER_OPTIMIZE_TIME _Pragma("pop")
+#elif defined(__GNUC__) && defined(__MTK_TARGET__)
+#define PRAGMA_BEGIN_COMPILER_OPTIMIZE_DISABLE \
+    _Pragma("GCC push_options") _Pragma("GCC optimize(\"-O0\")")
+#define PRAGMA_END_COMPILER_OPTIMIZE_DISABLE _Pragma("GCC pop_options")
+#define PRAGMA_BEGIN_COMPILER_OPTIMIZE_TIME \
+    _Pragma("GCC push_options") _Pragma("GCC optimize(\"-O3\")")
+#define PRAGMA_END_COMPILER_OPTIMIZE_TIME _Pragma("GCC pop_options")
+#else
+#define PRAGMA_BEGIN_COMPILER_OPTIMIZE_DISABLE
+#define PRAGMA_END_COMPILER_OPTIMIZE_DISABLE
+#define PRAGMA_BEGIN_COMPILER_OPTIMIZE_TIME
+#define PRAGMA_END_COMPILER_OPTIMIZE_TIME
+#endif /* Cross RVCT/GCC/VC9 Compiler marco definition */
+
+#define CBS_SCAN_EVENT_INDEX (1)
+
+#if defined(__EVENT_CNT_PROFILING__)
+#define EVENT_CNT_SCAN_EVENT_INDEX (2)
+
+#define EVENT_CNT_SCAN_TIME KAL_TICKS_30_SEC
+#endif /*__EVENT_CNT_PROFILING__*/
+
+/** Define the macro which tells compiler to reload all the variables from
+    memory after this. It can ensure all variables are reloaded after entering
+    a critical section. Otherwise compiler may optimize the code and result in
+    a race condition which can't be observed in source code level */
+#if defined(__ARMCC_VERSION)
+#define STRONG_ORDER_MEMORY_LOAD()
+#elif defined(__GNUC__)
+#define STRONG_ORDER_MEMORY_LOAD() asm volatile("" : : : "memory")
+#elif defined(_MSC_VER)
+#define STRONG_ORDER_MEMORY_LOAD()
+#endif /* Cross RVCT/GCC/VC9 Compiler marco definition */
+
+
+/* opaque type for event group identity */
+typedef struct {
+#if defined(KAL_ON_MERTOS)
+    kal_uint8 unused[96]; /* align to cache line size */
+#elif defined(KAL_ON_OSCAR)
+    kal_uint8 unused[76]; /* as sizeof(event group) in oscar */
+#endif
+} cc_eventgrpid;
+
+
+/*******************************************************************************
+ * Defines for ADT
+ *******************************************************************************/
+/* ADT */
+struct adt_node;
+
+/* ilm free callback function prototype */
+typedef void (*ilm_free_callback_t)(ilm_struct *ilm_ptr);
+/* ilm ADT translator callback function prototype */
+typedef void (*translator_adt_enc_callback_t)(const ilm_struct *ilm_ptr,
+                                              struct adt_node **adt);
+
+
+/* opaque type for RCU */
+typedef struct {
+    kal_uint8 unused;
+} * kalcc_rcuid;
+
+
+#define RCU_BUFF_HEADER kal_uint8 rcu_buff_header[32];
+#define RCU_HEADER kal_uint8      rcu_header[32];
+
+#define RCU_MEMORY_SIZE(sz, nr) \
+    (CPU_CACHE_LINE_SIZE + nr * (CPU_CACHE_LINE_SIZE + ALIGNTOCACHELINE(sz)))
+
+#define HRT_RCU_MEMORY_SIZE(sz, nr) \
+    (CPU_CACHE_LINE_SIZE + nr * (CPU_CACHE_LINE_SIZE + ALIGNTOCACHELINE(sz)))
+
+
+/*******************************************************************************
+ * Defines for ITC
+ *******************************************************************************/
+typedef enum{
+	
+    KAL_ITC_TAG_START = 0,
+
+    KAL_ITC_CORE01_RF = KAL_ITC_TAG_START,          /* 00: EL1D RF Ctrl Sequence (use FIFO) */
+    KAL_ITC_CORE01_SF,          /* 01: EL1D SF Tick Handshake for Multi-Threading (use FIFO) */
+    KAL_ITC_CORE0_CT,           /* 02: Core0 Child Thread Wait */
+    KAL_ITC_CORE1_CT,           /* 03: Core1 Child Thread Wait */
+    KAL_ITC_MT_CORE0_TC_STATUS, /* 04: CORE0 MT TC STATUS*/
+    KAL_ITC_MT_CORE1_TC_STATUS, /* 05: CORE0 MT TC STATUS*/
+    KAL_ITC_CORE012_HRT,        /* 06: HRT API (RCU) Usage */
+    KAL_ITC_OS_L_1,             /* 07: OS Schedule Lock #1 */
+    KAL_ITC_DHL_MDM,            /* 08: DHL Modem Monitor Lock */
+    KAL_ITC_DHL_ISR,            /* 09: DHL ISR Logging Lock */
+    KAL_ITC_PS_TL,              /* 10: PS Trace Lock */
+    KAL_ITC_L1_RF_REQ, /* 11: All RF requests from L1 modules running on Core 0/1 VPE 1 */
+    KAL_ITC_L2_PS_LOCK,      /* 12: 2/3G L2 PS lock (URLC/UMAC, RLC/MAC) */
+    KAL_ITC_ERRC_LOCK,       /* 13: ERRC Lock */
+    KAL_ITC_C2K_SLEEP_L,     /* 14: C2K Modem Timer ON/OFF */
+    KAL_ITC_C2K_RCP_TX_L,    /* 15: C2K L2/RCP TX Lock */
+    KAL_ITC_C2K_SYS_PROTECT, /* 16: C2K common system API protection */
+    KAL_ITC_DSP_SLEEP_L,     /* 17: DSP sleep flow control */
+    KAL_ITC_DSP_DOWNLOAD,    /* 18: DSP dynamic download */
+    KAL_ITC_GPT_DRIVER,      /* 19: GPT driver */
+    KAL_ITC_OS_L_2,             /*  20: All Cores SST EMM */
+    KAL_ITC_4GPS,               /* 21: EL2 Task/LISR C.S. */
+    KAL_ITC_EL1D_ALL,           /* 22: EL1D Common Data Between Core0,1 HISR/Task and LISR */
+    KAL_ITC_CORE012_GDMA,       /* 23: All Cores HRT API Handle: GDMA */
+    KAL_ITC_CORE012_INT,        /* 24: All Cores HRT API Handle: Interrupt */
+    KAL_ITC_DVFS,               /* 25: DVFS request table and DVFS/PLL HW control */
+    KAL_ITC_LOW_POWER,          /* 26: Core0/1: L1 low power, sleep flow, 32k less, HW resource control */
+    KAL_ITC_SLEEP_L,            /* 27: MIPS core sleep flow */
+    KAL_ITC_EL1D_LISR,          /* 28: EL1D Common Data Between Core0,1 LISR */
+    KAL_ITC_EL1D_GDMA_LIST,     /* 29: EL1D GDMA Link List Handling in Core 0/1 VPE 0/1 */
+    KAL_ITC_EL1CRX,             /* 30: EL1 RX Common Data */
+    KAL_ITC_EL1C_IDC,           /* 31: EL1C IDC Common Data Between Core 0/1 VPE 0/1 */
+    KAL_ITC_RTB_LOCK,           /* 32: L1 RTB Critical Section */
+    KAL_ITC_23G_L1_HRT_LOCK,    /* 33: 2/3G L1 lock in Core 0/1 VPE 1 */
+    KAL_ITC_23G_L1_LOCK,        /* 34: 2/3G L1 lock in Core 0/1 VPE 0/1 */
+    KAL_ITC_AMIF_LOCK,          /* 35: AP Modem Interface */
+    KAL_ITC_MEM_SLOW_DOWN,      /* 36: Memset Slow Down */
+    KAL_ITC_DCM,                /* 37: DCM handler */
+    KAL_ITC_ADT,                /* 38: ADT */
+    KAL_ITC_DSM,                /* 39: DSM */
+    KAL_ITC_ELM_LOCK,           /* 40: ELM */
+    KAL_ITC_EVRCP_RCP_RI,       /* 41: lock between ECRCP and RCP_RI */
+    KAL_ITC_CHLP_RCP_RI,        /* 42: lock between CHIP and RCP_RI */
+    KAL_ITC_PSTRACE_LOCK,       /* 43: dhl PSTRACE*/
+    KAL_ITC_EVSHED_EVNO_LOCK,   /* 44: Event Scheduler number lock*/
+    KAL_ITC_META_SYSTRACE_LOCK, /* 45: META_SYSTRACE lock*/
+    KAL_ITC_ERRC_AFM_LOCK,      /* 46: ERRC*/
+    KAL_ITC_ERRC_C2K_AMIF_LOCK, /* 47: AMIF modeule lock between ERRC and C2K LISR(IRQ137)*/
+    KAL_ITC_VPE0_DL,            /* 48: Core0 VPE0 Dummy LISR*/
+    KAL_ITC_VPE1_DL,            /* 49: Core0 VPE1 Dummy LISR*/
+    KAL_ITC_VPE2_DL,            /* 50: Core1 VPE0 Dummy LISR*/
+    KAL_ITC_VPE3_DL,            /* 51: Core1 VPE1 Dummy LISR*/
+    KAL_ITC_DL_PROTECT,         /* 52: Lock for Dummy LISR data*/
+    KAL_ITC_MMRFD_SCH_MIPI_LOCK, /* 53: Lock for MMRFD to protect API operation*/
+    KAL_ITC_MMRFD_SCH_BPI_LOCK,  /* 54: Lock for MMRFD to protect API operation*/
+    KAL_ITC_MMRFD_SCH_RFIC_LOCK, /* 55: Lock for MMRFD to protect API operation*/
+    KAL_ITC_IDC,                 /* 56: Lock for IDC driver */
+    KAL_ITC_AFM,                 /* 57: Lock for AFM */
+    KAL_ITC_NL1C_IDC,            /* 58: NL1C IDC Commond Data */
+    KAL_ITC_TTY,                 /* 59: Lock for TTY */
+    KAL_ITC_CCCITTY,            /* 60: Lock for CCCI TTY */
+    KAL_ITC_CCCI,               /* 61: Lock for CCCI */
+    KAL_ITC_CCISM,              /* 62: Lock for CCISM */
+    KAL_ITC_NL1_RFD_CMN,        /* 63: Lock for NL1 RFD Common */
+    KAL_ITC_GPT_DSCC1,          /* 64: Lock for GPT driver DSCC */
+    KAL_ITC_GPT_DSCC2,          /* 65: Lock for GPT driver DSCC */
+    KAL_ITC_NL1_CTRL,           /* 66: Lock for NL1 CTRL */
+    KAL_ITC_COMMON_L1C_IDC,     /* 67: Lock for NL1C & EL1C common IDC */
+    KAL_ITC_GPT_DPCOPRO,        /* 68: Lock for GPT driver, DPCOPRO */
+    KAL_ITC_ISR_Q,              /* 69: Lock for ISR Queue (!TARGET) */
+    KAL_ITC_DIGRF_MIPI_LOCK,    /* 70: Lock for MIPI driver */
+    KAL_ITC_CSIF_LOCK,          /* 71: Lock for CSIF driver */
+    KAL_ITC_DIGRF_DSB_LOCK,     /* 72: Lock for DSB driver */
+    KAL_ITC_DIGRF_DSB_READ_REG32_LOCK,    /* 73: Lock for DSB driver */
+    KAL_ITC_NRRC_SRB_UL_LOCK,   /* 74: Lock for NRRC AFM protection */
+    KAL_ITC_TXDFE_D_NRT,        /* 75: Lock for TXDFE-D NRT part */
+    KAL_ITC_TXDFE_A_NRT,        /* 76: Lock for TXDFE-A NRT part */
+#if defined(__KTEST__)	
+    KAL_ITC_PROF,               /* 77: Lock for KAL/OS profiling */
+#endif
+    KAL_ITC_EL1C_SLEEP_L,       /* 78: Lock phs sleep bmp*/
+    KAL_ITC_DIGRF_COM_DVFS_LOCK, /* 79: Lock for A-Die DVFS and MIPI control*/
+    KAL_ITC_SERDES_BW_CAL,      /* 80: Lock for serdes */
+#if defined(__ESL_MASE__)
+    KAL_ITC_ESL,
+#endif
+#if defined(KTEST_UART_TRACES)
+    // ITC locks for UART driver in KTEST. KTEST needs to use UART from HRT VPE.
+    KAL_ITC_DBG,
+    KAL_ITC_PRINT,
+#endif
+#if defined(__DYNAMIC_POWER_DOWN_L2CACHE_WAY_SUPPORT__)
+    KAL_ITC_DPDL2,
+#endif
+    KAL_ITC_SPMI_LOCK,          /* X: Lock for SPMI driver */
+
+    KAL_ITC_TAG_END,
+
+    KAL_ITC_CORE0_DL,    /* X: Core0 VPE0 Dummy LISR */
+    KAL_ITC_CORE1_DL,    /* X: Core1 VPE0 Dummy LISR */
+    KAL_ITC_CORE2_DL,    /* X: Core2 VPE0 Dummy LISR */
+    KAL_ITC_CORE0_23G,   /* X: Core0 23G Giant Lock */
+    KAL_ITC_CORE2_23G,   /* X: Core2 23G Giant Lock */
+    KAL_ITC_CORE012_SYNC /* X: All Cores HRT API Handle: Sync */
+} kal_itc_lock_id;
+
+#define KAL_ITC_NUM (KAL_ITC_TAG_END - KAL_ITC_TAG_START)
+
+/*******************************************************************************
+ * Defines for HRT Multi-threading
+ *******************************************************************************/
+typedef kal_uint32 kal_workqueue_mask;
+#if defined(__MD97__) || defined(__MD97P__)
+typedef enum {
+    KAL_Q1,
+    KAL_Q_MAX,
+} kal_workqueueid;
+
+#define KAL_Q1_MASK (1)
+#define KAL_ALL_Q_MASK (1)
+
+#define KAL_ALL_Q_FINISH (0)
+#define KAL_Q1_EXECUTE (1)
+
+typedef struct mt_func_para_struct {
+    kal_uint16 func_index;
+    //kal_uint8  reserved0;
+    //kal_uint8  reserved1;
+    void *func_param;
+} mt_func_para_struct;
+#else
+#error No MT config yet
+#endif
+
+/*******************************************************************************
+ * Defines for VPE ID
+ *******************************************************************************/
+typedef enum {
+    CORE0_VPE0 = 0,
+    CORE0_VPE1,
+#if SYS_MCU_NUM_CORE == 2
+    CORE1_VPE0,
+    CORE1_VPE1,
+#elif SYS_MCU_NUM_CORE == 3
+    CORE1_VPE0,
+    CORE1_VPE1,
+    CORE2_VPE0,
+    CORE2_VPE1,
+#elif SYS_MCU_NUM_CORE == 4
+#if defined(MT6297_IA)
+    CORE1_VPE0,
+    CORE1_VPE1,
+    CORE2_VPE0,
+    CORE2_VPE1,
+    CORE3_VPE0,
+    CORE3_VPE1,
+#else
+    CORE0_VPE2,
+    CORE1_VPE0,
+    CORE1_VPE1,
+    CORE1_VPE2,
+    CORE2_VPE0,
+    CORE2_VPE1,
+    CORE2_VPE2,
+    CORE3_VPE0,
+    CORE3_VPE1,
+    CORE3_VPE2,
+#endif
+#endif
+    TOTAL_VPE_NUM
+} kal_vpe_id;
+
+/*******************************************************************************
+ * Defines for TC ID per core
+ *******************************************************************************/
+typedef enum {
+    VPE0_MAIN_TC = 0,
+#if defined(__MD93__) || defined(__MD95__)
+    VPE1_MAIN_TC,
+    VPE1_CHILD_TC1,
+    VPE1_CHILD_TC2,
+#elif defined(__MD97__)
+#if defined(MT6297_IA)
+    VPE0_CHILD_TC1,
+    VPE0_CHILD_TC2,
+    VPE1_MAIN_TC,
+    VPE1_CHILD_TC1,
+    VPE1_CHILD_TC2,
+#else
+    VPE0_CHILD_TC1,
+    VPE1_MAIN_TC,
+    VPE1_CHILD_TC1,
+    VPE2_MAIN_TC,
+    VPE2_CHILD_TC1,
+#endif
+#endif
+    TOTAL_TC_NUM_PER_CORE
+} kal_tc_id;
+
+/*******************************************************************************
+ * Defines for Task/HISR affinity config
+ *******************************************************************************/
+#define AFFINITY_NIL 0x0
+#define AFFINITY_VPE0 0x1
+#define AFFINITY_VPE1 0x2
+#define AFFINITY_VPE2 0x4
+#define AFFINITY_VPE3 0x8
+#define AFFINITY_VPE4 0x10
+#define AFFINITY_VPE5 0x20
+#define AFFINITY_VPE6 0x40
+#define AFFINITY_VPE7 0x80
+#define AFFINITY_VPE8 0x100
+#define AFFINITY_VPE9 0x200
+#define AFFINITY_VPE10 0x400
+#define AFFINITY_VPE11 0x800
+#define AFFINITY_DYNAMIC 0x8000
+typedef enum {
+    None_Group = AFFINITY_NIL,
+
+#if (defined(__MD93__) || defined(__MD95__)) && SYS_MCU_NUM_CORE == 2
+    /* For Gen93/Gen95 2 Cores Configuration */
+    C0V0_Group = AFFINITY_VPE0,
+    C1V0_Group = AFFINITY_VPE2,
+
+    VPE0_Group       = C0V0_Group,
+    VPE2_Group       = C1V0_Group,
+    VPE0_RESERVED    = AFFINITY_VPE0, // this is only for vpe0 idle task
+    VPE1_RESERVED    = AFFINITY_VPE1, // this is only for vpe1 idle task
+    VPE2_RESERVED    = AFFINITY_VPE2, // this is only for vpe2 idle task
+    VPE3_RESERVED    = AFFINITY_VPE3, // this is only for vpe3 idle task
+    SMP_NORMAL_Group = C0V0_Group | C1V0_Group,
+    SMP_NORMAL_AND_HRT_Group =
+        AFFINITY_VPE0 | AFFINITY_VPE1 | AFFINITY_VPE2 | AFFINITY_VPE3
+#elif defined(__MD95__) && SYS_MCU_NUM_CORE == 3
+    /* For Gen95, if it supports 3 cores, the 3rd Core's 2 VPEs would be both Normal Domain */
+    C0V0_Group = AFFINITY_VPE0,
+    C1V0_Group = AFFINITY_VPE2,
+    C2V0_Group = AFFINITY_VPE4,
+
+    VPE0_Group               = C0V0_Group,
+    VPE2_Group               = C1V0_Group,
+    VPE4_Group               = C2V0_Group,
+    VPE0_RESERVED            = AFFINITY_VPE0, // this is only for vpe0 idle task
+    VPE1_RESERVED            = AFFINITY_VPE1, // this is only for vpe1 idle task
+    VPE2_RESERVED            = AFFINITY_VPE2, // this is only for vpe2 idle task
+    VPE3_RESERVED            = AFFINITY_VPE3, // this is only for vpe3 idle task
+    VPE4_RESERVED            = AFFINITY_VPE4, // this is only for vpe4 idle task
+    VPE5_RESERVED            = AFFINITY_VPE5, // this is only for vpe5 idle task
+    SMP_NORMAL_Group         = C0V0_Group | C1V0_Group | C2V0_Group | AFFINITY_VPE5,
+    SMP_NORMAL_AND_HRT_Group = AFFINITY_VPE0 | AFFINITY_VPE1 | AFFINITY_VPE2 |
+                               AFFINITY_VPE3 | AFFINITY_VPE4 | AFFINITY_VPE5
+#else /* SYS_MCU_NUM_CORE == 4 */
+/* Gen97 Core VPE configuration */
+#if defined(MT6297_IA)
+    /* For Gen97 iA, it supports 4 cores, 2 VPEs per core */
+    /* Per Core: VPE0 is normal domain, VPE1 are HRT domain */
+    C0V0_Group = AFFINITY_VPE0,
+    C1V0_Group = AFFINITY_VPE2,
+    C2V0_Group = AFFINITY_VPE4,
+    C3V0_Group = AFFINITY_VPE6,
+
+    VPE0_Group               = C0V0_Group,
+    VPE2_Group               = C1V0_Group,
+    VPE4_Group               = C2V0_Group,
+    VPE6_Group               = C3V0_Group,
+    VPE0_RESERVED            = AFFINITY_VPE0, // this is only for vpe0 idle task
+    VPE1_RESERVED            = AFFINITY_VPE1, // this is only for vpe1 idle task
+    VPE2_RESERVED            = AFFINITY_VPE2, // this is only for vpe2 idle task
+    VPE3_RESERVED            = AFFINITY_VPE3, // this is only for vpe3 idle task
+    VPE4_RESERVED            = AFFINITY_VPE4, // this is only for vpe4 idle task
+    VPE5_RESERVED            = AFFINITY_VPE5, // this is only for vpe5 idle task
+    VPE6_RESERVED            = AFFINITY_VPE6, // this is only for vpe6 idle task
+    VPE7_RESERVED            = AFFINITY_VPE7, // this is only for vpe7 idle task
+    SMP_NORMAL_Group         = C0V0_Group | C1V0_Group | C2V0_Group | C3V0_Group,
+    SMP_NORMAL_AND_HRT_Group = AFFINITY_VPE0 | AFFINITY_VPE1 | AFFINITY_VPE2 |
+                               AFFINITY_VPE3 | AFFINITY_VPE4 | AFFINITY_VPE5 |
+                               AFFINITY_VPE6 | AFFINITY_VPE7
+#else
+
+#if defined(__MD97_IS_2CORES__)
+    /* For Gen97 Shaolin FPGA H3, it supports 4 cores, 3 VPEs per core */
+    /* Per Core: VPE0 is normal domain, VPE1/2 are HRT domain */
+    C0V0_Group = AFFINITY_VPE0,
+    C1V0_Group = AFFINITY_VPE3,
+
+    VPE0_Group               = C0V0_Group,
+    VPE2_Group               = C1V0_Group, // this is temp version for building pass
+    VPE0_RESERVED            = AFFINITY_VPE0,  // this is only for vpe0 idle task
+    VPE1_RESERVED            = AFFINITY_VPE1,  // this is only for vpe1 idle task
+    VPE2_RESERVED            = AFFINITY_VPE2,  // this is only for vpe2 idle task
+    VPE3_RESERVED            = AFFINITY_VPE3,  // this is only for vpe3 idle task
+    VPE4_RESERVED            = AFFINITY_VPE4,  // this is only for vpe4 idle task
+    VPE5_RESERVED            = AFFINITY_VPE5,  // this is only for vpe5 idle task
+    SMP_NORMAL_Group         = C0V0_Group | C1V0_Group,
+    SMP_NORMAL_AND_HRT_Group = AFFINITY_VPE0 | AFFINITY_VPE1 | AFFINITY_VPE2 |
+                               AFFINITY_VPE3 | AFFINITY_VPE4 | AFFINITY_VPE5
+#else
+    /* For Gen97 Shaolin, it supports 4 cores, 3 VPEs per core */
+    /* Per Core: VPE0 is normal domain, VPE1/2 are HRT domain */
+    C0V0_Group = AFFINITY_VPE0,
+    C1V0_Group = AFFINITY_VPE3,
+    C2V0_Group = AFFINITY_VPE6,
+    C3V0_Group = AFFINITY_VPE9,
+
+    VPE0_Group               = C0V0_Group,
+    VPE2_Group               = C1V0_Group, // this is temp version for building pass
+    VPE0_RESERVED            = AFFINITY_VPE0,  // this is only for vpe0 idle task
+    VPE1_RESERVED            = AFFINITY_VPE1,  // this is only for vpe1 idle task
+    VPE2_RESERVED            = AFFINITY_VPE2,  // this is only for vpe2 idle task
+    VPE3_RESERVED            = AFFINITY_VPE3,  // this is only for vpe3 idle task
+    VPE4_RESERVED            = AFFINITY_VPE4,  // this is only for vpe4 idle task
+    VPE5_RESERVED            = AFFINITY_VPE5,  // this is only for vpe5 idle task
+    VPE6_RESERVED            = AFFINITY_VPE6,  // this is only for vpe6 idle task
+    VPE7_RESERVED            = AFFINITY_VPE7,  // this is only for vpe7 idle task
+    VPE8_RESERVED            = AFFINITY_VPE8,  // this is only for vpe8 idle task
+    VPE9_RESERVED            = AFFINITY_VPE9,  // this is only for vpe9 idle task
+    VPE10_RESERVED           = AFFINITY_VPE10, // this is only for vpe10 idle task
+    VPE11_RESERVED           = AFFINITY_VPE11, // this is only for vpe11 idle task
+    SMP_NORMAL_Group         = C0V0_Group | C1V0_Group | C2V0_Group | C3V0_Group,
+    SMP_NORMAL_AND_HRT_Group = AFFINITY_VPE0 | AFFINITY_VPE1 |
+                               AFFINITY_VPE3 | AFFINITY_VPE4 |
+                               AFFINITY_VPE6 | AFFINITY_VPE7 |
+                               AFFINITY_VPE9 | AFFINITY_VPE10 
+#endif /* defined(__MD97_IS_2CORES__) */
+#endif /* defined(MT6297_IA) */
+
+#endif
+} kal_affinity_group;
+
+/* Affinity group IDs for group affinity */
+
+typedef kal_uint32 kal_task_group_id;
+
+#define AFFI_GROUP_ID_0 0
+#define AFFI_GROUP_ID_1 1
+#define AFFI_GROUP_ID_2 2
+#define AFFI_GROUP_ID_3 3
+#define AFFI_GROUP_ID_4 4
+#define AFFI_GROUP_ID_5 5
+#define AFFI_GROUP_ID_6 6
+#define AFFI_GROUP_ID_7 7
+#define AFFI_GROUP_ID_8 8
+#define AFFI_GROUP_ID_9 9
+#define AFFI_GROUP_ID_NONE 0xFFFFFFFF
+
+
+typedef enum {
+    RESETM_SUCCESS = 0,
+    RESETM_SUCCESS_TASK_NOT_SUSPEND,
+    RESETM_FAIL,
+    RESETM_FAIL_TASK_NOT_SUSPEND,
+    RESETM_NOT_EXIST, // Module not found by module id
+    RESETM_NOT_TASK   // This module is not real task (maybe DUMMY or LISR/HISR)
+} E_RESETM_ERROR_CODE;
+
+/*******************************************************************************
+ * Defines for Task/HISR affinity config
+ *******************************************************************************/
+
+/*******************************************************************************
+ * Defines for UTC counte
+ *******************************************************************************/
+typedef struct wall_clock_t {
+    kal_uint32 ms_msb_utc_counter;
+    kal_uint32 ms_lsb_utc_counter;
+    kal_uint32 us_msb_utc_counter;
+    kal_uint32 us_lsb_utc_counter;
+} wall_clock;
+
+/* kal domain enumeration */
+typedef enum {
+    KAL_DOMAIN_NORMAL = 0,
+    KAL_DOMAIN_HRT,
+    KAL_DOMAIN_CHRT,
+} kal_domain;
+
+#endif /* _KAL_PUBLIC_DEFS_H */
diff --git a/mcu/interface/service/kal/kal_wp_hook.h b/mcu/interface/service/kal/kal_wp_hook.h
new file mode 100644
index 0000000..edf3bd3
--- /dev/null
+++ b/mcu/interface/service/kal/kal_wp_hook.h
@@ -0,0 +1,88 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2005
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Filename:
+ * ---------
+ *   kal_wp_hook.h
+ *
+ * Project:
+ * --------
+ *   Maui_Software
+ *
+ * Description:
+ * ------------
+ *   Modem watchpoint configuring related implementation
+ *
+ * Author:
+ * -------
+ * -------
+ *
+ *============================================================================
+ *             HISTORY
+ * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *------------------------------------------------------------------------------
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ * removed!
+ *
+ * removed!
+ * removed!
+ * removed!
+ *
+ *------------------------------------------------------------------------------
+ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
+ *============================================================================
+ ****************************************************************************/
+#ifndef __KAL_WP_HOOK__
+#define __KAL_WP_HOOK__
+
+void wp_hook_incInit(kal_uint32 cpu_id);
+void wp_hook_schedule(kal_uint32 cpu_id, kal_char * exe_unit_name);
+void wp_hook_dispatchLISR_start(kal_uint32 cpu_id,kal_uint32 irq_id);
+#if defined (__MIPS_I7200__)
+void wp_hook_dispatchLISR_end(kal_uint32 cpu_id,kal_uint32 irq_id);
+#else
+void wp_hook_dispatchLISR_end(kal_uint32 cpu_id, kal_char * exe_unit_name);
+#endif
+
+#endif // __KAL_WP_HOOK__
+
diff --git a/mcu/interface/service/kal/llist.h b/mcu/interface/service/kal/llist.h
new file mode 100644
index 0000000..379f2f5
--- /dev/null
+++ b/mcu/interface/service/kal/llist.h
@@ -0,0 +1,187 @@
+/*****************************************************************************
+*  Copyright Statement:
+*  --------------------
+*  This software is protected by Copyright and the information contained
+*  herein is confidential. The software may not be copied and the information
+*  contained herein may not be used or disclosed except with the written
+*  permission of MediaTek Inc. (C) 2012
+*
+*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
+*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
+*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
+*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
+*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
+*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
+*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
+*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
+*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
+*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
+*
+*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
+*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
+*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
+*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
+*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
+*
+*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
+*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
+*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
+*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
+*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
+*
+*****************************************************************************/
+
+/*******************************************************************************
+ * Filename:
+ * ---------
+ *   llist.h
+ *
+ * Project:
+ * --------
+ *   MOLY
+ *
+ * Description:
+ * ------------
+ *
+ *
+ * Author:
+ * -------
+ * -------
+ *   
+ *
+ * ==========================================================================
+ * $Log$
+ *
+ * 07 26 2018 hubert.wang
+ * [MOLY00342443] [KAL] Coding convention
+ * 	
+ * 	[KAL] Coding Convention
+ *
+ * 05 02 2018 hubert.wang
+ * [MOLY00323821] [UMOLYE][LLIST] Add a new macro List_ForEachPrevSafe() for llist
+ * 	
+ * 	[UMOLYE][LLIST] Request by Aric Chiu
+ *
+ * 09 29 2017 tee-yuen.chun
+ * [MOLY00281026] [Gen93][Mlib_dll] Remove llist.c and use Mlib_dll to implement llist
+ * . Remove list.c and replace it with Mlib_dll
+ ****************************************************************************/
+/**
+ *	@file  llist.h
+ *	@brief high efficient doubly "embedded" linked-list implementation
+ *
+ *	@author Howard Chen, Moja Hsu ,HR Hsu
+ *
+ *	@date   2006 , 7
+ *
+ **/
+#ifndef LLIST0630
+#define LLIST0630
+
+#include "mlib_dll.h"
+
+/**
+ *	@brief the embedded linked list
+ */
+typedef list_node llist_t;
+
+#define LIST_Empty(ptr) ((ptr)->next == (ptr))
+
+/**
+ * @brief the llist_t initializator
+ */
+#define LIST_VALUE(name) \
+    {                    \
+        &(name), &(name) \
+    }
+
+/**
+ * @brief the llist_t constructor
+ */
+#define LIST_Init(ptr) mlib_dll_insert_at_end(NULL, ptr)
+
+/**
+ * @brief Insert a _new entry after the specified head.
+ * @param _new  _new entry to be added
+ * @param head list head to add it after
+ *
+ */
+#define LIST_Add(new_ptr, head_ptr) mlib_dll_insert_at_start(head_ptr, new_ptr)
+
+/**
+ * @brief Insert a _new entry before the specified head.
+ * @param _new: _new entry to be added
+ * @param head: list head to add it before
+ *
+ */
+#define LIST_AddTail(new_ptr, head_ptr) mlib_dll_insert_at_end(head_ptr, new_ptr)
+
+/**
+* @brief deletes entry from list.
+* @param entry: the element to delete from the list.
+* @note: list_empty on entry does not return true after this, the entry is in an undefined state.
+*/
+#define LIST_Del(entry) mlib_dll_delete(NULL, entry)
+
+/**
+* @brief deletes entry from list and reinitialize it.
+* @param entry: the element to delete from the list.
+*/
+#define LIST_DelInit(entry) \
+    do {                    \
+        LIST_Del(entry);    \
+        LIST_Init(entry);   \
+    } while (0)
+
+/**
+ * @brief get the struct for this entry
+ * @param ptr		the &struct list_head pointer.
+ * @param type 		the type of the struct this is embedded in.
+ * @param member	the name of the list_struct within the struct.
+ */
+#define LIST_Entry(ptr, type, member) List2Container(ptr, type, member)
+
+/**
+ * @brief iterate over a list
+ * @param pos	the &struct list_head to use as a loop counter.
+ * @param head  the head for your list.
+ */
+#define LIST_ForEach(pos, head) \
+    for (pos = (head)->next; pos != (head); pos = pos->next)
+
+/**
+ * @brief iterate over a list safe against removal of list entry
+ * @param pos    	the &struct list_head to use as a loop counter.
+ * @param n         another &struct list_head to use as temporary storage
+ * @param head      the head for your list.
+ */
+#define LIST_ForEachSafe(pos, n, head) \
+    for (pos = (head)->next, n = pos->next; pos != (head); pos = n, n = pos->next)
+
+/**
+ * @brief LIST_for_each_prev   -       iterate over a list in reverse order
+ * @param pos	the &struct list_head to use as a loop counter.
+ * @param head	the head for your list.
+ */
+#define LIST_ForEachPrev(pos, head) \
+    for (pos = (head)->prev; pos != (head); pos = pos->prev)
+
+/**
+* @brief iterate over a list safe against removal of list entry
+* @param pos     the &struct list_head to use as a loop counter.
+* @param n         another &struct list_head to use as temporary storage
+* @param head      the head for your list.
+*/
+#define LIST_ForEachPrevSafe(pos, n, head) \
+    for (pos = (head)->prev, n = pos->prev; pos != (head); pos = n, n = pos->prev)
+
+/**
+ *  @brief Get the first of the linked list
+ */
+#define LIST_GetFirst(head, type, member) \
+    (((head)->next != (head)) ? (LIST_Entry((head)->next, type, member)) : (NULL))
+
+
+#endif