mysterywolf před 5 roky
revize
7daf174045
15 změnil soubory, kde provedl 11413 přidání a 0 odebrání
  1. 742 0
      Auth/auth.c
  2. 175 0
      Auth/auth.h
  3. 266 0
      Collections/slist.c
  4. 117 0
      Collections/slist.h
  5. 1549 0
      KAL/None/kal.c
  6. 1175 0
      KAL/POSIX/kal.c
  7. 1001 0
      KAL/Template/kal.c
  8. 559 0
      KAL/kal.h
  9. 2743 0
      KAL/uCOS-II/kal.c
  10. 2663 0
      KAL/uCOS-III/kal.c
  11. 202 0
      LICENSE
  12. 28 0
      NOTICE
  13. 81 0
      common.h
  14. 105 0
      common_err.h
  15. 7 0
      readme.md

+ 742 - 0
Auth/auth.c

@@ -0,0 +1,742 @@
+/*
+*********************************************************************************************************
+*                                              uC/Common
+*                                 Common Features for Micrium Stacks
+*
+*                    Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
+*
+*                                 SPDX-License-Identifier: APACHE-2.0
+*
+*               This software is subject to an open source license and is distributed by
+*                Silicon Laboratories Inc. pursuant to the terms of the Apache License,
+*                    Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
+*
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*
+*                              uC/Common - Authentication Module (Auth)
+*
+* Filename : auth.c
+* Version  : V1.02.00
+*********************************************************************************************************
+* Note(s)  : (1) 'goto' statements were used in this software module. Their usage
+*                is restricted to cleanup purposes in exceptional program flow (e.g.
+*                error handling), in compliance with CERT MEM12-C and MISRA C:2012
+*                rules 15.2, 15.3 and 15.4.
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            INCLUDE FILES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#include  <lib_str.h>
+#include  <KAL/kal.h>
+#include  "auth.h"
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                           LOCAL DATA TYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+typedef  struct  auth_user_credentials {                        /* --------------- AUTH USER CREDENTIALS -------------- */
+    AUTH_USER  User;                                            /* User structure.                                      */
+    CPU_CHAR   Pwd[AUTH_PWD_MAX_LENGTH];                        /* Password for this user.                              */
+} AUTH_USER_CREDENTIALS;
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                           GLOBAL VARIABLES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+AUTH_USER  Auth_RootUser = {
+        { 'r', 'o', 'o', 't', '\0' },
+        AUTH_RIGHT_ROOT
+};
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                        LOCAL GLOBAL VARIABLES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+static  KAL_LOCK_HANDLE        Auth_LockHandle;
+
+static  CPU_SIZE_T             Auth_UserNbr = 1;
+
+static  AUTH_USER_CREDENTIALS  Auth_UsersCredentials[AUTH_NB_USERS_MAX] = {
+        {
+            {
+                    { 'r', 'o', 'o', 't', '\0' },
+                    AUTH_RIGHT_ROOT
+            },
+            { 'a', 'd', 'm', 'i', 'n', '\0' }
+        }
+};
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                       LOCAL FUNCTION PROTOTYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+static  CPU_BOOLEAN  Auth_GetUserHandler (const  CPU_CHAR   *p_name,
+                                                 AUTH_USER  *p_user,
+                                                 RTOS_ERR   *p_err);
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            GLOBAL FUNCTIONS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                              Auth_Init()
+*
+* Description : (1) Initialize Authentication module:
+*
+*                   (a) Create Lock.
+*
+* Argument(s) : p_err       Pointer to variable that will receive the return error code from this function :
+*
+*                               --------------- RETURNED BY KAL_LockCreate() --------------
+*                               See KAL_LockCreate() for additional return error codes.
+*
+* Return(s)   : DEF_OK,   if initialization was successful.
+*               DEF_FAIL, otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+CPU_BOOLEAN  Auth_Init (RTOS_ERR  *p_err)
+{
+    CPU_BOOLEAN  res = DEF_OK;
+
+
+    Auth_LockHandle = KAL_LockCreate("Auth Lock",
+                                      KAL_OPT_CREATE_NONE,
+                                      p_err);
+    if (*p_err != RTOS_ERR_NONE) {
+        res = DEF_FAIL;
+    }
+
+    return (res);
+}
+
+
+/*
+*********************************************************************************************************
+*                                         Auth_CreateUser()
+*
+* Description : Create a user and fill the user structure provided.
+*
+* Argument(s) : p_name  Pointer to user name string.
+*
+*               p_pwd   Pointer to password string.
+*
+*               p_user  Pointer to user object to fill.
+*
+*               p_err   Pointer to variable that will receive the return error code from this function :
+*
+*                           RTOS_ERR_NONE
+*                           RTOS_ERR_INVALID_STR_LEN
+*                           RTOS_ERR_NO_MORE_RSRC
+*                           RTOS_ERR_ALREADY_EXISTS
+*
+*                               ----------- RETURNED BY KAL_LockAcquire/Release() ---------
+*                               See KAL_LockAcquire/Release() for additional return error codes.
+*
+* Return(s)   : DEF_OK,   if user created successfully.
+*               DEF_FAIL, otherwise.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+CPU_BOOLEAN  Auth_CreateUser (const  CPU_CHAR   *p_name,
+                              const  CPU_CHAR   *p_pwd,
+                                     AUTH_USER  *p_user,
+                                     RTOS_ERR   *p_err)
+{
+    AUTH_USER_CREDENTIALS  *p_user_cred;
+    CPU_SIZE_T              name_len;
+    CPU_SIZE_T              pwd_len;
+    CPU_SIZE_T              i;
+    CPU_INT16S              cmp_result;
+    CPU_BOOLEAN             result     = DEF_FAIL;
+    RTOS_ERR                local_err;
+
+
+    KAL_LockAcquire(Auth_LockHandle, KAL_OPT_PEND_NONE, KAL_TIMEOUT_INFINITE, p_err);
+    if (*p_err != RTOS_ERR_NONE) {
+        goto exit;
+    }
+
+    name_len = Str_Len_N(p_name, AUTH_NAME_MAX_LENGTH + 1);
+    pwd_len  = Str_Len_N(p_pwd,  AUTH_PWD_MAX_LENGTH  + 1);
+
+    if (name_len > AUTH_NAME_MAX_LENGTH) {
+       *p_err = RTOS_ERR_INVALID_STR_LEN;
+        goto exit_release;
+    }
+
+    if (pwd_len > AUTH_PWD_MAX_LENGTH) {
+       *p_err = RTOS_ERR_INVALID_STR_LEN;
+        goto exit_release;
+    }
+
+
+    if (Auth_UserNbr >= AUTH_NB_USERS_MAX) {
+       *p_err = RTOS_ERR_NO_MORE_RSRC;
+        goto exit_release;
+    }
+
+    for (i = 0; i < Auth_UserNbr; ++i) {
+
+        cmp_result = Str_Cmp_N(Auth_UsersCredentials[i].User.Name, p_name, name_len);
+        if (cmp_result == 0) {
+           *p_err = RTOS_ERR_ALREADY_EXISTS;
+            goto exit_release;
+        }
+    }
+
+    p_user_cred = &Auth_UsersCredentials[Auth_UserNbr];
+    ++Auth_UserNbr;
+
+    name_len = DEF_MIN(name_len + 1, AUTH_NAME_MAX_LENGTH);
+    pwd_len  = DEF_MIN(pwd_len + 1, AUTH_PWD_MAX_LENGTH);
+
+    (void)Str_Copy_N(p_user_cred->User.Name,
+                     p_name,
+                     name_len);
+
+    (void)Str_Copy_N(p_user_cred->Pwd,
+                     p_pwd,
+                     pwd_len);
+
+    p_user_cred->User.Rights = AUTH_RIGHT_NONE;
+
+    (void)Str_Copy_N(p_user->Name,
+                     p_name,
+                     name_len);
+
+    p_user->Rights = AUTH_RIGHT_NONE;
+
+
+    result = DEF_OK;
+   *p_err  = RTOS_ERR_NONE;
+
+
+exit_release:
+    KAL_LockRelease(Auth_LockHandle, &local_err);
+    (void)local_err;
+
+exit:
+    return (result);
+}
+
+
+/*
+*********************************************************************************************************
+*                                        Auth_ChangePassword()
+*
+* Description : Change the user's password.
+*
+* Argument(s) : p_user      Pointer to user object.
+*
+*               p_pwd       Pointer to the new password.
+*
+*               p_as_user   Pointer to user that have the permission level to do the action.
+*                               Must be the same as p_user or the ROOT user.
+*
+*               p_err       Pointer to variable that will receive the return error code from this function :
+*
+*                               RTOS_ERR_NONE
+*                               RTOS_ERR_INVALID_STR_LEN
+*                               RTOS_ERR_PERMISSION
+*                               RTOS_ERR_NOT_FOUND
+*
+*                               ----------- RETURNED BY KAL_LockAcquire/Release() ---------
+*                               See KAL_LockAcquire/Release() for additional return error codes.
+*
+* Return(s)   : DEF_OK,   if password changed successfully.
+*               DEF_FAIL, otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+#if 0
+CPU_BOOLEAN  Auth_ChangePassword (       AUTH_USER  *p_user,
+                                  const  CPU_CHAR   *p_pwd,
+                                  const  AUTH_USER  *p_as_user,
+                                         RTOS_ERR   *p_err)
+{
+    CPU_SIZE_T    name_len;
+    CPU_SIZE_T    pwd_len;
+    CPU_SIZE_T    i;
+    CPU_INT16S    cmp_result;
+    CPU_BOOLEAN   result     = DEF_FAIL;
+    RTOS_ERR      local_err;
+
+
+    KAL_LockAcquire(Auth_LockHandle, KAL_OPT_PEND_NONE, KAL_TIMEOUT_INFINITE, p_err);
+    if (*p_err != RTOS_ERR_NONE) {
+        goto exit;
+    }
+
+    name_len = Str_Len_N(p_user->Name, AUTH_NAME_MAX_LENGTH + 1);
+    pwd_len  = Str_Len_N(p_pwd,  AUTH_PWD_MAX_LENGTH  + 1);
+
+    if (pwd_len > AUTH_PWD_MAX_LENGTH) {
+       *p_err = RTOS_ERR_INVALID_STR_LEN;
+        goto exit_release;
+    }
+
+    if ((Str_Cmp(p_as_user->Name, p_user->Name)             != 0)      &&
+        (DEF_BIT_IS_CLR(p_as_user->Rights, AUTH_RIGHT_ROOT) == DEF_YES)) {
+       *p_err = RTOS_ERR_PERMISSION;
+        goto exit_release;
+    }
+
+    for (i = 0; i < Auth_UserNbr; ++i) {
+
+        cmp_result = Str_Cmp_N(Auth_UsersCredentials[i].User.Name, p_user->Name, name_len);
+        if (cmp_result == 0) {
+
+            (void)Str_Copy_N(Auth_UsersCredentials[i].Pwd,
+                             p_pwd,
+                             pwd_len);
+
+            result = DEF_OK;
+           *p_err  = RTOS_ERR_NONE;
+            goto exit_release;
+        }
+    }
+
+   *p_err = RTOS_ERR_NOT_FOUND;
+
+
+exit_release:
+    KAL_LockRelease(Auth_LockHandle, &local_err);
+    (void)local_err;
+
+exit:
+    return (result);
+}
+#endif
+
+
+/*
+*********************************************************************************************************
+*                                           Auth_GetUser()
+*
+* Description : Get the user structure with the given name.
+*
+* Argument(s) : p_name      Pointer to user name string to retrieve.
+*
+*               p_user      Pointer to user object that will be filled with the data retrieved.
+*
+*               p_err       Pointer to variable that will receive the return error code from this function :
+*
+*                               RTOS_ERR_NONE
+*
+*                               ----------- RETURNED BY KAL_LockAcquire/Release() ---------
+*                               See KAL_LockAcquire/Release() for additional return error codes.
+*
+*                               ------------ RETURNED BY Auth_GetUserHandler() ------------
+*                               See Auth_GetUserHandler() for additional return error codes.
+*
+* Return(s)   : DEF_OK,   if user was successfully found.
+*               DEF_FAIL, otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+CPU_BOOLEAN  Auth_GetUser (const  CPU_CHAR   *p_name,
+                                  AUTH_USER  *p_user,
+                                  RTOS_ERR   *p_err)
+{
+    CPU_BOOLEAN  result;
+    RTOS_ERR     local_err;
+
+
+    KAL_LockAcquire(Auth_LockHandle, KAL_OPT_PEND_NONE, KAL_TIMEOUT_INFINITE, p_err);
+    if (*p_err != RTOS_ERR_NONE) {
+        result = DEF_FAIL;
+        goto exit;
+    }
+
+    result = Auth_GetUserHandler(p_name, p_user, p_err);
+
+    KAL_LockRelease(Auth_LockHandle, &local_err);
+    (void)local_err;
+
+exit:
+    return (result);
+}
+
+
+/*
+*********************************************************************************************************
+*                                     Auth_ValidateCredentials()
+*
+* Description : Validates the user and password tuple with known users.
+*
+* Argument(s) : p_name      Pointer to user name string.
+*
+*               p_pwd       Pointer to password string.
+*
+*               p_user      Pointer to user object that will be filled with the data retrieved.
+*
+*               p_err       Pointer to variable that will receive the return error code from this function :
+*
+*                               RTOS_ERR_NONE
+*                               RTOS_ERR_INVALID_STR_LEN
+*                               RTOS_ERR_INVALID_CREDENTIALS
+*
+*                               ----------- RETURNED BY KAL_LockAcquire/Release() ---------
+*                               See KAL_LockAcquire/Release() for additional return error codes.
+*
+* Return(s)   : DEF_OK,   if credentials are valid.
+*               DEF_FAIL, otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+CPU_BOOLEAN  Auth_ValidateCredentials (const  CPU_CHAR   *p_name,
+                                       const  CPU_CHAR   *p_pwd,
+                                              AUTH_USER  *p_user,
+                                              RTOS_ERR   *p_err)
+{
+    CPU_SIZE_T   name_len;
+    CPU_SIZE_T   pwd_len;
+    CPU_SIZE_T   i;
+    CPU_INT16S   cmp_result;
+    CPU_BOOLEAN  result     = DEF_FAIL;
+    RTOS_ERR     local_err;
+
+
+    KAL_LockAcquire(Auth_LockHandle, KAL_OPT_PEND_NONE, KAL_TIMEOUT_INFINITE, p_err);
+    if (*p_err != RTOS_ERR_NONE) {
+        goto exit;
+    }
+
+    name_len = Str_Len_N(p_name, AUTH_NAME_MAX_LENGTH + 1);
+    pwd_len  = Str_Len_N(p_pwd,  AUTH_PWD_MAX_LENGTH  + 1);
+
+    if (name_len > AUTH_NAME_MAX_LENGTH) {
+       *p_err = RTOS_ERR_INVALID_STR_LEN;
+        goto exit_release;
+    }
+
+    if (pwd_len > AUTH_PWD_MAX_LENGTH) {
+       *p_err = RTOS_ERR_INVALID_STR_LEN;
+        goto exit_release;
+    }
+
+    for (i = 0; i < Auth_UserNbr; ++i) {
+
+        cmp_result = Str_Cmp_N(Auth_UsersCredentials[i].User.Name, p_name, name_len);
+        if (cmp_result == 0) {
+
+            cmp_result = Str_Cmp_N(Auth_UsersCredentials[i].Pwd, p_pwd, pwd_len);
+            if (cmp_result == 0) {
+
+                (void)Str_Copy_N(p_user->Name, p_name, name_len);
+                p_user->Rights = Auth_UsersCredentials[i].User.Rights;
+
+                result = DEF_OK;
+               *p_err  = RTOS_ERR_NONE;
+                goto exit_release;
+            }
+            break;
+        }
+    }
+
+   *p_err = RTOS_ERR_INVALID_CREDENTIALS;
+
+
+exit_release:
+    KAL_LockRelease(Auth_LockHandle, &local_err);
+    (void)local_err;
+
+exit:
+    return (result);
+}
+
+
+/*
+*********************************************************************************************************
+*                                         Auth_GrantRight()
+*
+* Description : Grants a right to a user as another user (limits the rights granted).
+*
+* Argument(s) : right       New right to grant.
+*
+*               p_user      Pointer to user object that will received the new right.
+*
+*               p_as_user   Pointer to user that has the permission level to do the action.
+*
+*               p_err       Pointer to variable that will receive the return error code from this function :
+*
+*                               RTOS_ERR_NONE
+*                               RTOS_ERR_PERMISSION
+*                               RTOS_ERR_NOT_FOUND
+*
+*                               ----------- RETURNED BY KAL_LockAcquire/Release() ---------
+*                               See KAL_LockAcquire/Release() for additional return error codes.
+*
+*                               ------------ RETURNED BY Auth_GetUserHandler() ------------
+*                               See Auth_GetUserHandler() for additional return error codes.
+*
+* Return(s)   : DEF_OK,   if right was granted successfully.
+*               DEF_FAIL, otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+CPU_BOOLEAN  Auth_GrantRight (AUTH_RIGHT   right,
+                              AUTH_USER   *p_user,
+                              AUTH_USER   *p_as_user,
+                              RTOS_ERR    *p_err)
+{
+    CPU_SIZE_T   name_len;
+    CPU_SIZE_T   i;
+    CPU_INT16S   cmp_result;
+    CPU_BOOLEAN  result     = DEF_FAIL;
+    RTOS_ERR     local_err;
+
+
+    KAL_LockAcquire(Auth_LockHandle, KAL_OPT_PEND_NONE, KAL_TIMEOUT_INFINITE, p_err);
+    if (*p_err != RTOS_ERR_NONE) {
+        goto exit;
+    }
+
+    (void)Auth_GetUserHandler(p_as_user->Name, p_as_user, p_err);
+    if (*p_err != RTOS_ERR_NONE) {
+        goto exit_release;
+    }
+
+    if (((DEF_BIT_IS_SET(p_as_user->Rights, AUTH_RIGHT_MNG)  == DEF_NO)  ||
+         (DEF_BIT_IS_SET(p_as_user->Rights, right)           == DEF_NO)) &&
+        (DEF_BIT_IS_SET(p_as_user->Rights, AUTH_RIGHT_ROOT)  == DEF_NO))  {
+       *p_err = RTOS_ERR_PERMISSION;
+        goto exit_release;
+    }
+
+    name_len = Str_Len_N(p_user->Name, AUTH_NAME_MAX_LENGTH + 1);
+
+    for (i = 0; i < Auth_UserNbr; ++i) {
+
+        cmp_result = Str_Cmp_N(Auth_UsersCredentials[i].User.Name, p_user->Name, name_len);
+        if (cmp_result == 0) {
+
+            DEF_BIT_SET(Auth_UsersCredentials[i].User.Rights, right);
+
+            p_user->Rights = Auth_UsersCredentials[i].User.Rights;
+
+            result = DEF_OK;
+           *p_err  = RTOS_ERR_NONE;
+            goto exit_release;
+        }
+    }
+
+   *p_err = RTOS_ERR_NOT_FOUND;
+
+
+exit_release:
+    KAL_LockRelease(Auth_LockHandle, &local_err);
+    (void)local_err;
+
+exit:
+    return (result);
+}
+
+
+/*
+*********************************************************************************************************
+*                                          Auth_RevokeRight()
+*
+* Description : Revokes the right of a specified user.
+*
+* Argument(s) : right       Right to revoke.
+*
+*               p_user      Pointer to user object which right will be revoked.
+*
+*               p_as_user   Pointer to user that has the permission level to do the action.
+*
+*               p_err       Pointer to variable that will receive the return error code from this function :
+*
+*                               RTOS_ERR_NONE
+*                               RTOS_ERR_PERMISSION
+*                               RTOS_ERR_NOT_FOUND
+*
+*                               ----------- RETURNED BY KAL_LockAcquire/Release() ---------
+*                               See KAL_LockAcquire/Release() for additional return error codes.
+*
+*                               ------------ RETURNED BY Auth_GetUserHandler() ------------
+*                               See Auth_GetUserHandler() for additional return error codes.
+*
+* Return(s)   : DEF_OK,   if right was revoked successfully.
+*               DEF_FAIL, otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+CPU_BOOLEAN  Auth_RevokeRight (AUTH_RIGHT   right,
+                               AUTH_USER   *p_user,
+                               AUTH_USER   *p_as_user,
+                               RTOS_ERR    *p_err)
+{
+    CPU_SIZE_T   name_len;
+    CPU_SIZE_T   i;
+    CPU_INT16S   cmp_result;
+    CPU_BOOLEAN  result     = DEF_FAIL;
+    RTOS_ERR     local_err;
+
+
+    KAL_LockAcquire(Auth_LockHandle, KAL_OPT_PEND_NONE, KAL_TIMEOUT_INFINITE, p_err);
+    if (*p_err != RTOS_ERR_NONE) {
+        goto exit;
+    }
+
+    (void)Auth_GetUserHandler(p_as_user->Name, p_as_user, p_err);
+    if (*p_err != RTOS_ERR_NONE) {
+        goto exit_release;
+    }
+
+                                                                /* This implementation allows the ROOT user ...         */
+                                                                /* ... to revoke it's own ROOT right.                   */
+    if (((DEF_BIT_IS_SET(p_as_user->Rights, AUTH_RIGHT_MNG)  == DEF_NO) ||
+         (DEF_BIT_IS_SET(p_as_user->Rights, right)           == DEF_NO)   ) &&
+        (DEF_BIT_IS_SET(p_as_user->Rights, AUTH_RIGHT_ROOT)  == DEF_NO    )    ) {
+       *p_err = RTOS_ERR_PERMISSION;
+        goto exit_release;
+    }
+
+    name_len = Str_Len_N(p_user->Name, AUTH_NAME_MAX_LENGTH + 1);
+
+    for (i = 0; i < Auth_UserNbr; ++i) {
+
+        cmp_result = Str_Cmp_N(Auth_UsersCredentials[i].User.Name, p_user->Name, name_len);
+        if (cmp_result == 0) {
+
+            DEF_BIT_CLR(Auth_UsersCredentials[i].User.Rights, right);
+
+            p_user->Rights = Auth_UsersCredentials[i].User.Rights;
+
+            result = DEF_OK;
+           *p_err  = RTOS_ERR_NONE;
+            goto exit_release;
+        }
+    }
+
+   *p_err = RTOS_ERR_NOT_FOUND;
+
+
+exit_release:
+    KAL_LockRelease(Auth_LockHandle, &local_err);
+    (void)local_err;
+
+exit:
+    return (result);
+}
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                          LOCAL FUNCTIONS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                         Auth_GetUserHandler()
+*
+* Description : Get the user structure with the given name.
+*
+* Argument(s) : p_name      Pointer to user name string to retrieve.
+*
+*               p_user      Pointer to user object that will be filled with the data retrieved.
+*
+*               p_err       Pointer to variable that will receive the return error code from this function :
+*
+*                               RTOS_ERR_NONE
+*                               RTOS_ERR_NOT_FOUND
+*
+* Return(s)   : DEF_OK,   if user was successfully found.
+*               DEF_FAIL, otherwise.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+static  CPU_BOOLEAN  Auth_GetUserHandler (const  CPU_CHAR   *p_name,
+                                                 AUTH_USER  *p_user,
+                                                 RTOS_ERR   *p_err)
+{
+    CPU_SIZE_T   name_len;
+    CPU_SIZE_T   i;
+    CPU_INT16S   cmp_result;
+    CPU_BOOLEAN  result;
+
+
+    name_len = Str_Len_N(p_name, AUTH_NAME_MAX_LENGTH + 1);
+
+    for (i = 0; i < Auth_UserNbr; ++i) {
+
+        cmp_result = Str_Cmp_N(Auth_UsersCredentials[i].User.Name, p_user->Name, name_len);
+        if (cmp_result == 0) {
+
+            (void)Str_Copy_N(p_user->Name,
+                             Auth_UsersCredentials[i].User.Name,
+                             name_len);
+
+            p_user->Rights = Auth_UsersCredentials[i].User.Rights;
+
+            result = DEF_OK;
+           *p_err  = RTOS_ERR_NONE;
+            goto exit;
+        }
+    }
+
+    result = DEF_FAIL;
+   *p_err  = RTOS_ERR_NOT_FOUND;
+
+
+exit:
+   return (result);
+}

+ 175 - 0
Auth/auth.h

@@ -0,0 +1,175 @@
+/*
+*********************************************************************************************************
+*                                              uC/Common
+*                                 Common Features for Micrium Stacks
+*
+*                    Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
+*
+*                                 SPDX-License-Identifier: APACHE-2.0
+*
+*               This software is subject to an open source license and is distributed by
+*                Silicon Laboratories Inc. pursuant to the terms of the Apache License,
+*                    Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
+*
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*
+*                              uC/Common - Authentication Module (Auth)
+*
+* Filename : auth.h
+* Version  : V1.02.00
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                               MODULE
+*
+* Note(s) : (1) This library header file is protected from multiple pre-processor inclusion through
+*               use of the library module present pre-processor macro definition.
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#ifndef AUTH_MODULE_PRESENT                                     /* See Note #1.                                         */
+#define AUTH_MODULE_PRESENT
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            INCLUDE FILES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#include  <lib_mem.h>
+#include  "../common_err.h"
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                               DEFINES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#define  AUTH_PWD_MAX_LENGTH     32
+#define  AUTH_NAME_MAX_LENGTH    32
+
+#define  AUTH_NB_USERS_MAX       10
+
+
+#define  AUTH_RIGHT_NONE         DEF_BIT_NONE
+#define  AUTH_RIGHT_0            DEF_BIT_00
+#define  AUTH_RIGHT_1            DEF_BIT_01
+#define  AUTH_RIGHT_2            DEF_BIT_02
+#define  AUTH_RIGHT_3            DEF_BIT_03
+#define  AUTH_RIGHT_4            DEF_BIT_04
+#define  AUTH_RIGHT_5            DEF_BIT_05
+#define  AUTH_RIGHT_6            DEF_BIT_06
+#define  AUTH_RIGHT_7            DEF_BIT_07
+#define  AUTH_RIGHT_8            DEF_BIT_08
+#define  AUTH_RIGHT_9            DEF_BIT_09
+#define  AUTH_RIGHT_10           DEF_BIT_10
+#define  AUTH_RIGHT_11           DEF_BIT_11
+#define  AUTH_RIGHT_12           DEF_BIT_12
+#define  AUTH_RIGHT_13           DEF_BIT_13
+#define  AUTH_RIGHT_14           DEF_BIT_14
+#define  AUTH_RIGHT_15           DEF_BIT_15
+#define  AUTH_RIGHT_16           DEF_BIT_16
+#define  AUTH_RIGHT_17           DEF_BIT_17
+#define  AUTH_RIGHT_18           DEF_BIT_18
+#define  AUTH_RIGHT_19           DEF_BIT_19
+#define  AUTH_RIGHT_20           DEF_BIT_20
+#define  AUTH_RIGHT_21           DEF_BIT_21
+#define  AUTH_RIGHT_22           DEF_BIT_22
+#define  AUTH_RIGHT_23           DEF_BIT_23
+#define  AUTH_RIGHT_24           DEF_BIT_24
+#define  AUTH_RIGHT_25           DEF_BIT_25
+#define  AUTH_RIGHT_26           DEF_BIT_26
+#define  AUTH_RIGHT_27           DEF_BIT_27
+
+#define  AUTH_RIGHT_RSVD_1       DEF_BIT_28
+#define  AUTH_RIGHT_RSVD_2       DEF_BIT_29
+
+#define  AUTH_RIGHT_MNG          DEF_BIT_30
+#define  AUTH_RIGHT_ROOT         DEF_BIT_31
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                              DATA TYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+typedef  CPU_INT32U  AUTH_RIGHT;                                /* Auth right is a 32-bit bitmap.                       */
+
+typedef  struct  auth_user  {                                   /* --------------------- AUTH USER -------------------- */
+    CPU_CHAR    Name[AUTH_NAME_MAX_LENGTH];                     /* Name of the user.                                    */
+    AUTH_RIGHT  Rights;                                         /* Rights associated to this user.                      */
+} AUTH_USER;
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                           GLOBAL VARIABLES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+extern  AUTH_USER  Auth_RootUser;
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                         FUNCTION PROTOTYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+CPU_BOOLEAN  Auth_Init                (        RTOS_ERR    *p_err);
+
+CPU_BOOLEAN  Auth_CreateUser          (const   CPU_CHAR    *p_name,
+                                       const   CPU_CHAR    *p_pwd,
+                                               AUTH_USER   *p_user,
+                                               RTOS_ERR    *p_err);
+
+CPU_BOOLEAN  Auth_GetUser             (const   CPU_CHAR    *p_name,
+                                               AUTH_USER   *p_user,
+                                               RTOS_ERR    *p_err);
+
+CPU_BOOLEAN  Auth_ValidateCredentials (const   CPU_CHAR    *p_name,
+                                       const   CPU_CHAR    *p_pwd,
+                                               AUTH_USER   *p_user,
+                                               RTOS_ERR    *p_err);
+
+CPU_BOOLEAN  Auth_GrantRight          (        AUTH_RIGHT   right,
+                                               AUTH_USER   *p_user,
+                                               AUTH_USER   *p_as_user,
+                                               RTOS_ERR    *p_err);
+
+CPU_BOOLEAN  Auth_RevokeRight         (        AUTH_RIGHT   right,
+                                               AUTH_USER   *p_user,
+                                               AUTH_USER   *p_as_user,
+                                               RTOS_ERR    *p_err);
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                             MODULE END
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#endif /* AUTH_MODULE_PRESENT */

+ 266 - 0
Collections/slist.c

@@ -0,0 +1,266 @@
+/*
+*********************************************************************************************************
+*                                              uC/Common
+*                                 Common Features for Micrium Stacks
+*
+*                    Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
+*
+*                                 SPDX-License-Identifier: APACHE-2.0
+*
+*               This software is subject to an open source license and is distributed by
+*                Silicon Laboratories Inc. pursuant to the terms of the Apache License,
+*                    Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
+*
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*
+*                               uC/Common - Singly-linked Lists (SList)
+*
+* Filename : slist.c
+* Version  : V1.02.00
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            INCLUDE FILES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#define  MICRIUM_SOURCE
+#define  COLL_SLIST_MODULE
+
+#include  "slist.h"
+#include  <lib_def.h>
+#include  <cpu_core.h>
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                           GLOBAL FUNCTIONS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                             SList_Init()
+*
+* Description : Initializes a singly-linked list.
+*
+* Argument(s) : p_head_ptr      Pointer to pointer of head element of list.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  SList_Init (SLIST_MEMBER  **p_head_ptr)
+{
+   *p_head_ptr = DEF_NULL;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             SList_Push()
+*
+* Description : Add given item at beginning of list.
+*
+* Argument(s) : p_head_ptr      Pointer to pointer of head element of list.
+*
+*               p_item          Pointer to item to add.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  SList_Push (SLIST_MEMBER  **p_head_ptr,
+                  SLIST_MEMBER   *p_item)
+{
+    p_item->p_next = *p_head_ptr;
+   *p_head_ptr     =  p_item;
+}
+
+
+/*
+*********************************************************************************************************
+*                                           SList_PushBack()
+*
+* Description : Add item at end of list.
+*
+* Argument(s) : p_head_ptr      Pointer to pointer of head element of list.
+*
+*               p_item          Pointer to item to add.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  SList_PushBack (SLIST_MEMBER  **p_head_ptr,
+                      SLIST_MEMBER   *p_item)
+{
+    SLIST_MEMBER  **p_next_ptr = p_head_ptr;
+
+
+    while (*p_next_ptr != DEF_NULL) {
+        p_next_ptr = &((*p_next_ptr)->p_next);
+    }
+
+    p_item->p_next = DEF_NULL;
+   *p_next_ptr     = p_item;
+}
+
+
+/*
+*********************************************************************************************************
+*                                              SList_Pop()
+*
+* Description : Removes and returns first element of list.
+*
+* Argument(s) : p_head_ptr      Pointer to pointer of head element of list.
+*
+* Return(s)   : Pointer to item that was at top of the list.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+SLIST_MEMBER  *SList_Pop (SLIST_MEMBER  **p_head_ptr)
+{
+    SLIST_MEMBER  *p_item;
+
+    p_item = *p_head_ptr;
+    if (p_item == DEF_NULL) {
+        return (DEF_NULL);
+    }
+
+   *p_head_ptr = p_item->p_next;
+
+    p_item->p_next = DEF_NULL;
+
+    return (p_item);
+}
+
+
+/*
+*********************************************************************************************************
+*                                              SList_Add()
+*
+* Description : Add item after given item.
+*
+* Argument(s) : p_item      Pointer to item to add.
+*
+*               p_pos       Pointer to item after which the item to add will be inserted.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  SList_Add (SLIST_MEMBER  *p_item,
+                 SLIST_MEMBER  *p_pos)
+{
+    p_item->p_next = p_pos->p_next;
+    p_pos->p_next  = p_item;
+}
+
+
+/*
+*********************************************************************************************************
+*                                              SList_Rem()
+*
+* Description : Remove item from list.
+*
+* Argument(s) : p_head_ptr      Pointer to pointer of head element of list.
+*
+*               p_item          Pointer to item to remove.
+*
+* Return(s)   : none.
+*
+* Note(s)     : (1) A CPU_SW_EXCEPTION() is thrown if the item is not found within the list.
+*********************************************************************************************************
+*/
+
+void  SList_Rem (SLIST_MEMBER  **p_head_ptr,
+                 SLIST_MEMBER   *p_item)
+{
+    SLIST_MEMBER  **p_next_ptr;
+
+
+    for (p_next_ptr = p_head_ptr; *p_next_ptr != DEF_NULL; p_next_ptr = &((*p_next_ptr)->p_next)) {
+        if (*p_next_ptr == p_item) {
+           *p_next_ptr = p_item->p_next;
+            return;
+        }
+    }
+
+    CPU_SW_EXCEPTION(;);                                        /* See Note #1.                                         */
+}
+
+
+/*
+*********************************************************************************************************
+*                                             SList_Sort()
+*
+* Description : Sorts list items.
+*
+* Argument(s) : p_head_ptr      Pointer to pointer of head element of list.
+*
+*               cmp_fnct        Pointer to function to use for sorting the list.
+*                                   p_item_l    Pointer to left  item.
+*                                   p_item_r    Pointer to right item.
+*                                   Returns whether the two items are ordered (DEF_YES) or not (DEF_NO).
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  SList_Sort (SLIST_MEMBER  **p_head_ptr,
+                  CPU_BOOLEAN   (*cmp_fnct)(SLIST_MEMBER  *p_item_l,
+                                            SLIST_MEMBER  *p_item_r))
+{
+    CPU_BOOLEAN     swapped;
+    SLIST_MEMBER  **pp_item_l;
+
+
+    do {
+        swapped = DEF_NO;
+
+        pp_item_l = p_head_ptr;
+                                                                /* Loop until end of list is found.                     */
+        while ((*pp_item_l != DEF_NULL) && ((*pp_item_l)->p_next != DEF_NULL)) {
+            SLIST_MEMBER  *p_item_r = (*pp_item_l)->p_next;
+            CPU_BOOLEAN    ordered;
+
+
+            ordered = cmp_fnct(*pp_item_l, p_item_r);           /* Call provided compare fnct.                          */
+            if (ordered == DEF_NO) {                            /* If order is not correct, swap items.                 */
+                SLIST_MEMBER  *p_tmp = p_item_r->p_next;
+
+
+                p_item_r->p_next   =  *pp_item_l;               /* Swap the two items.                                  */
+              (*pp_item_l)->p_next =   p_tmp;
+               *pp_item_l          =   p_item_r;
+                pp_item_l          = &(p_item_r->p_next);
+                swapped            =   DEF_YES;                 /* Indicate a swap has been done.                       */
+            } else {
+                pp_item_l = &((*pp_item_l)->p_next);
+            }
+        }
+    } while (swapped == DEF_YES);                               /* Re-loop until no items have been swapped.            */
+}

+ 117 - 0
Collections/slist.h

@@ -0,0 +1,117 @@
+/*
+*********************************************************************************************************
+*                                              uC/Common
+*                                 Common Features for Micrium Stacks
+*
+*                    Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
+*
+*                                 SPDX-License-Identifier: APACHE-2.0
+*
+*               This software is subject to an open source license and is distributed by
+*                Silicon Laboratories Inc. pursuant to the terms of the Apache License,
+*                    Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
+*
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*
+*                               uC/Common - Singly-linked Lists (SList)
+*
+* Filename : slist.h
+* Version  : V1.02.00
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                               MODULE
+*
+* Note(s) : (1) This library header file is protected from multiple pre-processor inclusion through
+*               use of the library module present pre-processor macro definition.
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#ifndef  COLL_SLIST_MODULE_PRESENT                              /* See Note #1.                                         */
+#define  COLL_SLIST_MODULE_PRESENT
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            INCLUDE FILES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#include  <cpu.h>
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                             DATA TYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+typedef  struct  slist_member  SLIST_MEMBER;
+
+struct  slist_member {
+    SLIST_MEMBER  *p_next;
+};
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                              MACROS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+#define  OFFSET_OF(type, member)                      ((CPU_SIZE_T)&(((type *)0)->member))
+#define  CONTAINER_OF(p_member, parent_type, member)  (parent_type *)((CPU_ADDR)(p_member) - ((CPU_ADDR)(&((parent_type *)0)->member)))
+
+#define  SLIST_FOR_EACH(list_head, iterator)          for ((iterator) = (list_head); (iterator) != DEF_NULL; (iterator) = (iterator)->p_next)
+
+#define  SLIST_FOR_EACH_ENTRY(list_head, entry, type, member) for (  (entry) = SLIST_ENTRY(list_head, type, member); \
+                                                                   &((entry)->member.p_next) != DEF_NULL; \
+                                                                     (entry) = SLIST_ENTRY((entry)->member.p_next, type, member))
+
+#define  SLIST_ENTRY                                  CONTAINER_OF
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                         FUNCTION PROTOTYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+void           SList_Init     (SLIST_MEMBER  **p_head_ptr);
+
+void           SList_Push     (SLIST_MEMBER  **p_head_ptr,
+                               SLIST_MEMBER   *p_item);
+
+void           SList_PushBack (SLIST_MEMBER  **p_head_ptr,
+                               SLIST_MEMBER   *p_item);
+
+SLIST_MEMBER  *SList_Pop      (SLIST_MEMBER  **p_head_ptr);
+
+void           SList_Add      (SLIST_MEMBER   *p_item,
+                               SLIST_MEMBER   *p_pos);
+
+void           SList_Rem      (SLIST_MEMBER  **p_head_ptr,
+                               SLIST_MEMBER   *p_item);
+
+void           SList_Sort     (SLIST_MEMBER  **p_head_ptr,
+                               CPU_BOOLEAN   (*cmp_fnct)(SLIST_MEMBER  *p_item_l, SLIST_MEMBER  *p_item_r));
+
+#endif /* COLL_SLIST_MODULE_PRESENT */

+ 1549 - 0
KAL/None/kal.c

@@ -0,0 +1,1549 @@
+/*
+*********************************************************************************************************
+*                                              uC/Common
+*                                 Common Features for Micrium Stacks
+*
+*                    Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
+*
+*                                 SPDX-License-Identifier: APACHE-2.0
+*
+*               This software is subject to an open source license and is distributed by
+*                Silicon Laboratories Inc. pursuant to the terms of the Apache License,
+*                    Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
+*
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*
+*                             uC/Common - Kernel Abstraction Layer (KAL)
+*                                         No Operating System
+*
+* Filename : kal.c
+* Version  : V1.02.00
+*********************************************************************************************************
+* Note(s)  : (1) Since no operating system is present, most of the present features are implemented
+*                directly in the KAL.
+*
+*            (2) Since no operating system is present, active wait is used and may considerably
+*                reduce performance.
+*
+*            (3) Since no operating system is present, it is assumed that there is no multi-tasking.
+*                Therefore, the locking mechanism can be reduced to nothing, since the execution
+*                flow can only be pre-empted by an interrupt and it is impossible to pend on a lock
+*                in an interrupt context.
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                             INCLUDE FILES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#define  MICRIUM_SOURCE
+#define  KAL_MODULE
+
+#include  "../kal.h"
+
+#include  <lib_def.h>
+#include  <lib_mem.h>
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                             LOCAL DEFINES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#define  KAL_CFG_ARG_CHK_EXT_EN                 DEF_ENABLED
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            LOCAL CONSTANTS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+KAL_CPP_EXT  const  CPU_INT32U           KAL_Version           =  10000u;
+KAL_CPP_EXT  const  KAL_TICK_RATE_HZ     KAL_TickRate          =  0u;
+
+KAL_CPP_EXT  const  KAL_TASK_HANDLE      KAL_TaskHandleNull    = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_LOCK_HANDLE      KAL_LockHandleNull    = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_SEM_HANDLE       KAL_SemHandleNull     = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_TMR_HANDLE       KAL_TmrHandleNull     = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_Q_HANDLE         KAL_QHandleNull       = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_TASK_REG_HANDLE  KAL_TaskRegHandleNull = {DEF_NULL};
+
+             const  KAL_LOCK_HANDLE      KAL_LockDfltHandle    = {(void *)1u};
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                           LOCAL DATA TYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+                                                                /* ------------------- KAL SEM TYPE ------------------- */
+typedef  struct  kal_sem {
+    volatile  CPU_INT32U  Cnt;                                  /* Cnt used by sem.                                     */
+} KAL_SEM;
+
+
+                                                                /* ----------------- KAL INTERNAL DATA ---------------- */
+typedef  struct  kal_data {
+    MEM_SEG       *MemSegPtr;                                   /* Mem Seg to alloc from.                               */
+    MEM_DYN_POOL   SemPool;                                     /* Pool for sems.                                       */
+} KAL_DATA;
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                              LOCAL TABLES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                         LOCAL GLOBAL VARIABLES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+static  KAL_DATA  *KAL_DataPtr = DEF_NULL;
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                       LOCAL FUNCTION PROTOTYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                       LOCAL CONFIGURATION ERRORS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            GLOBAL FUNCTIONS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                         KAL CORE API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                              KAL_Init()
+*
+* Description : Initialize the Kernel Abstraction Layer.
+*
+* Argument(s) : p_cfg       Pointer to KAL configuration structure.
+*
+*               p_err       Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_ALREADY_INIT       Already initialized and p_cfg is not NULL.
+*                                   RTOS_ERR_ALLOC              Memory segment allocation failed.
+*                                   RTOS_ERR_INIT               Memory pool initialization failed.
+*
+* Return(s)   : none.
+*
+* Note(s)     : (1) This function must be called prior to any product initialization function if the
+*                   application needs to specify a memory segment.
+*********************************************************************************************************
+*/
+
+void  KAL_Init (KAL_CFG   *p_cfg,
+                RTOS_ERR  *p_err)
+{
+    MEM_SEG  *p_seg;
+    LIB_ERR   err_lib;
+    CPU_SR_ALLOC();
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+    #endif
+
+    CPU_CRITICAL_ENTER();
+    if (KAL_DataPtr != DEF_NULL) {                              /* Chk if KAL already init. See note #1.                */
+        CPU_CRITICAL_EXIT();
+        if (p_cfg == DEF_NULL) {
+           *p_err = RTOS_ERR_NONE;                              /* KAL_Init() can be called many times if no cfg.       */
+        } else {
+           *p_err = RTOS_ERR_ALREADY_INIT;                      /* If a cfg is given and KAL is already init, set err.  */
+        }
+        return;
+    }
+
+    p_seg = DEF_NULL;
+    if (p_cfg != DEF_NULL) {                                    /* Load cfg if given.                                   */
+        p_seg = p_cfg->MemSegPtr;
+    }
+
+    KAL_DataPtr = (KAL_DATA *)Mem_SegAlloc("KAL internal data",
+                                            p_seg,
+                                            sizeof(KAL_DATA),
+                                           &err_lib);
+    CPU_CRITICAL_EXIT();
+    if (err_lib != LIB_MEM_ERR_NONE) {
+       *p_err = RTOS_ERR_ALLOC;
+        return;
+    }
+
+    KAL_DataPtr->MemSegPtr = p_seg;
+
+    Mem_DynPoolCreate("KAL sem pool",
+                      &KAL_DataPtr->SemPool,
+                       KAL_DataPtr->MemSegPtr,
+                       sizeof(KAL_SEM),
+                       sizeof(CPU_ALIGN),
+                       0u,
+                       LIB_MEM_BLK_QTY_UNLIMITED,
+                      &err_lib);
+    if (err_lib != LIB_MEM_ERR_NONE) {
+       *p_err = RTOS_ERR_INIT;
+        return;
+    }
+
+   *p_err = RTOS_ERR_NONE;
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                          KAL_FeatureQuery()
+*
+* Description : Check if specified feature is available.
+*
+* Argument(s) : feature     Feature to query.
+*
+*               opt         Option associated with the feature requested.
+*
+* Return(s)   : DEF_YES, if feature is available.
+*
+*               DEF_NO,  otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+CPU_BOOLEAN  KAL_FeatureQuery (KAL_FEATURE  feature,
+                               KAL_OPT      opt)
+{
+    CPU_BOOLEAN  is_en;
+
+
+    (void)opt;
+
+    is_en = DEF_NO;
+
+    switch (feature) {
+        case KAL_FEATURE_TASK_CREATE:                           /* ---------------------- TASKS ----------------------- */
+        case KAL_FEATURE_TASK_DEL:
+             break;
+
+
+        case KAL_FEATURE_LOCK_CREATE:                           /* ---------------------- LOCKS ----------------------- */
+        case KAL_FEATURE_LOCK_ACQUIRE:
+        case KAL_FEATURE_LOCK_RELEASE:
+        case KAL_FEATURE_LOCK_DEL:
+             is_en = DEF_YES;
+             break;
+
+
+        case KAL_FEATURE_SEM_CREATE:                            /* ----------------------- SEMS ----------------------- */
+        case KAL_FEATURE_SEM_DEL:
+             is_en = DEF_YES;
+             break;
+
+
+        case KAL_FEATURE_SEM_PEND:
+             if (DEF_BIT_IS_SET(opt, KAL_OPT_PEND_NON_BLOCKING) == DEF_YES) {
+                 is_en = DEF_YES;
+             } else {
+                 #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
+                     is_en = DEF_YES;
+                 #endif
+             }
+             break;
+
+
+        case KAL_FEATURE_SEM_POST:
+             is_en = DEF_YES;
+             break;
+
+
+        case KAL_FEATURE_SEM_ABORT:
+        case KAL_FEATURE_SEM_SET:
+             break;
+
+
+        case KAL_FEATURE_Q_CREATE:                              /* ---------------------- QUEUES ---------------------- */
+        case KAL_FEATURE_Q_POST:
+        case KAL_FEATURE_Q_PEND:
+             break;
+
+
+        case KAL_FEATURE_DLY:                                   /* ----------------------- DLYS ----------------------- */
+             #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
+                 is_en = DEF_YES;
+             #endif
+             break;
+
+
+        case KAL_FEATURE_TASK_REG:                              /* --------------------- TASK REGS -------------------- */
+             break;
+
+
+        case KAL_FEATURE_TICK_GET:                              /* ------------------- TICK CTR INFO ------------------ */
+             break;
+
+
+        default:
+             break;
+    }
+
+    return (is_en);
+}
+
+
+/*
+*********************************************************************************************************
+*                                         TASK API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                            KAL_TaskAlloc()
+*
+* Description : Allocate a task object and its stack.
+*
+* Argument(s) : p_name          Pointer to name of the task.
+*
+*               p_stk_base      Pointer to start of task stack. If NULL, the stack will be allocated from
+*                               the KAL memory segment.
+*
+*               stk_size_bytes  Size (in bytes) of the task stack.
+*
+*               p_cfg           Pointer to KAL task configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_AVAIL          Feature not available without an OS.
+*
+* Return(s)   : Allocated task's handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TASK_HANDLE  KAL_TaskAlloc (const  CPU_CHAR          *p_name,
+                                       void              *p_stk_base,
+                                       CPU_SIZE_T         stk_size_bytes,
+                                       KAL_TASK_EXT_CFG  *p_cfg,
+                                       RTOS_ERR          *p_err)
+{
+    KAL_TASK_HANDLE  handle = KAL_TaskHandleNull;
+
+
+                                                                /* Task creation is not avail.                          */
+    (void)p_name;
+    (void)p_stk_base;
+    (void)stk_size_bytes;
+    (void)p_cfg;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NOT_AVAIL;
+
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_TaskCreate()
+*
+* Description : Create and start a task.
+*
+* Argument(s) : task_handle     Handle of the task to create.
+*
+*               p_fnct          Pointer to task function.
+*
+*               p_task_arg      Pointer to argument that will be passed to task function (can be DEF_NULL).
+*
+*               prio            Task priority.
+*
+*               p_cfg           Pointer to KAL task configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_AVAIL          Feature not available without an OS.
+* Return(s)   : none.
+*
+* Note(s)     : (1) The task must be allocated prior to this call using KAL_TaskAlloc().
+*********************************************************************************************************
+*/
+
+void  KAL_TaskCreate (KAL_TASK_HANDLE     task_handle,
+                      void              (*p_fnct)(void  *p_arg),
+                      void               *p_task_arg,
+                      CPU_INT08U          prio,
+                      KAL_TASK_EXT_CFG   *p_cfg,
+                      RTOS_ERR           *p_err)
+{
+                                                                /* Task creation is not avail.                          */
+    (void)task_handle;
+    (void)(*p_fnct);
+    (void)p_task_arg;
+    (void)prio;
+    (void)p_cfg;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NOT_AVAIL;
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_TaskDel()
+*
+* Description : Delete a task.
+*
+* Argument(s) : task_handle     Handle of the task to delete.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_AVAIL          Feature not available without an OS.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_TaskDel (KAL_TASK_HANDLE   task_handle,
+                   RTOS_ERR         *p_err)
+{
+                                                                /* Task del is not avail.                               */
+    (void)task_handle;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NOT_AVAIL;
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                         LOCK API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                           KAL_LockCreate()
+*
+* Description : Create a lock, which is unlocked by default.
+*
+* Argument(s) : p_name          Pointer to name of the lock.
+*
+*               p_cfg           Pointer to KAL lock configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               Function always successful.
+*
+* Return(s)   : Created lock handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_LOCK_HANDLE  KAL_LockCreate (const  CPU_CHAR          *p_name,
+                                        KAL_LOCK_EXT_CFG  *p_cfg,
+                                        RTOS_ERR          *p_err)
+{
+    KAL_LOCK_HANDLE  handle = KAL_LockHandleNull;
+
+
+    (void)p_name;
+    (void)p_cfg;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NONE;
+
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_LockAcquire()
+*
+* Description : Acquire a lock.
+*
+* Argument(s) : lock_handle     Handle of the lock to acquire.
+*
+*               opt             Options available:
+*                                   KAL_OPT_PEND_NONE:          block until timeout expires or lock is available.
+*                                   KAL_OPT_PEND_BLOCKING:      block until timeout expires or lock is available.
+*                                   KAL_OPT_PEND_NON_BLOCKING:  return immediately even if lock is not available.
+*
+*               timeout_ms      Timeout, in milliseconds. A value of 0 will never timeout.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               Function always successful.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_LockAcquire (KAL_LOCK_HANDLE   lock_handle,
+                       KAL_OPT           opt,
+                       CPU_INT32U        timeout_ms,
+                       RTOS_ERR         *p_err)
+{
+    (void)lock_handle;
+    (void)opt;
+    (void)timeout_ms;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NONE;
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_LockRelease()
+*
+* Description : Release a lock.
+*
+* Argument(s) : lock_handle     Handle of the lock to release.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               Function always successful.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_LockRelease (KAL_LOCK_HANDLE   lock_handle,
+                       RTOS_ERR         *p_err)
+{
+    (void)lock_handle;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NONE;
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_LockDel()
+*
+* Description : Delete a lock.
+*
+* Argument(s) : lock_handle     Handle of the lock to delete.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               Function always successful.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_LockDel (KAL_LOCK_HANDLE   lock_handle,
+                   RTOS_ERR         *p_err)
+{
+    (void)lock_handle;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NONE;
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                          SEM API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                            KAL_SemCreate()
+*
+* Description : Create a semaphore, with a count of 0.
+*
+* Argument(s) : p_name          Pointer to name of the semaphore.
+*
+*               p_cfg           Pointer to KAL semaphore configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_SUPPORTED      'p_cfg' parameter was not NULL.
+*                                   RTOS_ERR_ALLOC              Unable to allocate memory for semaphore.
+*
+* Return(s)   : Created semaphore's handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_SEM_HANDLE  KAL_SemCreate (const  CPU_CHAR         *p_name,
+                                      KAL_SEM_EXT_CFG  *p_cfg,
+                                      RTOS_ERR         *p_err)
+{
+    KAL_SEM_HANDLE   handle = KAL_SemHandleNull;
+    KAL_SEM         *p_sem;
+    LIB_ERR          err_lib;
+
+
+    (void)p_name;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+
+        if (p_cfg != DEF_NULL) {                                /* Make sure no unsupported cfg recv.                   */
+           *p_err = RTOS_ERR_NOT_SUPPORTED;
+            return (handle);
+        }
+    #else
+        (void)p_cfg;
+    #endif
+
+    p_sem = (KAL_SEM *)Mem_DynPoolBlkGet(&KAL_DataPtr->SemPool,
+                                         &err_lib);
+    if (err_lib != LIB_MEM_ERR_NONE) {
+       *p_err = RTOS_ERR_ALLOC;
+        return (handle);
+    }
+
+    p_sem->Cnt       =  0u;                                     /* Created sem is unvavail at creation.                 */
+    handle.SemObjPtr = (void *)p_sem;
+   *p_err            =  RTOS_ERR_NONE;
+
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemPend()
+*
+* Description : Pend on a semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to pend on.
+*
+*               opt             Options available:
+*                                   KAL_OPT_PEND_NONE:          block until timeout expires or semaphore is available.
+*                                   KAL_OPT_PEND_BLOCKING:      block until timeout expires or semaphore is available.
+*                                   KAL_OPT_PEND_NON_BLOCKING:  return immediately even if semaphore is not available.
+*
+*               timeout_ms      Timeout, in milliseconds. A value of 0 will never timeout.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_WOULD_BLOCK        KAL_OPT_PEND_NON_BLOCKING opt specified and
+*                                                               semaphore is not available.
+*                                   RTOS_ERR_TIMEOUT            Operation timed-out.
+*                                   RTOS_ERR_OS                 Generic OS error.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPend (KAL_SEM_HANDLE   sem_handle,
+                   KAL_OPT          opt,
+                   CPU_INT32U       timeout_ms,
+                   RTOS_ERR        *p_err)
+{
+    KAL_SEM    *p_sem;
+    CPU_REG32   sem_cnt = 0u;
+    CPU_SR_ALLOC();
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_SEM_HANDLE_IS_NULL(sem_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+
+        if (DEF_BIT_IS_SET_ANY(opt, ~(KAL_OPT_PEND_NONE | KAL_OPT_PEND_NON_BLOCKING)) == DEF_YES) {
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return;
+        }
+
+        if (dly_ts > (DEF_GET_U_MAX_VAL(CPU_TS_TMR) - 1u)) {
+           *p_err = RTOS_ERR_INVALID_ARG;                       /* Dly too long for size of tmr used.                   */
+            return;
+        }
+    #endif
+
+    p_sem = (KAL_SEM *)sem_handle.SemObjPtr;
+
+    if (DEF_BIT_IS_CLR(opt, KAL_OPT_PEND_NON_BLOCKING) == DEF_YES) {
+                                                                /* Blocking call.                                       */
+        if (timeout_ms == 0u) {
+            while (sem_cnt == 0u) {
+                CPU_CRITICAL_ENTER();
+                sem_cnt = p_sem->Cnt;
+                if (sem_cnt != 0u) {
+                   p_sem->Cnt--;                                /* Dec sem cnt.                                         */
+                }
+                CPU_CRITICAL_EXIT();
+            }
+           *p_err = RTOS_ERR_NONE;
+        } else {
+            #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
+            {
+                CPU_TS_TMR       ts;
+                CPU_TS_TMR       ts_prev;
+                CPU_INT32U       ts_delta;
+                CPU_INT32U       timeout_ts;
+                CPU_TS_TMR_FREQ  tmr_freq;
+                CPU_INT08U       tmr_size = sizeof(CPU_TS_TMR);
+                CPU_ERR          err_cpu;
+
+
+                tmr_freq = CPU_TS_TmrFreqGet(&err_cpu);
+                if (err_cpu != CPU_ERR_NONE) {
+                   *p_err = RTOS_ERR_OS;
+                    return;
+                }
+
+                timeout_ts = timeout_ms * (tmr_freq / 1000u);   /* Calc timeout ts val, depending on tmr freq.          */
+                ts_delta   = 0u;
+                ts_prev    = CPU_TS_TmrRd();
+
+                while (ts_delta < timeout_ts) {                 /* Loop until sem is avail or timeout expires.          */
+                    CPU_CRITICAL_ENTER();
+                    sem_cnt = p_sem->Cnt;
+                    if (sem_cnt != 0u) {
+                        p_sem->Cnt--;                           /* Dec sem cnt.                                         */
+                        CPU_CRITICAL_EXIT();
+                       *p_err = RTOS_ERR_NONE;
+                        return;
+                    }
+                    CPU_CRITICAL_EXIT();
+
+                    ts = CPU_TS_TmrRd();
+                    if (ts >= ts_prev) {                        /* Update ts_delta val.                                 */
+                        ts_delta += ts - ts_prev;
+                    } else {                                    /* Wraparound.                                          */
+                        ts_delta += DEF_GET_U_MAX_VAL(CPU_TS_TMR) - ts_prev + ts;
+                    }
+                    ts_prev = ts;
+                }
+               *p_err = RTOS_ERR_TIMEOUT;
+            }
+            #else
+               *p_err = RTOS_ERR_NOT_AVAIL;
+            #endif
+        }
+    } else {                                                    /* Non-blocking call.                                   */
+        CPU_CRITICAL_ENTER();
+        if (p_sem->Cnt != 0u) {
+            p_sem->Cnt--;
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = RTOS_ERR_WOULD_BLOCK;
+        }
+        CPU_CRITICAL_EXIT();
+    }
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemPost()
+*
+* Description : Post a semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to post.
+*
+*               opt             Options available:
+*                                   KAL_OPT_POST_NONE:     wake only the highest priority task pending on semaphore.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_WOULD_OVF          Semaphore would overflow.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPost (KAL_SEM_HANDLE   sem_handle,
+                   KAL_OPT          opt,
+                   RTOS_ERR        *p_err)
+{
+    KAL_SEM  *p_sem;
+    CPU_SR_ALLOC();
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_SEM_HANDLE_IS_NULL(sem_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+
+        if (opt != KAL_OPT_POST_NONE) {
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return;
+        }
+    #endif
+
+    p_sem = (KAL_SEM *)sem_handle.SemObjPtr;
+
+    CPU_CRITICAL_ENTER();
+    p_sem->Cnt++;
+    if (p_sem->Cnt != 0u) {
+       *p_err = RTOS_ERR_NONE;
+    } else {
+       *p_err = RTOS_ERR_WOULD_OVF;
+        p_sem->Cnt--;
+    }
+    CPU_CRITICAL_EXIT();
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                          KAL_SemPendAbort()
+*
+* Description : Abort given semaphore and resume all the tasks pending on it.
+*
+* Argument(s) : sem_handle      Handle of the sempahore to abort.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Feature not implemented.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPendAbort (KAL_SEM_HANDLE   sem_handle,
+                        RTOS_ERR        *p_err)
+{
+    (void)sem_handle;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemSet()
+*
+* Description : Set value of semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to set.
+*
+*               cnt             Count value to set semaphore.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Feature not implemented.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemSet (KAL_SEM_HANDLE   sem_handle,
+                  CPU_INT16U       cnt,
+                  RTOS_ERR        *p_err)
+{
+    (void)sem_handle;
+    (void)cnt;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemDel()
+*
+* Description : Delete a semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to delete.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemDel (KAL_SEM_HANDLE   sem_handle,
+                  RTOS_ERR        *p_err)
+{
+    KAL_SEM  *p_sem;
+    LIB_ERR   err_lib;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_SEM_HANDLE_IS_NULL(sem_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    p_sem = (KAL_SEM *)sem_handle.SemObjPtr;
+
+    Mem_DynPoolBlkFree(       &KAL_DataPtr->SemPool,
+                       (void *)p_sem,
+                              &err_lib);
+    (void)err_lib;
+
+   *p_err = RTOS_ERR_NONE;
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                          TMR API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                            KAL_TmrCreate()
+*
+* Description : Create a single-shot timer.
+*
+* Argument(s) : p_name          Pointer to name of the timer.
+*
+*               p_callback      Pointer to the callback function that will be called on completion of timer.
+*
+*               p_callback_arg  Argument passed to callback function.
+*
+*               interval_ms     If timer is 'one-shot', delay  used by the timer, in milliseconds.
+*                               If timer is 'periodic', period used by the timer, in milliseconds.
+*
+*               p_cfg           Pointer to KAL timer configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*
+* Return(s)   : Created timer handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TMR_HANDLE  KAL_TmrCreate (const  CPU_CHAR   *p_name,
+                               void             (*p_callback)(void  *p_arg),
+                               void              *p_callback_arg,
+                               CPU_INT32U         interval_ms,
+                               KAL_TMR_EXT_CFG   *p_cfg,
+                               RTOS_ERR          *p_err)
+{
+    KAL_TMR_HANDLE  handle = KAL_TmrHandleNull;
+
+
+    (void)p_name;
+    (void)p_callback;
+    (void)p_callback_arg;
+    (void)interval_ms;
+    (void)p_cfg;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NOT_AVAIL;
+
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                            KAL_TmrStart()
+*
+* Description : Start timer.
+*
+* Argument(s) : tmr_handle      Handle of timer to start.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_TmrStart (KAL_TMR_HANDLE   tmr_handle,
+                    RTOS_ERR        *p_err)
+{
+    (void)tmr_handle;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NOT_AVAIL;
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                           Q API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                             KAL_QCreate()
+*
+* Description : Create an empty queue.
+*
+* Argument(s) : p_name          Pointer to name of the queue.
+*
+*               max_msg_qty     Maximum number of message contained in the queue.
+*
+*               p_cfg           Pointer to KAL queue configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_AVAIL          Feature not available without an OS.
+*
+* Return(s)   : Created queue handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_Q_HANDLE  KAL_QCreate (const  CPU_CHAR       *p_name,
+                                  KAL_MSG_QTY     max_msg_qty,
+                                  KAL_Q_EXT_CFG  *p_cfg,
+                                  RTOS_ERR       *p_err)
+{
+    KAL_Q_HANDLE  handle = KAL_QHandleNull;
+
+
+                                                                /* Qs are not avail.                                    */
+    (void)p_name;
+    (void)max_msg_qty;
+    (void)p_cfg;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NOT_AVAIL;
+
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                              KAL_QPend()
+*
+* Description : Pend/get first message of queue.
+*
+* Argument(s) : q_handle        Handle of the queue to pend on.
+*
+*               opt             Options available:
+*                                   KAL_OPT_PEND_NONE:          block until timeout expires or message is available.
+*                                   KAL_OPT_PEND_BLOCKING:      block until timeout expires or message is available.
+*                                   KAL_OPT_PEND_NON_BLOCKING:  return immediately with or without message.
+*
+*               timeout_ms      Timeout, in milliseconds. A value of 0 will never timeout.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_AVAIL          Feature not available without an OS.
+*
+* Return(s)   : Pointer to message obtained, if any, if no error.
+*
+*               Null pointer,                        otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  *KAL_QPend (KAL_Q_HANDLE   q_handle,
+                  KAL_OPT        opt,
+                  CPU_INT32U     timeout_ms,
+                  RTOS_ERR      *p_err)
+{
+                                                                /* Qs are not avail.                                    */
+    (void)q_handle;
+    (void)opt;
+    (void)timeout_ms;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(DEF_NULL);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NOT_AVAIL;
+
+    return (DEF_NULL);
+}
+
+
+/*
+*********************************************************************************************************
+*                                              KAL_QPost()
+*
+* Description : Post message on queue.
+*
+* Argument(s) : q_handle        Handle of the queue on which to post message.
+*
+*               p_msg           Pointer to message to post.
+*
+*               opt             Options available:
+*                                   KAL_OPT_POST_NONE:     wake only the highest priority task pending on queue.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_AVAIL          Feature not available without an OS.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_QPost (KAL_Q_HANDLE   q_handle,
+                 void          *p_msg,
+                 KAL_OPT        opt,
+                 RTOS_ERR      *p_err)
+{
+                                                                /* Qs are not avail.                                    */
+    (void)q_handle;
+    (void)p_msg;
+    (void)opt;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NOT_AVAIL;
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                          DLY API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                               KAL_Dly()
+*
+* Description : Delay current task (in milliseconds).
+*
+* Argument(s) : dly_ms          Delay value, in milliseconds.
+*
+* Return(s)   : none.
+*
+* Note(s)     : (1) This function is only available if time stamp is enabled. Otherwise, without an OS,
+*                   there is no other available way to measure time.
+*********************************************************************************************************
+*/
+
+void  KAL_Dly (CPU_INT32U  dly_ms)
+{
+    #if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
+        CPU_TS_TMR       ts;
+        CPU_TS_TMR       ts_prev;
+        CPU_INT32U       ts_delta;
+        CPU_INT32U       dly_ts;
+        CPU_TS_TMR_FREQ  tmr_freq;
+        CPU_INT08U       tmr_size = sizeof(CPU_TS_TMR);
+        CPU_ERR          err_cpu;
+
+
+        #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)             /* ---------------- VALIDATE ARGUMENTS ---------------- */
+            if (dly_ts > (DEF_GET_U_MAX_VAL(CPU_TS_TMR) - 1u)) {
+                CPU_SW_EXCEPTION(;);                            /* Fail call. Dly too long for size of tmr used.        */
+            }
+        #endif
+
+        tmr_freq = CPU_TS_TmrFreqGet(&err_cpu);
+        if (err_cpu != CPU_ERR_NONE) {
+            CPU_SW_EXCEPTION(;);                                /* Fail call.                                           */
+        }
+
+        dly_ts   = dly_ms * (tmr_freq / 1000u);                 /* Calc dly ts val, depending on tmr freq.              */
+        ts_delta = 0u;
+        ts_prev  = CPU_TS_TmrRd();
+
+        while (ts_delta < dly_ts) {                             /* Loop until dly expires.                              */
+            ts = CPU_TS_TmrRd();
+            if (ts > ts_prev) {                                 /* Update ts_delta val.                                 */
+                ts_delta += ts - ts_prev;
+            } else {                                            /* Wraparound.                                          */
+                ts_delta += DEF_GET_U_MAX_VAL(CPU_TS_TMR) - ts_prev + ts;
+            }
+            ts_prev = ts;
+        }
+
+        return;
+    #else
+        (void)dly_ms;
+
+        CPU_SW_EXCEPTION(;);                                    /* Fail call. See note #1.                              */
+    #endif
+}
+
+/*
+*********************************************************************************************************
+*                                             KAL_DlyTick()
+*
+* Description : Delay current task (in ticks).
+*
+* Argument(s) : dly_ticks       Delay value, in ticks.
+*
+*               opt             Options available:
+*                                   KAL_OPT_DLY_NONE:       apply a 'normal' delay.
+*                                   KAL_OPT_DLY:            apply a 'normal' delay.
+*                                   KAL_OPT_DLY_PERIODIC:   apply a periodic delay.
+*
+* Return(s)   : none.
+*
+* Note(s)     : (1) This function can only be called if an OS is present, since the notion of 'tick' is
+*                   not present if no OS is available.
+*********************************************************************************************************
+*/
+
+void  KAL_DlyTick (KAL_TICK  dly_ticks,
+                   KAL_OPT   opt)
+{
+    (void)dly_ticks;
+    (void)opt;
+
+    CPU_SW_EXCEPTION(;);                                        /* Fail call. See note #1.                              */
+}
+
+
+/*
+*********************************************************************************************************
+*                                       TASK REG API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                          KAL_TaskRegCreate()
+*
+* Description : Create a task register.
+*
+* Argument(s) : p_cfg           Pointer to KAL task register configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_AVAIL          Feature not available without an OS.
+*
+* Return(s)   : Created task register's handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TASK_REG_HANDLE  KAL_TaskRegCreate (KAL_TASK_REG_EXT_CFG  *p_cfg,
+                                        RTOS_ERR              *p_err)
+{
+    KAL_TASK_REG_HANDLE  handle = KAL_TaskRegHandleNull;
+
+
+    (void)p_cfg;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NOT_AVAIL;
+
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_TaskRegGet()
+*
+* Description : Get value from a task register.
+*
+* Argument(s) : task_handle     Handle of the task associated to the task register. Current task is used if NULL.
+*
+*               task_reg_handle Handle of the task register to read.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_AVAIL          Feature not available without an OS.
+*
+* Return(s)   : Value read from the task register, if no error.
+*               0,                                 otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+CPU_INT32U  KAL_TaskRegGet (KAL_TASK_HANDLE       task_handle,
+                            KAL_TASK_REG_HANDLE   task_reg_handle,
+                            RTOS_ERR             *p_err)
+{
+                                                                /* Task reg is not avail.                               */
+    (void)task_handle;
+    (void)task_reg_handle;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(0u);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NOT_AVAIL;
+
+    return (0u);
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_TaskRegSet()
+*
+* Description : Set value of task register.
+*
+* Argument(s) : task_handle     Handle of the task associated to the task register. Current task is used if NULL.
+*
+*               task_reg_handle Handle of the task register to write to.
+*
+*               val             Value to write in the task register.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_AVAIL          Feature not available without an OS.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_TaskRegSet (KAL_TASK_HANDLE       task_handle,
+                      KAL_TASK_REG_HANDLE   task_reg_handle,
+                      CPU_INT32U            val,
+                      RTOS_ERR             *p_err)
+{
+                                                                /* Task reg is not avail.                               */
+    (void)task_handle;
+    (void)task_reg_handle;
+    (void)val;
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NOT_AVAIL;
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_TickGet()
+*
+* Description : Get value of OS' tick counter.
+*
+* Argument(s) : p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_AVAIL          Feature not available without an OS.
+*
+* Return(s)   : OS tick counter's value.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TICK  KAL_TickGet (RTOS_ERR  *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(0u);
+        }
+    #endif
+
+   *p_err = RTOS_ERR_NOT_AVAIL;
+
+    return (0u);
+}
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            LOCAL FUNCTIONS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+

+ 1175 - 0
KAL/POSIX/kal.c

@@ -0,0 +1,1175 @@
+/*
+*********************************************************************************************************
+*                                              uC/Common
+*                                 Common Features for Micrium Stacks
+*
+*                    Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
+*
+*                                 SPDX-License-Identifier: APACHE-2.0
+*
+*               This software is subject to an open source license and is distributed by
+*                Silicon Laboratories Inc. pursuant to the terms of the Apache License,
+*                    Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
+*
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*
+*                             uC/Common - Kernel Abstraction Layer (KAL)
+*                                            POSIX Threads
+*
+* Filename : kal.c
+* Version  : V1.02.00
+*********************************************************************************************************
+* Notes    : (1) Requires a Single UNIX Specification, Version 3 compliant operating environment.
+*                On Linux _XOPEN_SOURCE must be defined to at least 600, generally by passing the
+*                -D_XOPEN_SOURCE=600 command line option to GCC.
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                             INCLUDE FILES
+*********************************************************************************************************
+*/
+
+#define   MICRIUM_SOURCE
+#define   KAL_MODULE
+
+#include  "../kal.h"
+
+#include  <lib_def.h>
+
+#include  <pthread.h>
+#include  <semaphore.h>
+
+
+/*
+*********************************************************************************************************
+*                                             LOCAL DEFINES
+*********************************************************************************************************
+*/
+
+#define KAL_CFG_ARG_CHK_EXT_EN  DEF_ENABLED
+
+/*
+*********************************************************************************************************
+*                                            LOCAL CONSTANTS
+*********************************************************************************************************
+*/
+
+KAL_CPP_EXT  const  KAL_TASK_HANDLE      KAL_TaskHandleNull    = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_LOCK_HANDLE      KAL_LockHandleNull    = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_SEM_HANDLE       KAL_SemHandleNull     = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_Q_HANDLE         KAL_QHandleNull       = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_TMR_HANDLE       KAL_TmrHandleNull     = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_TASK_REG_HANDLE  KAL_TaskRegHandleNull = {DEF_NULL};
+
+
+/*
+*********************************************************************************************************
+*                                            LOCAL DATA TYPES
+*********************************************************************************************************
+*/
+
+typedef  struct  kal_data {
+    MEM_SEG       *MemSegPtr;
+
+    MEM_DYN_POOL   TaskPool;
+    MEM_DYN_POOL   LockPool;
+    MEM_DYN_POOL   SemPool;
+} KAL_DATA;
+
+typedef  struct  kal_lock {
+    pthread_mutex_t      Mutex;
+    pthread_mutexattr_t  MutexAttr;
+} KAL_LOCK;
+
+
+typedef  struct  kal_sem {
+    sem_t      Sem;
+} KAL_SEM;
+
+typedef  struct  kal_task {
+    pthread_t       Thread;
+    pthread_attr_t  ThreadAttr;
+} KAL_TASK;
+
+typedef  struct  kal_task_fnct_info {
+    void  (*Fnct)(void  *p_arg);
+    void   *ArgPtr;
+    sem_t   SemInit;
+} KAL_TASK_FNCT_INFO;
+
+
+/*
+*********************************************************************************************************
+*                                              LOCAL TABLES
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*                                         LOCAL GLOBAL VARIABLES
+*********************************************************************************************************
+*/
+
+static  KAL_DATA  *KAL_DataPtr = DEF_NULL;
+
+
+/*
+*********************************************************************************************************
+*                                       LOCAL FUNCTION PROTOTYPES
+*********************************************************************************************************
+*/
+
+void  *KAL_TaskFnctWrapper(void  *p_arg);
+
+
+/*
+*********************************************************************************************************
+*                                       LOCAL CONFIGURATION ERRORS
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            GLOBAL FUNCTIONS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                         KAL CORE API FUNCTIONS
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_Init()
+*
+* Description : Initialize the Kernel Abstraction Layer.
+*
+* Note(s)     : (1) This function must be called prior to any product initialization function if the
+*                   application needs to specify a memory segment
+*********************************************************************************************************
+*/
+
+void  KAL_Init (KAL_CFG  *p_cfg,
+                KAL_ERR  *p_err)
+{
+    LIB_ERR   err_lib;
+    MEM_SEG  *p_seg ;
+
+
+#if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                     /* ---------------- VALIDATE ARGUMENTS ---------------- */
+    if (p_err == DEF_NULL) {                                    /* Validate err ptr.                                    */
+        CPU_SW_EXCEPTION(DEF_NULL);
+    }
+#endif                                                          /* ----- (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED) ------ */
+
+    if (KAL_DataPtr != (KAL_DATA *)0) {                         /* Chk if KAL already init. See note (1).               */
+       *p_err = KAL_ERR_NONE;
+        return;
+    }
+
+                                                                /* ------------------ ALLOC KAL DATA ------------------ */
+    p_seg = DEF_NULL;
+    if (p_cfg != DEF_NULL) {                                    /* Load cfg if given.                                   */
+        KAL_DataPtr->MemSegPtr = p_cfg->MemSegPtr;
+    }
+
+    KAL_DataPtr = (KAL_DATA *)Mem_SegAlloc("KAL internal data",
+                                            p_seg,
+                                            sizeof(KAL_DATA),
+                                           &err_lib);
+    if (err_lib != LIB_MEM_ERR_NONE) {
+       *p_err = KAL_ERR_MEM_ALLOC;
+        return;
+    }
+
+    KAL_DataPtr->MemSegPtr = p_seg;
+
+                                                                /* ----------------- CREATE TASK POOL ----------------- */
+    Mem_DynPoolCreate("KAL task pool",
+                     &KAL_DataPtr->TaskPool,
+                      KAL_DataPtr->MemSegPtr,
+                      sizeof(KAL_TASK),
+                      sizeof(CPU_ALIGN),
+                      0u,
+                      LIB_MEM_BLK_QTY_UNLIMITED,
+                     &err_lib);
+    if (err_lib != LIB_MEM_ERR_NONE) {
+       *p_err = KAL_ERR_POOL_INIT;
+        return;
+    }
+
+                                                                /* ----------------- CREATE LOCK POOL ----------------- */
+    Mem_DynPoolCreate("KAL lock pool",
+                     &KAL_DataPtr->LockPool,
+                      KAL_DataPtr->MemSegPtr,
+                      sizeof(KAL_LOCK),
+                      sizeof(CPU_ALIGN),
+                      0u,
+                      LIB_MEM_BLK_QTY_UNLIMITED,
+                     &err_lib);
+    if (err_lib != LIB_MEM_ERR_NONE) {
+       *p_err = KAL_ERR_POOL_INIT;
+        return;
+    }
+
+                                                                /* ----------------- CREATE LOCK POOL ----------------- */
+    Mem_DynPoolCreate("KAL sem pool",
+                     &KAL_DataPtr->SemPool,
+                      KAL_DataPtr->MemSegPtr,
+                      sizeof(KAL_SEM),
+                      sizeof(CPU_ALIGN),
+                      0u,
+                      LIB_MEM_BLK_QTY_UNLIMITED,
+                      &err_lib);
+    if (err_lib != LIB_MEM_ERR_NONE) {
+        *p_err = KAL_ERR_POOL_INIT;
+        return;
+    }
+
+
+   *p_err = KAL_ERR_NONE;
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                         KAL_FeatureQuery()
+*
+* Description : Query a feature and make sure it is available.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+CPU_BOOLEAN  KAL_FeatureQuery (KAL_FEATURE  feature,
+                               KAL_OPT      opt)
+{
+    switch (feature) {
+        case KAL_FEATURE_LOCK_CREATE:
+        case KAL_FEATURE_LOCK_DEL:
+             return (DEF_YES);
+
+
+        default:
+             return (DEF_NO);
+    }
+}
+
+
+/*
+*********************************************************************************************************
+*                                         TASK API FUNCTIONS
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_TaskAlloc()
+*
+* Description : Allocate a task object and its stack.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+KAL_TASK_HANDLE  KAL_TaskAlloc (const  CPU_CHAR          *p_name,
+                                       void              *p_stk_base,
+                                       CPU_SIZE_T         stk_size_word,
+                                       KAL_TASK_EXT_CFG  *p_cfg,
+                                       KAL_ERR           *p_err)
+{
+    KAL_TASK_HANDLE   handle = {DEF_NULL};
+    KAL_TASK         *p_task_data;
+    LIB_ERR           lib_err;
+    int               pthread_err;
+
+#if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                     /* ---------------- VALIDATE ARGUMENTS ---------------- */
+    if (p_err == DEF_NULL) {                                    /* Validate err ptr.                                    */
+        CPU_SW_EXCEPTION(handle);
+    }
+
+    if (p_cfg != DEF_NULL) {                                    /* Chk for unimpl cfg specified.                        */
+       *p_err = KAL_ERR_UNIMPLEMENTED;
+        return (handle);
+    }
+
+    if (p_stk_base != DEF_NULL) {                               /* Chk for unimpl user-specified stk base.              */
+       *p_err = KAL_ERR_UNIMPLEMENTED;
+        return (handle);
+    }
+#endif
+
+    p_task_data = (KAL_TASK *)Mem_DynPoolBlkGet(&KAL_DataPtr->TaskPool,
+                                                     &lib_err);
+    if (lib_err != LIB_MEM_ERR_NONE) {
+       *p_err = KAL_ERR_MEM_ALLOC;
+        return (handle);
+    }
+
+                                                                /* ------------------ SET MUTEX ATTR ------------------ */
+    pthread_err = pthread_attr_init(&p_task_data->ThreadAttr);
+    if (pthread_err != 0) {
+       *p_err = KAL_ERR_CREATE;
+        return (handle);
+    }
+
+
+                                                                /* Turn off sched param inheritance.                    */
+    pthread_err = pthread_attr_setinheritsched(&p_task_data->ThreadAttr, PTHREAD_EXPLICIT_SCHED);
+    if (pthread_err != 0) {
+       *p_err = KAL_ERR_CREATE;
+        return (handle);
+    }
+
+                                                                /* Sel round-robin sched policy for equal-prio tasks    */
+    pthread_err = pthread_attr_setschedpolicy(&p_task_data->ThreadAttr, SCHED_RR);
+    if (pthread_err != 0) {
+       *p_err = KAL_ERR_CREATE;
+        return (handle);
+    }
+
+                                                                /* Set stk size.                                        */
+    pthread_err = pthread_attr_setstacksize(&p_task_data->ThreadAttr, stk_size_word * sizeof(CPU_DATA));
+    if (pthread_err != 0) {
+       *p_err = KAL_ERR_CREATE;
+        return (handle);
+    }
+
+    handle.TaskObjPtr = (void *)p_task_data;
+   *p_err = KAL_ERR_NONE;
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                          KAL_TaskSizeGet()
+*
+* Description : Get the size in memory of a task.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+CPU_SIZE_T  KAL_TaskSizeGet (CPU_SIZE_T         stk_size_word,
+                             KAL_TASK_EXT_CFG  *p_cfg,
+                             KAL_ERR           *p_err)
+{
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+    return (0);
+}
+
+
+/*
+*********************************************************************************************************
+*                                          KAL_TaskCreate()
+*
+* Description : Create a task.
+*
+* Note(s)     : (1) The task must be allocated prior to this call using KAL_TaskAlloc().
+*********************************************************************************************************
+*/
+
+void  KAL_TaskCreate (KAL_TASK_HANDLE    task_handle,
+                      void             (*p_fnct)(void *),
+                      void              *p_arg,
+                      CPU_INT08U         prio,
+                      KAL_TASK_EXT_CFG  *p_cfg,
+                      KAL_ERR           *p_err)
+{
+    KAL_TASK        *p_task_data;
+    KAL_TASK_FNCT_INFO    fnct_info;
+    int                   pthread_err;
+    struct  sched_param   param;
+
+
+#if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                     /* ---------------- VALIDATE ARGUMENTS ---------------- */
+    if (p_err == DEF_NULL) {                                    /* Validate err ptr.                                    */
+        CPU_SW_EXCEPTION(DEF_NULL);
+    }
+
+    if (task_handle.TaskObjPtr == DEF_NULL) {                   /* Chk for NULL obj ptr.                                */
+       *p_err = KAL_ERR_NULL_PTR;
+        return;
+    }
+
+    if (p_cfg != DEF_NULL) {                                    /* Chk for invalid opt flag.                            */
+       *p_err = KAL_ERR_UNIMPLEMENTED;
+        return;
+    }
+#endif
+
+    p_task_data = (KAL_TASK *)task_handle.TaskObjPtr;
+
+                                                                /* ----------------- SET THREAD ATTRS ----------------- */
+    param.sched_priority = 99 - prio;
+    pthread_err = pthread_attr_setschedparam(&p_task_data->ThreadAttr, &param);
+    if (pthread_err != 0) {
+       *p_err = KAL_ERR_CREATE;
+        return;
+    }
+
+
+                                                                /* ------------------ CREATE THREAD ------------------- */
+    fnct_info.Fnct  = p_fnct;
+    fnct_info.ArgPtr = p_arg;
+
+    pthread_err = sem_init(&fnct_info.SemInit, 0u, 0u);
+    if (pthread_err != 0) {
+       *p_err = KAL_ERR_CREATE;
+        return;
+    }
+
+    pthread_err = pthread_create(&p_task_data->Thread,
+                                 &p_task_data->ThreadAttr,
+                                  KAL_TaskFnctWrapper,
+                         (void *)&fnct_info);
+    if (pthread_err != 0) {
+       *p_err = KAL_ERR_CREATE;
+        return;
+    }
+
+    pthread_err = sem_wait(&fnct_info.SemInit);
+    if (pthread_err != 0) {
+       *p_err = KAL_ERR_CREATE;
+        return;
+    }
+
+   *p_err = KAL_ERR_NONE;
+}
+
+
+/*
+*********************************************************************************************************
+*                                            KAL_TaskDel()
+*
+* Description : Delete a task.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+void  KAL_TaskDel (KAL_TASK_HANDLE   task_handle,
+                   KAL_ERR          *p_err)
+{
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                         LOCK API FUNCTIONS
+*********************************************************************************************************
+*/
+
+KAL_LOCK_HANDLE  KAL_LockCreate (const  CPU_CHAR          *p_name,
+                                        KAL_LOCK_EXT_CFG  *p_cfg,
+                                        KAL_ERR           *p_err)
+{
+    KAL_LOCK_HANDLE   handle = KAL_LockHandleNull;
+    KAL_LOCK    *p_lock_data;
+    LIB_ERR           lib_err;
+    int               pthread_err;
+
+
+#if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                     /* ---------------- VALIDATE ARGUMENTS ---------------- */
+    if (p_err == DEF_NULL) {                                    /* Validate err ptr.                                    */
+        CPU_SW_EXCEPTION(handle);
+    }
+
+    if ((p_cfg != DEF_NULL) &&                                  /* Chk for invalid opt flags.                           */
+        ((p_cfg->Opt & ~(KAL_OPT_CREATE_REENTRANT)) != 0u)) {
+       *p_err = KAL_ERR_INVALID_ARG;
+        return (handle);
+    }
+#endif
+
+    p_lock_data = (KAL_LOCK *)Mem_DynPoolBlkGet(&KAL_DataPtr->LockPool,
+                                                     &lib_err);
+    if (lib_err != LIB_MEM_ERR_NONE) {
+       *p_err = KAL_ERR_MEM_ALLOC;
+        return (handle);
+    }
+
+                                                                /* ------------------ SET MUTEX ATTR ------------------ */
+    pthread_err = pthread_mutexattr_init(&p_lock_data->MutexAttr);
+    if (pthread_err != 0) {
+       *p_err = KAL_ERR_CREATE;
+        goto fail_release_blk;
+    }
+
+    if (p_cfg != DEF_NULL) {                                    /* Set attr according to cfg.                           */
+        if (DEF_BIT_IS_SET(p_cfg->Opt, KAL_OPT_CREATE_REENTRANT)) {
+            pthread_err = pthread_mutexattr_settype(&p_lock_data->MutexAttr, PTHREAD_MUTEX_RECURSIVE);
+            if (pthread_err != 0) {
+               *p_err = KAL_ERR_CREATE;
+                goto fail_release_attr;
+            }
+        }
+    }
+
+                                                                /* -------------------- INIT MUTEX -------------------- */
+    pthread_err = pthread_mutex_init(&p_lock_data->Mutex, &p_lock_data->MutexAttr);
+    if (pthread_err != 0) {
+       *p_err = KAL_ERR_CREATE;
+        goto fail_release_attr;
+    }
+
+    handle.LockObjPtr = p_lock_data;
+
+   *p_err = KAL_ERR_NONE;
+    return (handle);
+
+
+fail_release_attr:
+    pthread_err = pthread_mutexattr_destroy(&p_lock_data->MutexAttr);
+    if (pthread_err != 0) {
+        CPU_SW_EXCEPTION(handle);
+    }
+
+fail_release_blk:
+    Mem_DynPoolBlkFree(&KAL_DataPtr->LockPool, (void *)p_lock_data, &lib_err);
+    if (lib_err != LIB_MEM_ERR_NONE) {
+        CPU_SW_EXCEPTION(handle);
+    }
+
+    return (handle);
+}
+
+
+CPU_SIZE_T  KAL_LockSizeGet (KAL_LOCK_EXT_CFG  *p_cfg,
+                             KAL_ERR           *p_err)
+{
+   *p_err = KAL_ERR_NONE;
+    return (sizeof(KAL_LOCK));
+}
+
+
+void  KAL_LockAcquire (KAL_LOCK_HANDLE   lock_handle,
+                       KAL_OPT           opt,
+                       CPU_INT32U        timeout,
+                       KAL_ERR          *p_err)
+{
+    KAL_LOCK  *p_lock_data;
+    int             pthread_err;
+
+
+#if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                     /* ---------------- VALIDATE ARGUMENTS ---------------- */
+    if (p_err == DEF_NULL) {                                    /* Validate err ptr.                                    */
+        CPU_SW_EXCEPTION(DEF_NULL);
+    }
+
+    if (lock_handle.LockObjPtr == DEF_NULL) {                   /* Chk for NULL obj ptr.                                */
+       *p_err = KAL_ERR_NULL_PTR;
+        return;
+    }
+
+    if (opt != 0u) {                                            /* Chk for invalid opt flag.                            */
+       *p_err = KAL_ERR_INVALID_ARG;
+        return;
+    }
+#endif
+
+    p_lock_data = (KAL_LOCK *)lock_handle.LockObjPtr;
+
+    if (timeout == 0u) {
+        pthread_err = pthread_mutex_lock(&p_lock_data->Mutex);
+        if (pthread_err != 0) {
+           *p_err = KAL_ERR_OS;
+            return;
+        }
+    } else {
+        struct  timespec  ts_timeout;
+
+
+        ts_timeout.tv_sec  =  timeout / 1000u;
+        ts_timeout.tv_nsec = (timeout % 1000u) * 1000u;
+
+        pthread_err = pthread_mutex_timedlock(&p_lock_data->Mutex, &ts_timeout);
+        if (pthread_err != 0) {
+           *p_err = KAL_ERR_OS;
+            return;
+        }
+    }
+
+   *p_err = KAL_ERR_NONE;
+}
+
+
+void  KAL_LockRelease (KAL_LOCK_HANDLE   lock_handle,
+                       KAL_ERR          *p_err)
+{
+    KAL_LOCK  *p_lock_data;
+    int             pthread_err;
+
+
+#if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                     /* ---------------- VALIDATE ARGUMENTS ---------------- */
+    if (p_err == DEF_NULL) {                                    /* Validate err ptr.                                    */
+        CPU_SW_EXCEPTION(DEF_NULL);
+    }
+
+    if (lock_handle.LockObjPtr == DEF_NULL) {                   /* Chk for NULL obj ptr.                                */
+       *p_err = KAL_ERR_NULL_PTR;
+        return;
+    }
+#endif
+
+    p_lock_data = (KAL_LOCK *)lock_handle.LockObjPtr;
+
+    pthread_err = pthread_mutex_unlock(&p_lock_data->Mutex);
+    if (pthread_err != 0) {
+       *p_err = KAL_ERR_OS;
+        return;
+    }
+
+   *p_err = KAL_ERR_NONE;
+}
+
+
+void  KAL_LockDel (KAL_LOCK_HANDLE   lock_handle,
+                   KAL_ERR          *p_err)
+{
+    KAL_LOCK  *p_lock_data;
+    int             pthread_err;
+    LIB_ERR         lib_err;
+
+
+    p_lock_data = (KAL_LOCK *)lock_handle.LockObjPtr;
+    if (p_lock_data == DEF_NULL) {
+       *p_err = KAL_ERR_NULL_PTR;
+        return;
+    }
+
+    pthread_err = pthread_mutexattr_destroy(&p_lock_data->MutexAttr);
+    if (pthread_err != 0) {
+        CPU_SW_EXCEPTION(;);
+    }
+
+    pthread_err = pthread_mutex_destroy(&p_lock_data->Mutex);
+    if (pthread_err != 0) {
+        CPU_SW_EXCEPTION(;);
+    }
+
+    Mem_DynPoolBlkFree(&KAL_DataPtr->LockPool, (void *)p_lock_data, &lib_err);
+    if (lib_err != LIB_MEM_ERR_NONE) {
+        CPU_SW_EXCEPTION(;);
+    }
+
+   *p_err = KAL_ERR_NONE;
+}
+
+/*
+*********************************************************************************************************
+*                                          SEM API FUNCTIONS
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*                                          KAL_SemCreate()
+*
+* Description : Create a semaphore.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+KAL_SEM_HANDLE  KAL_SemCreate (const  CPU_CHAR         *p_name,
+                                      KAL_SEM_EXT_CFG  *p_cfg,
+                                      KAL_ERR          *p_err)
+{
+    KAL_SEM_HANDLE   handle = KAL_SemHandleNull;
+    KAL_SEM    *p_sem_data;
+    LIB_ERR          lib_err;
+    int              sem_err;
+
+
+#if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                     /* ---------------- VALIDATE ARGUMENTS ---------------- */
+    if (p_err == DEF_NULL) {                                    /* Validate err ptr.                                    */
+        CPU_SW_EXCEPTION(handle);
+    }
+
+    if (p_cfg != DEF_NULL) {                                    /* Chk for invalid opt flags.                           */
+       *p_err = KAL_ERR_INVALID_ARG;
+        return (handle);
+    }
+#endif
+
+    p_sem_data = (KAL_SEM *)Mem_DynPoolBlkGet(&KAL_DataPtr->SemPool,
+                                                   &lib_err);
+    if (lib_err != LIB_MEM_ERR_NONE) {
+       *p_err = KAL_ERR_MEM_ALLOC;
+        return (handle);
+    }
+
+                                                                /* --------------------- INIT SEM --------------------- */
+    sem_err = sem_init(&p_sem_data->Sem, 0u, 0u);
+    if (sem_err != 0) {
+      *p_err = KAL_ERR_CREATE;
+       Mem_DynPoolBlkFree(&KAL_DataPtr->SemPool, (void *)p_sem_data, &lib_err);
+       if (lib_err != LIB_MEM_ERR_NONE) {
+           CPU_SW_EXCEPTION(handle);
+       }
+       return (handle);
+    }
+
+    handle.SemObjPtr = p_sem_data;
+
+   *p_err = KAL_ERR_NONE;
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                          KAL_SemSizeGet()
+*
+* Description : Get the size of a semaphore.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+CPU_SIZE_T  KAL_SemSizeGet (KAL_SEM_EXT_CFG  *p_cfg,
+                            KAL_ERR          *p_err)
+{
+    *p_err = KAL_ERR_NONE;
+     return (sizeof(KAL_SEM));
+}
+
+
+/*
+*********************************************************************************************************
+*                                            KAL_SemPend()
+*
+* Description : Pend on a semaphore.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPend (KAL_SEM_HANDLE   sem_handle,
+                   KAL_OPT          opt,
+                   CPU_INT32U       timeout,
+                   KAL_ERR         *p_err)
+{
+    KAL_SEM  *p_sem_data;
+    int            sem_err;
+
+
+#if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                     /* ---------------- VALIDATE ARGUMENTS ---------------- */
+    if (p_err == DEF_NULL) {                                    /* Validate err ptr.                                    */
+        CPU_SW_EXCEPTION(DEF_NULL);
+    }
+
+    if (sem_handle.SemObjPtr == DEF_NULL) {                     /* Chk for NULL obj ptr.                                */
+       *p_err = KAL_ERR_NULL_PTR;
+        return;
+    }
+
+    if (opt != 0u) {                                            /* Chk for invalid opt flag.                            */
+       *p_err = KAL_ERR_INVALID_ARG;
+        return;
+    }
+#endif
+
+    p_sem_data = (KAL_SEM *)sem_handle.SemObjPtr;
+
+    if (timeout == 0u) {
+        sem_err = sem_wait(&p_sem_data->Sem);
+        if (sem_err != 0) {
+           *p_err = KAL_ERR_OS;
+            return;
+        }
+    } else {
+        struct  timespec  ts_timeout;
+
+
+        ts_timeout.tv_sec  =  timeout / 1000u;
+        ts_timeout.tv_nsec = (timeout % 1000u) * 1000u;
+
+        sem_err = sem_timedwait(&p_sem_data->Sem, &ts_timeout);
+        if (sem_err != 0) {
+           *p_err = KAL_ERR_OS;
+            return;
+        }
+    }
+
+   *p_err = KAL_ERR_NONE;
+}
+
+
+/*
+*********************************************************************************************************
+*                                            KAL_SemPost()
+*
+* Description : Post a semaphore.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPost (KAL_SEM_HANDLE   sem_handle,
+                   KAL_OPT          opt,
+                   KAL_ERR         *p_err)
+{
+    KAL_SEM  *p_sem_data;
+    int            sem_err;
+
+
+#if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                     /* ---------------- VALIDATE ARGUMENTS ---------------- */
+    if (p_err == DEF_NULL) {                                    /* Validate err ptr.                                    */
+        CPU_SW_EXCEPTION(DEF_NULL);
+    }
+
+    if (sem_handle.SemObjPtr == DEF_NULL) {                     /* Chk for NULL obj ptr.                                */
+       *p_err = KAL_ERR_NULL_PTR;
+        return;
+    }
+
+    if (opt != KAL_OPT_NONE) {                                  /* Chk for invalid opt flags.                           */
+       *p_err = KAL_ERR_INVALID_ARG;
+        return;
+    }
+#endif
+
+    p_sem_data = (KAL_SEM *)sem_handle.SemObjPtr;
+
+    sem_err = sem_post(&p_sem_data->Sem);
+    if (sem_err != 0) {
+       *p_err = KAL_ERR_OS;
+        return;
+    }
+
+   *p_err = KAL_ERR_NONE;
+}
+
+
+/*
+*********************************************************************************************************
+*                                         KAL_SemPendAbort()
+*
+* Description : Abort given semaphore and resume all the tasks pending on it.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPendAbort (KAL_SEM_HANDLE   sem_handle,
+                        KAL_ERR         *p_err)
+{
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                            KAL_SemSet()
+*
+* Description : Set count of given semaphore.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+void  KAL_SemSet (KAL_SEM_HANDLE   sem_handle,
+                  CPU_INT16U       count,
+                  KAL_ERR         *p_err)
+{
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                            KAL_SemDel()
+*
+* Description : Delete given semaphore.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+void  KAL_SemDel (KAL_SEM_HANDLE   sem_handle,
+                  KAL_ERR         *p_err)
+{
+    KAL_SEM  *p_sem_data;
+    int            sem_err;
+    LIB_ERR        err_lib;
+
+
+    p_sem_data = (KAL_SEM *)sem_handle.SemObjPtr;
+
+    sem_err = sem_destroy(&p_sem_data->Sem);
+    if (sem_err != 0) {
+        CPU_SW_EXCEPTION(;);
+    }
+
+    Mem_DynPoolBlkFree(&KAL_DataPtr->SemPool, (void *)p_sem_data, &err_lib);
+    if (err_lib != LIB_MEM_ERR_NONE) {
+        CPU_SW_EXCEPTION(;);
+    }
+
+   *p_err = KAL_ERR_NONE;
+}
+
+
+/*
+*********************************************************************************************************
+*                                          TMR API FUNCTIONS
+*********************************************************************************************************
+*/
+
+KAL_TMR_HANDLE  KAL_TmrCreate (const  CPU_CHAR         *p_name,
+                                      void            (*p_callback)(void *),
+                                      void             *p_callback_arg,
+                                      CPU_INT32U        period_ms,
+                                      KAL_TMR_EXT_CFG  *p_cfg,
+                                      KAL_ERR          *p_err)
+{
+    KAL_TMR_HANDLE  handle = {DEF_NULL};
+
+
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+    return (handle);
+}
+
+
+CPU_SIZE_T  KAL_TmrSizeGet (void            (*p_callback)(void *),
+                            void             *p_callback_arg,
+                            CPU_INT32U        delay_ms,
+                            KAL_TMR_EXT_CFG  *p_cfg,
+                            KAL_ERR          *p_err)
+{
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+    return (0);
+}
+
+
+void  KAL_TmrStart (KAL_TMR_HANDLE   tmr,
+                    KAL_ERR         *p_err)
+{
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                           Q API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                            KAL_QCreate()
+*
+* Description : Create a message queue.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+KAL_Q_HANDLE  KAL_QCreate (const  CPU_CHAR       *p_name,
+                                  KAL_MSG_QTY     max_msg_qty,
+                                  KAL_Q_EXT_CFG  *p_cfg,
+                                  KAL_ERR        *p_err)
+{
+    KAL_Q_HANDLE  handle = {DEF_NULL};
+
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_QSizeGet()
+*
+* Description : Get message queue size.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+CPU_SIZE_T  KAL_QSizeGet (KAL_MSG_QTY     max_msg_qty,
+                          KAL_Q_EXT_CFG  *p_cfg,
+                          KAL_ERR        *p_err)
+{
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+    return (0);
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_QPost()
+*
+* Description : Post message on queue.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+void  KAL_QPost (KAL_Q_HANDLE   q_handle,
+                 void          *p_msg,
+                 KAL_OPT        opt,
+                 KAL_ERR       *p_err)
+{
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_QPend()
+*
+* Description : Pend/get first message of queue.
+*
+* Note(s)     : None.
+*********************************************************************************************************
+*/
+
+void  *KAL_QPend (KAL_Q_HANDLE   q_handle,
+                  KAL_OPT        opt,
+                  CPU_INT32U     timeout,
+                  KAL_ERR       *p_err)
+{
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+    return (DEF_NULL);
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_QDel()
+*
+* Description : Delay current task.
+*
+* Note(s)     : If someone ever wants to implement this function, the KAL_QCreate() function will have
+*               to be modified in order to allocate the Qs from a dynamic memory pool.
+*********************************************************************************************************
+*/
+
+void  KAL_QDel (KAL_Q_HANDLE   q_handle,
+                KAL_ERR       *p_err)
+{
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                          DLY API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                               KAL_Dly()
+*
+* Description : Delay current task.
+*
+* Notes(s)    : None.
+*********************************************************************************************************
+*/
+
+void  KAL_Dly (CPU_INT32U  dly_ms)
+{
+    struct timespec time;
+
+
+    time.tv_sec  = dly_ms/1000;
+    dly_ms      %= 1000u;
+    time.tv_nsec = dly_ms * 1000 * 1000;
+
+    if (nanosleep(&time, DEF_NULL) != 0) {
+        CPU_SW_EXCEPTION(;);
+    }
+}
+
+
+/*
+*********************************************************************************************************
+*                                       TASK REG API FUNCTIONS
+*********************************************************************************************************
+*/
+
+KAL_TASK_REG_HANDLE  KAL_TaskRegCreate (KAL_TASK_REG_EXT_CFG  *p_cfg,
+                                        KAL_ERR               *p_err)
+{
+    KAL_TASK_REG_HANDLE  handle = {DEF_NULL};
+
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+    return (handle);
+}
+
+
+CPU_SIZE_T  KAL_TaskRegSizeGet (KAL_TASK_REG_EXT_CFG  *p_cfg,
+                                KAL_ERR               *p_err)
+{
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+    return (0);
+}
+
+
+CPU_INT32U  KAL_TaskRegGet (KAL_TASK_HANDLE       task_handle,
+                            KAL_TASK_REG_HANDLE   task_reg,
+                            KAL_ERR              *p_err)
+{
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+    return ((CPU_INT32U)-1);
+}
+
+
+void  KAL_TaskRegSet (KAL_TASK_HANDLE       task_handle,
+                      KAL_TASK_REG_HANDLE   task_reg_handle,
+                      CPU_INT32U            value,
+                      KAL_ERR              *p_err)
+{
+   *p_err = KAL_ERR_UNIMPLEMENTED;
+}
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            LOCAL FUNCTIONS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+void  *KAL_TaskFnctWrapper(void  *p_arg)
+{
+    KAL_TASK_FNCT_INFO  *p_fnct_info;
+    void (*fnct)(void *);
+    void  *p_fnct_arg;
+
+
+    p_fnct_info = (KAL_TASK_FNCT_INFO *)p_arg;
+    fnct        = p_fnct_info->Fnct;
+    p_fnct_arg  = p_fnct_info->ArgPtr;
+
+    sem_post(&p_fnct_info->SemInit);
+
+    fnct(p_fnct_arg);
+
+    return (DEF_NULL);
+}
+
+

+ 1001 - 0
KAL/Template/kal.c

@@ -0,0 +1,1001 @@
+/*
+*********************************************************************************************************
+*                                              uC/Common
+*                                 Common Features for Micrium Stacks
+*
+*                    Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
+*
+*                                 SPDX-License-Identifier: APACHE-2.0
+*
+*               This software is subject to an open source license and is distributed by
+*                Silicon Laboratories Inc. pursuant to the terms of the Apache License,
+*                    Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
+*
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*
+*                             uC/Common - Kernel Abstraction Layer (KAL)
+*                                              Template
+*
+* Filename : kal.c
+* Version  : V1.02.00
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                             INCLUDE FILES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#define  MICRIUM_SOURCE
+#define  KAL_MODULE
+
+#include  "../kal.h"
+
+#include  <lib_def.h>
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                             LOCAL DEFINES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            LOCAL CONSTANTS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+KAL_CPP_EXT  const  CPU_INT32U           KAL_Version           =  10000u;
+                                                                /* &&&& OS TICK RATE                            */
+KAL_CPP_EXT  const  KAL_TICK_RATE_HZ     KAL_TickRate          =  0u;
+
+KAL_CPP_EXT  const  KAL_TASK_HANDLE      KAL_TaskHandleNull    = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_LOCK_HANDLE      KAL_LockHandleNull    = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_SEM_HANDLE       KAL_SemHandleNull     = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_TMR_HANDLE       KAL_TmrHandleNull     = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_Q_HANDLE         KAL_QHandleNull       = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_TASK_REG_HANDLE  KAL_TaskRegHandleNull = {DEF_NULL};
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                           LOCAL DATA TYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                              LOCAL TABLES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                         LOCAL GLOBAL VARIABLES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                       LOCAL FUNCTION PROTOTYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                       LOCAL CONFIGURATION ERRORS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            GLOBAL FUNCTIONS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                         KAL CORE API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                              KAL_Init()
+*
+* Description : Initialize the Kernel Abstraction Layer.
+*
+* Argument(s) : p_cfg       Pointer to KAL configuration structure.
+*
+*               p_err       Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : none.
+*
+* Note(s)     : (1) This function must be called prior to any product initialization function if the
+*                   application needs to specify a memory segment.
+*********************************************************************************************************
+*/
+
+void  KAL_Init (KAL_CFG   *p_cfg,
+                RTOS_ERR  *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                          KAL_FeatureQuery()
+*
+* Description : Check if specified feature is available.
+*
+* Argument(s) : feature     Feature to query.
+*
+*               opt         Option associated with the feature requested.
+*
+* Return(s)   : DEF_YES, if feature is available.
+*
+*               DEF_NO,  otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+CPU_BOOLEAN  KAL_FeatureQuery (KAL_FEATURE  feature,
+                               KAL_OPT      opt)
+{
+    CPU_BOOLEAN  is_en;
+
+
+    (void)opt;
+
+    is_en = DEF_NO;
+
+    switch (feature) {
+        case KAL_FEATURE_TASK_CREATE:                           /* ---------------------- TASKS ----------------------- */
+        case KAL_FEATURE_TASK_DEL:
+             break;
+
+
+        case KAL_FEATURE_LOCK_CREATE:                           /* ---------------------- LOCKS ----------------------- */
+        case KAL_FEATURE_LOCK_ACQUIRE:
+        case KAL_FEATURE_LOCK_RELEASE:
+        case KAL_FEATURE_LOCK_DEL:
+             break;
+
+
+        case KAL_FEATURE_SEM_CREATE:                            /* ----------------------- SEMS ----------------------- */
+        case KAL_FEATURE_SEM_DEL:
+        case KAL_FEATURE_SEM_PEND:
+        case KAL_FEATURE_SEM_POST:
+        case KAL_FEATURE_SEM_ABORT:
+        case KAL_FEATURE_SEM_SET:
+             break;
+
+
+        case KAL_FEATURE_Q_CREATE:                              /* ---------------------- QUEUES ---------------------- */
+        case KAL_FEATURE_Q_POST:
+        case KAL_FEATURE_Q_PEND:
+             break;
+
+
+        case KAL_FEATURE_DLY:                                   /* ----------------------- DLYS ----------------------- */
+             break;
+
+
+        case KAL_FEATURE_TASK_REG:                              /* --------------------- TASK REGS -------------------- */
+             break;
+
+
+        case KAL_FEATURE_TICK_GET:                              /* ------------------- TICK CTR INFO ------------------ */
+             break;
+
+
+        default:
+             break;
+    }
+
+    return (is_en);
+}
+
+
+/*
+*********************************************************************************************************
+*                                         TASK API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                            KAL_TaskAlloc()
+*
+* Description : Allocate a task object and its stack.
+*
+* Argument(s) : p_name          Pointer to name of the task.
+*
+*               p_stk_base      Pointer to start of task stack. If NULL, the stack will be allocated from
+*                               the KAL memory segment.
+*
+*               stk_size_bytes  Size (in bytes) of the task stack.
+*
+*               p_cfg           Pointer to KAL task configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : Allocated task's handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TASK_HANDLE  KAL_TaskAlloc (const  CPU_CHAR          *p_name,
+                                       void              *p_stk_base,
+                                       CPU_SIZE_T         stk_size_bytes,
+                                       KAL_TASK_EXT_CFG  *p_cfg,
+                                       RTOS_ERR          *p_err)
+{
+    KAL_TASK_HANDLE  handle = KAL_TaskHandleNull;
+
+
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_TaskCreate()
+*
+* Description : Create and start a task.
+*
+* Argument(s) : task_handle     Handle of the task to create.
+*
+*               p_fnct          Pointer to task function.
+*
+*               p_task_arg      Pointer to argument that will be passed to task function (can be DEF_NULL).
+*
+*               prio            Task priority.
+*
+*               p_cfg           Pointer to KAL task configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+* Return(s)   : none.
+*
+* Note(s)     : (1) The task must be allocated prior to this call using KAL_TaskAlloc().
+*********************************************************************************************************
+*/
+
+void  KAL_TaskCreate (KAL_TASK_HANDLE     task_handle,
+                      void              (*p_fnct)(void  *p_arg),
+                      void               *p_task_arg,
+                      CPU_INT08U          prio,
+                      KAL_TASK_EXT_CFG   *p_cfg,
+                      RTOS_ERR           *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_TaskDel()
+*
+* Description : Delete a task.
+*
+* Argument(s) : task_handle     Handle of the task to delete.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_TaskDel (KAL_TASK_HANDLE   task_handle,
+                   RTOS_ERR         *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                         LOCK API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                           KAL_LockCreate()
+*
+* Description : Create a lock, which is unlocked by default.
+*
+* Argument(s) : p_name          Pointer to name of the lock.
+*
+*               p_cfg           Pointer to KAL lock configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : Created lock handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_LOCK_HANDLE  KAL_LockCreate (const  CPU_CHAR          *p_name,
+                                        KAL_LOCK_EXT_CFG  *p_cfg,
+                                        RTOS_ERR          *p_err)
+{
+    KAL_LOCK_HANDLE  handle = KAL_LockHandleNull;
+
+
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_LockAcquire()
+*
+* Description : Acquire a lock.
+*
+* Argument(s) : lock_handle     Handle of the lock to acquire.
+*
+*               opt             Options available:
+*                                   KAL_OPT_PEND_NONE:          block until timeout expires or lock is available.
+*                                   KAL_OPT_PEND_BLOCKING:      block until timeout expires or lock is available.
+*                                   KAL_OPT_PEND_NON_BLOCKING:  return immediately even if lock is not available.
+*
+*               timeout_ms      Timeout, in milliseconds. A value of 0 will never timeout.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_LockAcquire (KAL_LOCK_HANDLE   lock_handle,
+                       KAL_OPT           opt,
+                       CPU_INT32U        timeout_ms,
+                       RTOS_ERR         *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_LockRelease()
+*
+* Description : Release a lock.
+*
+* Argument(s) : lock_handle     Handle of the lock to release.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_LockRelease (KAL_LOCK_HANDLE   lock_handle,
+                       RTOS_ERR         *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_LockDel()
+*
+* Description : Delete a lock.
+*
+* Argument(s) : lock_handle     Handle of the lock to delete.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_LockDel (KAL_LOCK_HANDLE   lock_handle,
+                   RTOS_ERR         *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                          SEM API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                            KAL_SemCreate()
+*
+* Description : Create a semaphore, with a count of 0.
+*
+* Argument(s) : p_name          Pointer to name of the semaphore.
+*
+*               p_cfg           Pointer to KAL semaphore configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : Created semaphore's handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_SEM_HANDLE  KAL_SemCreate (const  CPU_CHAR         *p_name,
+                                      KAL_SEM_EXT_CFG  *p_cfg,
+                                      RTOS_ERR         *p_err)
+{
+    KAL_SEM_HANDLE  handle = KAL_SemHandleNull;
+
+
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemPend()
+*
+* Description : Pend on a semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to pend on.
+*
+*               opt             Options available:
+*                                   KAL_OPT_PEND_NONE:          block until timeout expires or semaphore is available.
+*                                   KAL_OPT_PEND_BLOCKING:      block until timeout expires or semaphore is available.
+*                                   KAL_OPT_PEND_NON_BLOCKING:  return immediately even if semaphore is not available.
+*
+*               timeout_ms      Timeout, in milliseconds. A value of 0 will never timeout.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPend (KAL_SEM_HANDLE   sem_handle,
+                   KAL_OPT          opt,
+                   CPU_INT32U       timeout_ms,
+                   RTOS_ERR        *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemPost()
+*
+* Description : Post a semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to post.
+*
+*               opt             Options available:
+*                                   KAL_OPT_POST_NONE:     wake only the highest priority task pending on semaphore.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPost (KAL_SEM_HANDLE   sem_handle,
+                   KAL_OPT          opt,
+                   RTOS_ERR        *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                          KAL_SemPendAbort()
+*
+* Description : Abort given semaphore and resume all the tasks pending on it.
+*
+* Argument(s) : sem_handle      Handle of the sempahore to abort.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPendAbort (KAL_SEM_HANDLE   sem_handle,
+                        RTOS_ERR        *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemSet()
+*
+* Description : Set value of semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to set.
+*
+*               cnt             Count value to set semaphore.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemSet (KAL_SEM_HANDLE   sem_handle,
+                  CPU_INT16U       cnt,
+                  RTOS_ERR        *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemDel()
+*
+* Description : Delete a semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to delete.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemDel (KAL_SEM_HANDLE   sem_handle,
+                  RTOS_ERR        *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                          TMR API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                            KAL_TmrCreate()
+*
+* Description : Create a single-shot timer.
+*
+* Argument(s) : p_name          Pointer to name of the timer.
+*
+*               p_callback      Pointer to the callback function that will be called on completion of timer.
+*
+*               p_callback_arg  Argument passed to callback function.
+*
+*               interval_ms     If timer is 'one-shot', delay  used by the timer, in milliseconds.
+*                               If timer is 'periodic', period used by the timer, in milliseconds.
+*
+*               p_cfg           Pointer to KAL timer configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : Created timer handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TMR_HANDLE  KAL_TmrCreate (const  CPU_CHAR   *p_name,
+                               void             (*p_callback)(void  *p_arg),
+                               void              *p_callback_arg,
+                               CPU_INT32U         interval_ms,
+                               KAL_TMR_EXT_CFG   *p_cfg,
+                               RTOS_ERR          *p_err)
+{
+    KAL_TMR_HANDLE  handle = KAL_TmrHandleNull;
+
+
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                            KAL_TmrStart()
+*
+* Description : Start timer.
+*
+* Argument(s) : tmr_handle      Handle of timer to start.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_TmrStart (KAL_TMR_HANDLE   tmr_handle,
+                    RTOS_ERR        *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                           Q API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                             KAL_QCreate()
+*
+* Description : Create an empty queue.
+*
+* Argument(s) : p_name          Pointer to name of the queue.
+*
+*               max_msg_qty     Maximum number of message contained in the queue.
+*
+*               p_cfg           Pointer to KAL queue configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : Created queue handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_Q_HANDLE  KAL_QCreate (const  CPU_CHAR       *p_name,
+                                  KAL_MSG_QTY     max_msg_qty,
+                                  KAL_Q_EXT_CFG  *p_cfg,
+                                  RTOS_ERR       *p_err)
+{
+    KAL_Q_HANDLE  handle = KAL_QHandleNull;
+
+
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                              KAL_QPend()
+*
+* Description : Pend/get first message of queue.
+*
+* Argument(s) : q_handle        Handle of the queue to pend on.
+*
+*               opt             Options available:
+*                                   KAL_OPT_PEND_NONE:          block until timeout expires or message is available.
+*                                   KAL_OPT_PEND_BLOCKING:      block until timeout expires or message is available.
+*                                   KAL_OPT_PEND_NON_BLOCKING:  return immediately with or without message.
+*
+*               timeout_ms      Timeout, in milliseconds. A value of 0 will never timeout.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : Pointer to message obtained, if any, if no error.
+*
+*               Null pointer,                        otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  *KAL_QPend (KAL_Q_HANDLE   q_handle,
+                  KAL_OPT        opt,
+                  CPU_INT32U     timeout_ms,
+                  RTOS_ERR      *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+    return (DEF_NULL);
+}
+
+
+/*
+*********************************************************************************************************
+*                                              KAL_QPost()
+*
+* Description : Post message on queue.
+*
+* Argument(s) : q_handle        Handle of the queue on which to post message.
+*
+*               p_msg           Pointer to message to post.
+*
+*               opt             Options available:
+*                                   KAL_OPT_POST_NONE:     wake only the highest priority task pending on queue.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_QPost (KAL_Q_HANDLE   q_handle,
+                 void          *p_msg,
+                 KAL_OPT        opt,
+                 RTOS_ERR      *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+}
+
+
+/*
+*********************************************************************************************************
+*                                          DLY API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                               KAL_Dly()
+*
+* Description : Delay current task (in milliseconds).
+*
+* Argument(s) : dly_ms          Delay value, in milliseconds.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_Dly (CPU_INT32U  dly_ms)
+{
+
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_DlyTick()
+*
+* Description : Delay current task (in ticks).
+*
+* Argument(s) : dly_ticks       Delay value, in ticks.
+*
+*               opt             Options available:
+*                                   KAL_OPT_DLY_NONE:       apply a 'normal' delay.
+*                                   KAL_OPT_DLY:            apply a 'normal' delay.
+*                                   KAL_OPT_DLY_PERIODIC:   apply a periodic delay.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_DlyTick (KAL_TICK  dly_ticks,
+                   KAL_OPT   opt)
+{
+
+}
+
+
+/*
+*********************************************************************************************************
+*                                       TASK REG API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                          KAL_TaskRegCreate()
+*
+* Description : Create a task register.
+*
+* Argument(s) : p_cfg           Pointer to KAL task register configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : Created task register's handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TASK_REG_HANDLE  KAL_TaskRegCreate (KAL_TASK_REG_EXT_CFG  *p_cfg,
+                                        RTOS_ERR              *p_err)
+{
+    KAL_TASK_REG_HANDLE  handle = KAL_TaskRegHandleNull;
+
+
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_TickGet()
+*
+* Description : Get value of OS' tick counter.
+*
+* Argument(s) : p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : OS tick counter's value.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TICK  KAL_TickGet (RTOS_ERR *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+    return (0u);
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_TaskRegGet()
+*
+* Description : Get value from a task register.
+*
+* Argument(s) : task_handle     Handle of the task associated to the task register. Current task is used if NULL.
+*
+*               task_reg_handle Handle of the task register to read.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : Value read from the task register, if no error.
+*               0,                                 otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+CPU_INT32U  KAL_TaskRegGet (KAL_TASK_HANDLE       task_handle,
+                            KAL_TASK_REG_HANDLE   task_reg_handle,
+                            RTOS_ERR             *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+    return (0u);
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_TaskRegSet()
+*
+* Description : Set value of task register.
+*
+* Argument(s) : task_handle     Handle of the task associated to the task register. Current task is used if NULL.
+*
+*               task_reg_handle Handle of the task register to write to.
+*
+*               val             Value to write in the task register.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NOT_SUPPORTED      Function not implemented.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_TaskRegSet (KAL_TASK_HANDLE       task_handle,
+                      KAL_TASK_REG_HANDLE   task_reg_handle,
+                      CPU_INT32U            val,
+                      RTOS_ERR             *p_err)
+{
+   *p_err = RTOS_ERR_NOT_SUPPORTED;
+}
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            LOCAL FUNCTIONS
+*********************************************************************************************************
+*********************************************************************************************************
+*/

+ 559 - 0
KAL/kal.h

@@ -0,0 +1,559 @@
+/*
+*********************************************************************************************************
+*                                              uC/Common
+*                                 Common Features for Micrium Stacks
+*
+*                    Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
+*
+*                                 SPDX-License-Identifier: APACHE-2.0
+*
+*               This software is subject to an open source license and is distributed by
+*                Silicon Laboratories Inc. pursuant to the terms of the Apache License,
+*                    Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
+*
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*
+*                             uC/Common - Kernel Abstraction Layer (KAL)
+*
+* Filename : kal.h
+* Version  : V1.02.00
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                               MODULE
+*
+* Note(s) : (1) This library header file is protected from multiple pre-processor inclusion through
+*               use of the library module present pre-processor macro definition.
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#ifndef  KAL_MODULE_PRESENT                                     /* See Note #1.                                         */
+#define  KAL_MODULE_PRESENT
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            INCLUDE FILES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#include  <cpu.h>
+#include  <lib_def.h>
+#include  <lib_mem.h>
+#include  "../common_err.h"
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                               EXTERNS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#ifdef   KAL_MODULE
+#define  KAL_EXT
+#else
+#define  KAL_EXT  extern
+#endif
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                        CONFIGURATION ERRORS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#if (LIB_VERSION < 13800)
+#error  "KAL requires LIB_VERSION (defined in lib_def.h) 1.38.00 or higher to function properly."
+#endif
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                                DEFINES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                                GENERAL
+*********************************************************************************************************
+*/
+
+#define  KAL_TIMEOUT_INFINITE                  0u
+
+#define  KAL_OPT_NONE                           DEF_BIT_NONE
+
+
+/*
+*********************************************************************************************************
+*                                        CREATE OPTS (LOCK ONLY)
+*********************************************************************************************************
+*/
+
+#define  KAL_OPT_CREATE_NONE           (KAL_OPT)KAL_OPT_NONE
+
+#define  KAL_OPT_CREATE_NON_REENTRANT           KAL_OPT_NONE    /* Create non-re-entrant lock.                          */
+#define  KAL_OPT_CREATE_REENTRANT      (KAL_OPT)DEF_BIT_00      /* Create     re-entrant lock.                          */
+
+
+/*
+*********************************************************************************************************
+*                                       PEND OPTS (LOCK, SEM, Q)
+*********************************************************************************************************
+*/
+
+#define  KAL_OPT_PEND_NONE             (KAL_OPT)KAL_OPT_NONE
+
+#define  KAL_OPT_PEND_BLOCKING                  KAL_OPT_NONE    /* Block until rsrc is avail.                           */
+#define  KAL_OPT_PEND_NON_BLOCKING     (KAL_OPT)DEF_BIT_00      /* Don't block if rsrc is unavail.                      */
+
+
+/*
+*********************************************************************************************************
+*                                       POST OPTS (LOCK, SEM, Q)
+*********************************************************************************************************
+*/
+
+#define  KAL_OPT_POST_NONE                      KAL_OPT_NONE
+
+
+/*
+*********************************************************************************************************
+*                                        ABORT OPTS (LOCK, SEM)
+*********************************************************************************************************
+*/
+
+#define  KAL_OPT_ABORT_NONE                     KAL_OPT_NONE
+
+
+/*
+*********************************************************************************************************
+*                                      DELETE OPTS (LOCK, SEM, Q)
+*********************************************************************************************************
+*/
+
+#define  KAL_OPT_DEL_NONE                       KAL_OPT_NONE
+
+
+/*
+*********************************************************************************************************
+*                                               TMR OPTS
+*********************************************************************************************************
+*/
+
+#define  KAL_OPT_TMR_NONE              (KAL_OPT)KAL_OPT_NONE
+
+#define  KAL_OPT_TMR_ONE_SHOT                   KAL_OPT_NONE    /* One-shot tmr,   callback called only once.           */
+#define  KAL_OPT_TMR_PERIODIC          (KAL_OPT)DEF_BIT_00      /* Periodic timer, callback called periodically.        */
+
+
+/*
+*********************************************************************************************************
+*                                               DLY OPTS
+*********************************************************************************************************
+*/
+
+#define  KAL_OPT_DLY_NONE                       KAL_OPT_NONE
+
+#define  KAL_OPT_DLY                            KAL_OPT_NONE    /* 'Normal' delay.                                      */
+#define  KAL_OPT_DLY_PERIODIC                   DEF_BIT_00      /* Periodic delay.                                      */
+
+
+/*
+*********************************************************************************************************
+*                                      LEGACY ERROR CODES
+*
+* Note(s) : (1) These error codes are deprecated and will be removed in a future version. Please use the
+*               codes from RTOS_ERR instead, located in common_err.h
+*********************************************************************************************************
+*/
+
+#define  KAL_ERR_NONE               RTOS_ERR_NONE
+
+#define  KAL_ERR_NOT_AVAIL          RTOS_ERR_NOT_AVAIL
+#define  KAL_ERR_UNIMPLEMENTED      RTOS_ERR_NOT_SUPPORTED
+#define  KAL_ERR_INVALID_ARG        RTOS_ERR_INVALID_ARG
+#define  KAL_ERR_NULL_PTR           RTOS_ERR_NULL_PTR
+#define  KAL_ERR_OS                 RTOS_ERR_OS
+
+#define  KAL_ERR_ALREADY_INIT       RTOS_ERR_ALREADY_INIT
+#define  KAL_ERR_MEM_ALLOC          RTOS_ERR_ALLOC
+#define  KAL_ERR_POOL_INIT          RTOS_ERR_INIT
+#define  KAL_ERR_CREATE             RTOS_ERR_CREATE_FAIL
+#define  KAL_ERR_TIMEOUT            RTOS_ERR_TIMEOUT
+#define  KAL_ERR_ABORT              RTOS_ERR_ABORT
+#define  KAL_ERR_WOULD_BLOCK        RTOS_ERR_WOULD_BLOCK
+#define  KAL_ERR_ISR                RTOS_ERR_ISR
+#define  KAL_ERR_OVF                RTOS_ERR_WOULD_OVF
+#define  KAL_ERR_RSRC               RTOS_ERR_NO_MORE_RSRC
+
+#define  KAL_ERR_LOCK_OWNER         RTOS_ERR_OWNERSHIP
+
+
+/*
+*********************************************************************************************************
+*                                      LANGUAGE SUPPORT DEFINES
+*********************************************************************************************************
+*/
+
+#ifdef  __cplusplus
+#define  KAL_CPP_EXT  extern
+#else
+#define  KAL_CPP_EXT
+#endif
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                             DATA TYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                                GENERAL
+*********************************************************************************************************
+*/
+
+typedef  CPU_INT32U  KAL_TICK;
+typedef  CPU_INT32U  KAL_TICK_RATE_HZ;
+
+typedef  CPU_INT16U  KAL_MSG_QTY;
+
+typedef  CPU_INT08U  KAL_OPT;
+
+                                                                /* !!!! This type is deprecated and will be removed ... */
+typedef  RTOS_ERR    KAL_ERR;                                   /* ... a future version. Use RTOS_ERR instead.          */
+
+
+/*
+*********************************************************************************************************
+*                                              OBJ HANDLES
+*********************************************************************************************************
+*/
+
+typedef  struct  kal_task_handle {                              /* -------------------- TASK HANDLE ------------------- */
+    void  *TaskObjPtr;
+} KAL_TASK_HANDLE;
+
+typedef  struct  kal_lock_handle {                              /* -------------------- LOCK HANDLE ------------------- */
+    void  *LockObjPtr;
+} KAL_LOCK_HANDLE;
+
+typedef  struct  kal_sem_handle {                               /* -------------------- SEM HANDLE -------------------- */
+    void  *SemObjPtr;
+} KAL_SEM_HANDLE;
+
+typedef  struct  kal_q_handle {                                 /* --------------------- Q HANDLE --------------------- */
+    void  *QObjPtr;
+} KAL_Q_HANDLE;
+
+typedef  struct  kal_tmr_handle {                               /* -------------------- TMR HANDLE -------------------- */
+    void  *TmrObjPtr;
+} KAL_TMR_HANDLE;
+
+typedef  struct  kal_task_reg_handle {                          /* ------------------ TASK REG HANDLE ----------------- */
+    void  *TaskRegObjPtr;
+} KAL_TASK_REG_HANDLE;
+
+
+/*
+*********************************************************************************************************
+*                                              CFG STRUCTS
+*********************************************************************************************************
+*/
+
+typedef  struct  kal_cfg {                                      /* ---------------------- GEN CFG --------------------- */
+    MEM_SEG     *MemSegPtr;                                     /* Mem seg to use for alloc.                            */
+} KAL_CFG;
+
+typedef  struct  kal_task_ext_cfg {                             /* ------------------- TASK EXT CFG ------------------- */
+    CPU_INT32U   Rsvd;                                          /* Rsvd for future use.                                 */
+} KAL_TASK_EXT_CFG;
+
+typedef  struct  kal_lock_ext_cfg {                             /* ------------------- LOCK EXT CFG ------------------- */
+    KAL_OPT      Opt;                                           /* Opt passed to LockCreate() funct.                    */
+} KAL_LOCK_EXT_CFG;
+
+typedef  struct  kal_sem_ext_cfg {                              /* -------------------- SEM EXT CFG ------------------- */
+    CPU_INT32U   Rsvd;                                          /* Rsvd for future use.                                 */
+} KAL_SEM_EXT_CFG;
+
+typedef  struct  kal_q_ext_cfg {                                /* --------------------- Q EXT CFG -------------------- */
+    CPU_INT32U   Rsvd;                                          /* Rsvd for future use.                                 */
+} KAL_Q_EXT_CFG;
+
+typedef  struct  kal_tmr_ext_cfg {                              /* -------------------- TMR EXT CFG ------------------- */
+    KAL_OPT      Opt;                                           /* Opt passed to TmrCreate() funct.                     */
+} KAL_TMR_EXT_CFG;
+
+typedef  struct  kal_task_reg_ext_cfg {                         /* ----------------- TASK REG EXT CFG ----------------- */
+    CPU_INT32U   Rsvd;                                          /* Rsvd for future use.                                 */
+} KAL_TASK_REG_EXT_CFG;
+
+
+/*
+*********************************************************************************************************
+*                                            KAL FEATURES
+*********************************************************************************************************
+*/
+
+typedef  enum  kal_feature {
+    KAL_FEATURE_TASK_CREATE = 0u,                               /* Task creation.                                       */
+    KAL_FEATURE_TASK_DEL,                                       /* Task del.                                            */
+
+    KAL_FEATURE_LOCK_CREATE,                                    /* Lock create, acquire and release.                    */
+    KAL_FEATURE_LOCK_ACQUIRE,                                   /* Lock pend.                                           */
+    KAL_FEATURE_LOCK_RELEASE,                                   /* Lock post.                                           */
+    KAL_FEATURE_LOCK_DEL,                                       /* Lock del.                                            */
+
+    KAL_FEATURE_SEM_CREATE,                                     /* Sem creation.                                        */
+    KAL_FEATURE_SEM_PEND,                                       /* Sem pend.                                            */
+    KAL_FEATURE_SEM_POST,                                       /* Sem post.                                            */
+    KAL_FEATURE_SEM_ABORT,                                      /* Sem pend abort.                                      */
+    KAL_FEATURE_SEM_SET,                                        /* Sem set cnt.                                         */
+    KAL_FEATURE_SEM_DEL,                                        /* Sem del.                                             */
+
+    KAL_FEATURE_TMR,                                            /* Tmr creation and exec.                               */
+
+    KAL_FEATURE_Q_CREATE,                                       /* Q creation.                                          */
+    KAL_FEATURE_Q_POST,                                         /* Q post.                                              */
+    KAL_FEATURE_Q_PEND,                                         /* Q pend.                                              */
+
+    KAL_FEATURE_DLY,                                            /* Dly in both ms and ticks.                            */
+
+    KAL_FEATURE_TASK_REG,                                       /* Task storage creation, get and set.                  */
+
+    KAL_FEATURE_TICK_GET                                        /* Get OS tick val.                                     */
+} KAL_FEATURE;
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                          GLOBAL CONSTANTS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+extern  const  CPU_INT32U           KAL_Version;                /* KAL version.                                         */
+extern  const  KAL_TICK_RATE_HZ     KAL_TickRate;               /* Tick rate.                                           */
+
+                                                                /* ------------------- NULL HANDLES ------------------- */
+extern  const  KAL_TASK_HANDLE      KAL_TaskHandleNull;
+extern  const  KAL_LOCK_HANDLE      KAL_LockHandleNull;
+extern  const  KAL_SEM_HANDLE       KAL_SemHandleNull;
+extern  const  KAL_Q_HANDLE         KAL_QHandleNull;
+extern  const  KAL_TASK_REG_HANDLE  KAL_TaskRegHandleNull;
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                               MACROS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#define  KAL_TASK_HANDLE_IS_NULL(task_handle)            (((task_handle).TaskObjPtr        == KAL_TaskHandleNull.TaskObjPtr)       ? DEF_YES : DEF_NO)
+#define  KAL_LOCK_HANDLE_IS_NULL(lock_handle)            (((lock_handle).LockObjPtr        == KAL_LockHandleNull.LockObjPtr)       ? DEF_YES : DEF_NO)
+#define  KAL_SEM_HANDLE_IS_NULL(sem_handle)              (((sem_handle).SemObjPtr          == KAL_SemHandleNull.SemObjPtr)         ? DEF_YES : DEF_NO)
+#define  KAL_Q_HANDLE_IS_NULL(q_handle)                  (((q_handle).QObjPtr              == KAL_QHandleNull.QObjPtr)             ? DEF_YES : DEF_NO)
+#define  KAL_TMR_HANDLE_IS_NULL(tmr_handle)              (((tmr_handle).TmrObjPtr          == KAL_TmrHandleNull.TmrObjPtr)         ? DEF_YES : DEF_NO)
+#define  KAL_TASK_REG_HANDLE_IS_NULL(task_reg_handle)    (((task_reg_handle).TaskRegObjPtr == KAL_TaskRegHandleNull.TaskRegObjPtr) ? DEF_YES : DEF_NO)
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                         FUNCTION PROTOTYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                                 CORE
+*********************************************************************************************************
+*/
+
+void                  KAL_Init         (      KAL_CFG                *p_cfg,
+                                              RTOS_ERR               *p_err);
+
+CPU_BOOLEAN           KAL_FeatureQuery (      KAL_FEATURE             feature,
+                                              KAL_OPT                 opt);
+
+
+/*
+*********************************************************************************************************
+*                                                 TASKS
+*********************************************************************************************************
+*/
+
+KAL_TASK_HANDLE       KAL_TaskAlloc    (const CPU_CHAR               *p_name,
+                                              void                   *p_stk_base,
+                                              CPU_SIZE_T              stk_size_bytes,
+                                              KAL_TASK_EXT_CFG       *p_cfg,
+                                              RTOS_ERR               *p_err);
+
+void                  KAL_TaskCreate   (      KAL_TASK_HANDLE         task_handle,
+                                              void                  (*p_fnct)(void  *p_arg),
+                                              void                   *p_task_arg,
+                                              CPU_INT08U              prio,
+                                              KAL_TASK_EXT_CFG       *p_cfg,
+                                              RTOS_ERR               *p_err);
+
+void                  KAL_TaskDel      (      KAL_TASK_HANDLE         task_handle,
+                                              RTOS_ERR               *p_err);
+
+
+/*
+*********************************************************************************************************
+*                                                 LOCKS
+*********************************************************************************************************
+*/
+
+KAL_LOCK_HANDLE       KAL_LockCreate   (const CPU_CHAR               *p_name,
+                                              KAL_LOCK_EXT_CFG       *p_cfg,
+                                              RTOS_ERR               *p_err);
+
+void                  KAL_LockAcquire  (      KAL_LOCK_HANDLE         lock_handle,
+                                              KAL_OPT                 opt,
+                                              CPU_INT32U              timeout,
+                                              RTOS_ERR               *p_err);
+
+void                  KAL_LockRelease  (      KAL_LOCK_HANDLE         lock_handle,
+                                              RTOS_ERR               *p_err);
+
+void                  KAL_LockDel      (      KAL_LOCK_HANDLE         lock_handle,
+                                              RTOS_ERR               *p_err);
+
+
+/*
+*********************************************************************************************************
+*                                                 SEMS
+*********************************************************************************************************
+*/
+
+KAL_SEM_HANDLE        KAL_SemCreate    (const CPU_CHAR               *p_name,
+                                              KAL_SEM_EXT_CFG        *p_cfg,
+                                              RTOS_ERR               *p_err);
+
+void                  KAL_SemPend      (      KAL_SEM_HANDLE          sem_handle,
+                                              KAL_OPT                 opt,
+                                              CPU_INT32U              timeout,
+                                              RTOS_ERR               *p_err);
+
+void                  KAL_SemPost      (      KAL_SEM_HANDLE          sem_handle,
+                                              KAL_OPT                 opt,
+                                              RTOS_ERR               *p_err);
+
+void                  KAL_SemPendAbort (      KAL_SEM_HANDLE          sem_handle,
+                                              RTOS_ERR               *p_err);
+
+void                  KAL_SemSet       (      KAL_SEM_HANDLE          sem_handle,
+                                              CPU_INT16U              cnt,
+                                              RTOS_ERR               *p_err);
+
+void                  KAL_SemDel       (      KAL_SEM_HANDLE          sem_handle,
+                                              RTOS_ERR               *p_err);
+
+
+/*
+*********************************************************************************************************
+*                                                 TMRS
+*********************************************************************************************************
+*/
+
+KAL_TMR_HANDLE        KAL_TmrCreate    (const CPU_CHAR               *p_name,
+                                              void                  (*p_callback)(void  *p_arg),
+                                              void                   *p_callback_arg,
+                                              CPU_INT32U              interval_ms,
+                                              KAL_TMR_EXT_CFG        *p_cfg,
+                                              RTOS_ERR               *p_err);
+
+void                  KAL_TmrStart     (      KAL_TMR_HANDLE          tmr_handle,
+                                              RTOS_ERR               *p_err);
+
+
+/*
+*********************************************************************************************************
+*                                                  QS
+*********************************************************************************************************
+*/
+
+KAL_Q_HANDLE          KAL_QCreate      (const CPU_CHAR               *p_name,
+                                              KAL_MSG_QTY             max_msg_qty,
+                                              KAL_Q_EXT_CFG          *p_cfg,
+                                              RTOS_ERR               *p_err);
+
+void                 *KAL_QPend        (      KAL_Q_HANDLE            q_handle,
+                                              KAL_OPT                 opt,
+                                              CPU_INT32U              timeout,
+                                              RTOS_ERR               *p_err);
+
+void                  KAL_QPost        (      KAL_Q_HANDLE            q_handle,
+                                              void                   *p_msg,
+                                              KAL_OPT                 opt,
+                                              RTOS_ERR               *p_err);
+
+
+/*
+*********************************************************************************************************
+*                                                 DLYS
+*********************************************************************************************************
+*/
+
+void                  KAL_Dly          (      CPU_INT32U              dly_ms);
+
+void                  KAL_DlyTick      (      KAL_TICK                dly_tick,
+                                              KAL_OPT                 opt);
+
+
+/*
+*********************************************************************************************************
+*                                               TASK REGS
+*********************************************************************************************************
+*/
+
+KAL_TASK_REG_HANDLE   KAL_TaskRegCreate(      KAL_TASK_REG_EXT_CFG   *p_cfg,
+                                              RTOS_ERR               *p_err);
+
+CPU_INT32U            KAL_TaskRegGet   (      KAL_TASK_HANDLE         task_handle,
+                                              KAL_TASK_REG_HANDLE     task_reg,
+                                              RTOS_ERR               *p_err);
+
+void                  KAL_TaskRegSet   (      KAL_TASK_HANDLE         task_handle,
+                                              KAL_TASK_REG_HANDLE     task_reg_handle,
+                                              CPU_INT32U              val,
+                                              RTOS_ERR               *p_err);
+
+
+/*
+*********************************************************************************************************
+*                                               TICK CTR
+*********************************************************************************************************
+*/
+
+KAL_TICK              KAL_TickGet      (      RTOS_ERR               *p_err);
+
+#endif /* KAL_MODULE_PRESENT */
+

+ 2743 - 0
KAL/uCOS-II/kal.c

@@ -0,0 +1,2743 @@
+/*
+*********************************************************************************************************
+*                                              uC/Common
+*                                 Common Features for Micrium Stacks
+*
+*                    Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
+*
+*                                 SPDX-License-Identifier: APACHE-2.0
+*
+*               This software is subject to an open source license and is distributed by
+*                Silicon Laboratories Inc. pursuant to the terms of the Apache License,
+*                    Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
+*
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*
+*                             uC/Common - Kernel Abstraction Layer (KAL)
+*                                               uCOS-II
+*
+* Filename : kal.c
+* Version  : V1.02.00
+*********************************************************************************************************
+* Note(s)  : (1) 'goto' statements were used in this software module. Their usage
+*                is restricted to cleanup purposes in exceptional program flow (e.g.
+*                error handling), in compliance with CERT MEM12-C and MISRA C:2012
+*                rules 15.2, 15.3 and 15.4.
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                             INCLUDE FILES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#define  MICRIUM_SOURCE
+#define  KAL_MODULE
+
+#include  "../kal.h"
+#include  <lib_math.h>
+#include  <lib_mem.h>
+#include  <os_cfg.h>
+#include  <Source/ucos_ii.h>
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                             LOCAL DEFINES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#define  KAL_CFG_ARG_CHK_EXT_EN                 OS_ARG_CHK_EN
+
+#define  KAL_LOCK_OWNER_PRIO_NONE              (OS_LOWEST_PRIO + 1u)
+
+#define  KAL_INIT_STATUS_NONE                   0u
+#define  KAL_INIT_STATUS_OK                     1u
+#define  KAL_INIT_STATUS_FAIL                   2u
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            LOCAL CONSTANTS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+KAL_CPP_EXT  const  CPU_INT32U           KAL_Version           =  10000u;
+KAL_CPP_EXT  const  KAL_TICK_RATE_HZ     KAL_TickRate          =  OS_TICKS_PER_SEC;
+
+KAL_CPP_EXT  const  KAL_TASK_HANDLE      KAL_TaskHandleNull    = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_LOCK_HANDLE      KAL_LockHandleNull    = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_SEM_HANDLE       KAL_SemHandleNull     = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_TMR_HANDLE       KAL_TmrHandleNull     = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_Q_HANDLE         KAL_QHandleNull       = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_TASK_REG_HANDLE  KAL_TaskRegHandleNull = {DEF_NULL};
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                           LOCAL DATA TYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+                                                                /* ------------------ KAL TASK TYPE ------------------- */
+typedef  struct  kal_task {
+           CPU_STK     *StkBasePtr;                             /* Task stack base ptr.                                 */
+           CPU_INT32U   StkSizeBytes;                           /* Task stack size (in bytes).                          */
+
+           CPU_INT08U   Prio;                                   /* Task prio.                                           */
+#if (OS_TASK_NAME_EN == DEF_ENABLED)                            /* Check if task name is en.                            */
+    const  CPU_CHAR    *NamePtr;                                /* Task name string.                                    */
+#endif
+} KAL_TASK;
+
+                                                                /* ------------------- KAL LOCK TYPE ------------------ */
+typedef  struct  kal_lock {
+    OS_EVENT    *SemEventPtr;                                   /* Pointer to an OS_EVENT sem.                          */
+    CPU_INT08U   OptFlags;                                      /* Opt flags passed at creation.                        */
+
+    CPU_INT08U   OwnerPrio;                                     /* Prio of curr lock owner. Used only when re-entrant.  */
+    CPU_INT08U   NestingCtr;                                    /* Curr cnt of nesting calls to acquire re-entrant lock.*/
+} KAL_LOCK;
+
+                                                                /* ------------------- KAL TMR TYPE ------------------- */
+#if (OS_TMR_EN == DEF_ENABLED)
+typedef  struct  kal_tmr {
+    OS_TMR   *TmrPtr;                                           /* Ptr to an OS-II tmr obj.                             */
+
+    void    (*CallbackFnct)(void  *p_arg);                      /* Tmr registered callback fnct.                        */
+    void     *CallbackArg;                                      /* Arg to pass to callback fnct.                        */
+} KAL_TMR;
+#endif
+
+                                                                /* ---------------- KAL TASK REG TYPE ----------------- */
+#if (OS_TASK_REG_TBL_SIZE > 0u)
+typedef  struct  kal_task_reg {
+    CPU_INT08U  Id;                                             /* Id of the task reg.                                  */
+} KAL_TASK_REG;
+#endif
+
+                                                                /* -------------- KAL INTERNAL DATA TYPE -------------- */
+typedef  struct  kal_data {
+    MEM_SEG       *MemSegPtr;                                   /* Mem Seg to alloc from.                               */
+
+#if (OS_SEM_EN == DEF_ENABLED)
+    MEM_DYN_POOL   LockPool;                                    /* Dyn mem pool used to alloc locks.                    */
+#endif
+
+#if (OS_TMR_EN == DEF_ENABLED)
+    MEM_DYN_POOL   TmrPool;                                     /* Dyn mem pool used to alloc tmrs.                     */
+#endif
+
+#if (OS_TASK_REG_TBL_SIZE > 0u)
+    MEM_DYN_POOL   TaskRegPool;                                 /* Dyn mem pool used to alloc task regs.                */
+#endif
+} KAL_DATA;
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                              LOCAL TABLES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                         LOCAL GLOBAL VARIABLES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+static            KAL_DATA     *KAL_DataPtr    = DEF_NULL;
+
+static            CPU_BOOLEAN   KAL_IsInit     = DEF_NO;
+static  volatile  CPU_INT08U    KAL_InitStatus = KAL_INIT_STATUS_NONE;
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                       LOCAL FUNCTION PROTOTYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#if (OS_TMR_EN == DEF_ENABLED)
+static  void      KAL_TmrFnctWrapper(void        *p_tmr_os,
+                                     void        *p_arg);
+#endif
+
+static  KAL_TICK  KAL_msToTicks     (CPU_INT32U   ms);
+
+static  RTOS_ERR  KAL_ErrConvert    (CPU_INT08U   err_os);
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                       LOCAL CONFIGURATION ERRORS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            GLOBAL FUNCTIONS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                         KAL CORE API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                              KAL_Init()
+*
+* Description : Initialize the Kernel Abstraction Layer.
+*
+* Argument(s) : p_cfg       Pointer to KAL configuration structure.
+*
+*               p_err       Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_OS                 Concurrent initialization failed.
+*                                   RTOS_ERR_ALREADY_INIT       Already initialized and p_cfg is not NULL.
+*                                   RTOS_ERR_ALLOC              Memory segment allocation failed.
+*                                   RTOS_ERR_INIT               Memory pool initialization failed.
+*
+* Return(s)   : none.
+*
+* Note(s)     : (1) This function must be called prior to any product initialization function if the
+*                   application needs to specify a memory segment.
+*********************************************************************************************************
+*/
+
+void  KAL_Init (KAL_CFG   *p_cfg,
+                RTOS_ERR  *p_err)
+{
+    MEM_SEG  *p_seg;
+    LIB_ERR   err_lib;
+    CPU_SR_ALLOC();
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+    #endif
+
+    CPU_CRITICAL_ENTER();
+    if (KAL_IsInit == DEF_YES) {                                /* Chk if KAL already init. See note #1.                */
+        CPU_INT08U  init_status = KAL_InitStatus;
+
+
+        CPU_CRITICAL_EXIT();
+
+        while (init_status == KAL_INIT_STATUS_NONE) {           /* Wait until init is done before returning.            */
+            OSTimeDly(100u);
+            CPU_CRITICAL_ENTER();
+            init_status = KAL_InitStatus;
+            CPU_CRITICAL_EXIT();
+        }
+        if (init_status == KAL_INIT_STATUS_OK) {                /* Check resulting init status.                         */
+            if (p_cfg == DEF_NULL) {
+               *p_err = RTOS_ERR_NONE;                          /* KAL_Init() can be called many times if no cfg.       */
+            } else {
+               *p_err = RTOS_ERR_ALREADY_INIT;                  /* If a cfg is given and KAL is already init, set err.  */
+            }
+        } else {
+           *p_err = RTOS_ERR_OS;                                /* Concurrent init failed.                              */
+        }
+        return;
+    }
+
+    KAL_IsInit = DEF_YES;                                       /* Prevent another init, even in case of err.           */
+    CPU_CRITICAL_EXIT();
+
+    p_seg = DEF_NULL;
+    if (p_cfg != DEF_NULL) {                                    /* Load cfg if given.                                   */
+        p_seg = p_cfg->MemSegPtr;
+    }
+
+    KAL_DataPtr = (KAL_DATA *)Mem_SegAlloc("KAL internal data",
+                                            p_seg,
+                                            sizeof(KAL_DATA),
+                                           &err_lib);
+    if (err_lib != LIB_MEM_ERR_NONE) {
+       *p_err = RTOS_ERR_ALLOC;
+        goto end_err;
+    }
+
+    KAL_DataPtr->MemSegPtr = p_seg;
+
+    #if (OS_SEM_EN == DEF_ENABLED)
+        Mem_DynPoolCreate("KAL lock pool",
+                          &KAL_DataPtr->LockPool,
+                           KAL_DataPtr->MemSegPtr,
+                           sizeof(KAL_LOCK),
+                           sizeof(CPU_ALIGN),
+                           0u,
+                           LIB_MEM_BLK_QTY_UNLIMITED,
+                          &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_INIT;
+            goto end_err;
+        }
+    #endif
+
+    #if (OS_TMR_EN == DEF_ENABLED)
+        Mem_DynPoolCreate("KAL tmr pool",
+                          &KAL_DataPtr->TmrPool,
+                           KAL_DataPtr->MemSegPtr,
+                           sizeof(KAL_TMR),
+                           sizeof(CPU_ALIGN),
+                           0u,
+                           LIB_MEM_BLK_QTY_UNLIMITED,
+                          &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_INIT;
+            goto end_err;
+        }
+    #endif
+
+    #if (OS_TASK_REG_TBL_SIZE > 0u)
+        Mem_DynPoolCreate("KAL task reg pool",
+                          &KAL_DataPtr->TaskRegPool,
+                           KAL_DataPtr->MemSegPtr,
+                           sizeof(KAL_TASK_REG),
+                           sizeof(CPU_ALIGN),
+                           0u,
+                           LIB_MEM_BLK_QTY_UNLIMITED,
+                          &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_INIT;
+            goto end_err;
+        }
+    #endif
+
+    CPU_CRITICAL_ENTER();
+    KAL_InitStatus = KAL_INIT_STATUS_OK;
+    CPU_CRITICAL_EXIT();
+
+   *p_err = RTOS_ERR_NONE;
+
+    return;
+
+end_err:                                                        /* Init failed. Handle vars for other concurrent init.  */
+    CPU_CRITICAL_ENTER();
+    KAL_InitStatus = KAL_INIT_STATUS_FAIL;                      /* Indicate potential concurrent init that it failed.   */
+    CPU_CRITICAL_EXIT();
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                          KAL_FeatureQuery()
+*
+* Description : Check if specified feature is available.
+*
+* Argument(s) : feature     Feature to query.
+*
+*               opt         Option associated with the feature requested.
+*
+* Return(s)   : DEF_YES, if feature is available.
+*
+*               DEF_NO,  otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+CPU_BOOLEAN  KAL_FeatureQuery (KAL_FEATURE  feature,
+                               KAL_OPT      opt)
+{
+    CPU_BOOLEAN  is_en;
+
+
+    is_en = DEF_NO;
+
+    switch (feature) {
+        case KAL_FEATURE_TASK_CREATE:                           /* ---------------------- TASKS ----------------------- */
+             is_en = DEF_YES;
+             break;
+
+
+        case KAL_FEATURE_TASK_DEL:
+             #if (OS_TASK_DEL_EN == DEF_ENABLED)
+                 is_en = DEF_YES;
+             #endif
+             break;
+
+
+#if (OS_SEM_EN == DEF_ENABLED)                                  /* ------------------- LOCKS & SEMS ------------------- */
+        case KAL_FEATURE_LOCK_CREATE:
+        case KAL_FEATURE_LOCK_RELEASE:
+        case KAL_FEATURE_SEM_CREATE:
+             is_en = DEF_YES;
+             break;
+
+
+        case KAL_FEATURE_LOCK_ACQUIRE:
+             if (DEF_BIT_IS_CLR(opt, KAL_OPT_CREATE_REENTRANT) == DEF_YES) {
+                                                                /* Re-entrant locks not supported in OS-II right now.   */
+                 if (DEF_BIT_IS_CLR(opt, KAL_OPT_PEND_NON_BLOCKING) == DEF_YES) {
+                     is_en = DEF_YES;
+                 } else {
+                     #if (OS_SEM_ACCEPT_EN == DEF_ENABLED)
+                         is_en = DEF_YES;                       /* Non-blocking supported only if OSSemAccept() is en.  */
+                     #endif
+                 }
+             }
+             break;
+
+
+        case KAL_FEATURE_SEM_PEND:
+             if (DEF_BIT_IS_CLR(opt, KAL_OPT_PEND_NON_BLOCKING) == DEF_YES) {
+                 is_en = DEF_YES;
+             } else {
+                 #if (OS_SEM_ACCEPT_EN == DEF_ENABLED)
+                     is_en = DEF_YES;                           /* Non-blocking supported only if OSSemAccept() is en.  */
+                 #endif
+             }
+             break;
+
+
+        case KAL_FEATURE_SEM_POST:
+             is_en = DEF_YES;
+             break;
+
+
+        case KAL_FEATURE_SEM_ABORT:
+             #if (OS_SEM_PEND_ABORT_EN == DEF_ENABLED)
+                 is_en = DEF_YES;
+             #endif
+             break;
+
+
+        case KAL_FEATURE_SEM_SET:
+             #if (OS_SEM_SET_EN == DEF_ENABLED)
+                 is_en = DEF_YES;
+             #endif
+             break;
+
+
+#if (OS_SEM_DEL_EN == DEF_ENABLED)
+        case KAL_FEATURE_LOCK_DEL:
+             if (DEF_BIT_IS_CLR(opt, KAL_OPT_CREATE_REENTRANT) == DEF_YES) {
+                 is_en = DEF_YES;
+             }
+             break;
+
+
+        case KAL_FEATURE_SEM_DEL:
+             is_en = DEF_YES;
+             break;
+#endif
+#endif /* OS_SEM_EN */
+
+
+        case KAL_FEATURE_TMR:                                   /* ----------------------- TMRS ----------------------- */
+             #if (OS_TMR_EN == DEF_ENABLED)
+                 is_en = DEF_YES;
+             #endif
+             break;
+
+
+#if (OS_Q_EN == DEF_ENABLED)                                    /* ---------------------- QUEUES ---------------------- */
+        case KAL_FEATURE_Q_CREATE:
+             #if ((OS_Q_POST_EN     == DEF_ENABLED) || \
+                  (OS_Q_POST_OPT_EN == DEF_ENABLED))
+                 is_en = DEF_YES;                               /* Qs and at least one of the Q post fnct are avail.    */
+             #endif
+             break;
+
+
+        case KAL_FEATURE_Q_PEND:
+             if (DEF_BIT_IS_CLR(opt, KAL_OPT_PEND_NON_BLOCKING) == DEF_YES) {
+                 is_en = DEF_YES;
+             } else {
+                 #if (OS_Q_ACCEPT_EN == DEF_ENABLED)
+                     is_en = DEF_YES;                           /* Non-blocking supported only if OSQAccept() is en.    */
+                 #endif
+             }
+             break;
+
+
+        case KAL_FEATURE_Q_POST:
+             #if ((OS_Q_POST_OPT_EN == DEF_ENABLED) || \
+                  (OS_Q_POST_EN == DEF_ENABLED))
+                 is_en = DEF_YES;
+             #endif
+             break;
+#endif  /* OS_Q_EN */
+
+
+        case KAL_FEATURE_DLY:                                   /* ----------------------- DLYS ----------------------- */
+             if (DEF_BIT_IS_CLR(opt, KAL_OPT_DLY_PERIODIC) == DEF_YES) {
+                 is_en = DEF_YES;
+             }
+             break;
+
+
+        case KAL_FEATURE_TASK_REG:                              /* ------------------- TASK STORAGE ------------------- */
+             #if (OS_TASK_REG_TBL_SIZE > 0u)
+                 is_en = DEF_YES;
+             #endif
+             break;
+
+
+        case KAL_FEATURE_TICK_GET:                              /* ------------------- TICK CTR INFO ------------------ */
+             #if (OS_TIME_GET_SET_EN == DEF_ENABLED)
+                 is_en = DEF_YES;
+             #endif
+             break;
+
+
+        default:
+             break;
+    }
+
+    return (is_en);
+}
+
+
+/*
+*********************************************************************************************************
+*                                         TASK API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                            KAL_TaskAlloc()
+*
+* Description : Allocate a task object and its stack.
+*
+* Argument(s) : p_name          Pointer to name of the task.
+*
+*               p_stk_base      Pointer to start of task stack. If NULL, the stack will be allocated from
+*                               the KAL memory segment.
+*
+*               stk_size_bytes  Size (in bytes) of the task stack.
+*
+*               p_cfg           Pointer to KAL task configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_INVALID_ARG        Specified stack size is invalid.
+*                                   RTOS_ERR_NOT_SUPPORTED      'p_cfg' parameter was not NULL.
+*                                   RTOS_ERR_ALLOC              Task stack or control block allocation failed.
+*
+* Return(s)   : Allocated task's handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TASK_HANDLE  KAL_TaskAlloc (const  CPU_CHAR          *p_name,
+                                       void              *p_stk_base,
+                                       CPU_SIZE_T         stk_size_bytes,
+                                       KAL_TASK_EXT_CFG  *p_cfg,
+                                       RTOS_ERR          *p_err)
+{
+    KAL_TASK_HANDLE   handle = KAL_TaskHandleNull;
+    KAL_TASK         *p_task;
+    CPU_ADDR          stk_addr;
+    CPU_ADDR          stk_addr_aligned;
+    CPU_SIZE_T        actual_stk_size_bytes;
+    LIB_ERR           err_lib;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+
+        if (p_cfg != DEF_NULL) {                                /* Make sure no unsupported cfg recv.                   */
+           *p_err = RTOS_ERR_NOT_SUPPORTED;
+            return (handle);
+        }
+    #else
+        (void)p_cfg;
+    #endif
+
+    if (p_stk_base == DEF_NULL) {                               /* Must alloc task stk on mem seg.                      */
+        stk_addr_aligned = (CPU_ADDR)Mem_SegAllocExt("KAL task stk",
+                                                      KAL_DataPtr->MemSegPtr,
+                                                      stk_size_bytes,
+                                                      CPU_CFG_STK_ALIGN_BYTES,
+                                                      DEF_NULL,
+                                                     &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_ALLOC;
+            return (handle);
+        }
+        actual_stk_size_bytes = stk_size_bytes;
+    } else {
+                                                                /* Align stk ptr, if needed.                            */
+        stk_addr              = (CPU_ADDR)p_stk_base;
+        stk_addr_aligned      =  MATH_ROUND_INC_UP_PWR2(stk_addr, CPU_CFG_STK_ALIGN_BYTES);
+        actual_stk_size_bytes =  stk_size_bytes - (stk_addr_aligned - stk_addr);
+    }
+
+    p_task = (KAL_TASK *)Mem_SegAlloc("KAL task",
+                                       KAL_DataPtr->MemSegPtr,
+                                       sizeof(KAL_TASK),
+                                      &err_lib);
+    if (err_lib != LIB_MEM_ERR_NONE) {
+       *p_err = RTOS_ERR_ALLOC;
+        return (handle);
+    }
+
+    p_task->StkBasePtr   = (CPU_STK *)stk_addr_aligned;
+    p_task->StkSizeBytes =  actual_stk_size_bytes;
+    p_task->Prio         =  0u;
+    #if (OS_TASK_NAME_EN == DEF_ENABLED)                        /* Check if task name is en.                            */
+        p_task->NamePtr  =  p_name;
+    #else
+        (void)p_name;
+    #endif
+    handle.TaskObjPtr    = (void *)p_task;
+
+   *p_err = RTOS_ERR_NONE;
+
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_TaskCreate()
+*
+* Description : Create and start a task.
+*
+* Argument(s) : task_handle     Handle of the task to create.
+*
+*               p_fnct          Pointer to task function.
+*
+*               p_task_arg      Pointer to argument that will be passed to task function (can be DEF_NULL).
+*
+*               prio            Task priority.
+*
+*               p_cfg           Pointer to KAL task configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_SUPPORTED      'p_cfg' parameter was not NULL.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Invalid argument passed to function.
+*                                   RTOS_ERR_ISR                Function called from an ISR context.
+*
+* Return(s)   : none.
+*
+* Note(s)     : (1) The task must be allocated prior to this call using KAL_TaskAlloc().
+*********************************************************************************************************
+*/
+
+void  KAL_TaskCreate (KAL_TASK_HANDLE     task_handle,
+                      void              (*p_fnct)(void  *p_arg),
+                      void               *p_task_arg,
+                      CPU_INT08U          prio,
+                      KAL_TASK_EXT_CFG   *p_cfg,
+                      RTOS_ERR           *p_err)
+{
+    KAL_TASK      *p_task;
+    CPU_STK_SIZE   stk_size_words;
+    CPU_INT32U     stk_top_offset;
+    CPU_INT08U     err_os;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (p_fnct == DEF_NULL) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+
+        if (KAL_TASK_HANDLE_IS_NULL(task_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+
+        if (p_cfg != DEF_NULL) {                                /* Make sure no unsupported cfg recv.                   */
+           *p_err = RTOS_ERR_NOT_SUPPORTED;
+            return;
+        }
+    #else
+        (void)p_cfg;
+    #endif
+
+    p_task         = (KAL_TASK *)task_handle.TaskObjPtr;
+    stk_size_words =  p_task->StkSizeBytes / sizeof(CPU_STK);
+
+    #if (OS_STK_GROWTH == DEF_ENABLED)                          /* Set stk top offset, based on OS_STK_GROWTH cfg.      */
+        stk_top_offset = stk_size_words - 1u;
+    #else
+        stk_top_offset = 0u;
+    #endif
+
+    #if (OS_TASK_CREATE_EXT_EN == DEF_ENABLED)
+    {
+        CPU_INT32U  stk_bottom_offset;
+
+
+        #if (OS_STK_GROWTH == DEF_ENABLED)                      /* Set stk bottom offset, based on OS_STK_GROWTH cfg.   */
+            stk_bottom_offset = 0u;
+        #else
+            stk_bottom_offset = stk_size_words - 1u;
+        #endif
+
+        err_os = OSTaskCreateExt(p_fnct,
+                                 p_task_arg,
+                                &p_task->StkBasePtr[stk_top_offset],
+                                 prio,
+                                 prio,
+                                &p_task->StkBasePtr[stk_bottom_offset],
+                                 stk_size_words,
+                                 DEF_NULL,
+                                 OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK);
+    }
+    #else
+        err_os = OSTaskCreate(p_fnct,
+                              p_task_arg,
+                             &p_task->StkBasePtr[stk_top_offset],
+                              prio);
+    #endif
+    if (err_os != OS_ERR_NONE) {
+       *p_err = KAL_ErrConvert(err_os);
+        return;
+    }
+
+   *p_err        = RTOS_ERR_NONE;
+    p_task->Prio = prio;
+
+    #if (OS_TASK_NAME_EN == DEF_ENABLED)                        /* Set task name if names en.                           */
+        if (p_task->NamePtr != DEF_NULL) {                      /* Do not try to set name if name is NULL.              */
+            OSTaskNameSet(prio, (INT8U *)p_task->NamePtr, &err_os);
+            if (err_os != OS_ERR_NONE) {
+               *p_err = KAL_ErrConvert(err_os);
+            }
+        }
+    #endif
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_TaskDel()
+*
+* Description : Delete a task.
+*
+* Argument(s) : task_handle     Handle of the task to delete.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Task handle is invalid.
+*                                   RTOS_ERR_ISR                If trying to delete task from an ISR.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_TaskDel (KAL_TASK_HANDLE   task_handle,
+                   RTOS_ERR         *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_TASK_HANDLE_IS_NULL(task_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if (OS_TASK_DEL_EN == DEF_ENABLED)
+    {
+        KAL_TASK    *p_task;
+        CPU_INT08U   err_os;
+
+
+        p_task = (KAL_TASK *)task_handle.TaskObjPtr;
+
+        err_os =  OSTaskDel(p_task->Prio);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else
+        (void)task_handle;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                         LOCK API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                           KAL_LockCreate()
+*
+* Description : Create a lock, which is unlocked by default.
+*
+* Argument(s) : p_name          Pointer to name of the lock.
+*
+*               p_cfg           Pointer to KAL lock configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_ALLOC              Unable to allocate memory for lock.
+*                                   RTOS_ERR_CREATE_FAIL        Lock creation failed.
+*
+* Return(s)   : Created lock handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_LOCK_HANDLE  KAL_LockCreate (const  CPU_CHAR          *p_name,
+                                        KAL_LOCK_EXT_CFG  *p_cfg,
+                                        RTOS_ERR          *p_err)
+{
+    KAL_LOCK_HANDLE  handle = KAL_LockHandleNull;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+
+        if (p_cfg != DEF_NULL) {
+            if (DEF_BIT_IS_SET_ANY(p_cfg->Opt, ~(KAL_OPT_CREATE_NONE | KAL_OPT_CREATE_REENTRANT)) == DEF_YES) {
+               *p_err = RTOS_ERR_INVALID_ARG;
+                return (handle);
+            }
+        }
+    #endif
+
+    #if (OS_SEM_EN == DEF_ENABLED)
+    {
+        KAL_LOCK  *p_kal_lock;
+        OS_EVENT  *p_sem;
+        LIB_ERR    err_lib;
+
+
+        p_kal_lock = (KAL_LOCK *)Mem_DynPoolBlkGet(&KAL_DataPtr->LockPool,
+                                                   &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_ALLOC;
+            return (handle);
+        }
+
+        p_kal_lock->OptFlags = DEF_BIT_NONE;
+
+        if ((p_cfg                                                != DEF_NULL) &&
+            (DEF_BIT_IS_SET(p_cfg->Opt, KAL_OPT_CREATE_REENTRANT) == DEF_YES)) {
+                                                                /* Created lock is re-entrant.                          */
+            DEF_BIT_SET(p_kal_lock->OptFlags, KAL_OPT_CREATE_REENTRANT);
+            p_kal_lock->OwnerPrio  = KAL_LOCK_OWNER_PRIO_NONE;
+            p_kal_lock->NestingCtr = 0u;
+        }
+
+       *p_err = RTOS_ERR_NONE;
+
+        p_sem = OSSemCreate(1u);
+        if (p_sem == (OS_EVENT *)0) {
+            Mem_DynPoolBlkFree(       &KAL_DataPtr->LockPool,   /* Free rsrc to pool.                                   */
+                               (void *)p_kal_lock,
+                                      &err_lib);
+            (void)err_lib;                                     /* Err ignored.                                         */
+
+           *p_err = RTOS_ERR_CREATE_FAIL;
+            return (handle);
+        }
+
+        #if (OS_EVENT_NAME_EN == DEF_ENABLED)                   /* Set name only if cfg is en.                          */
+            if (p_name != DEF_NULL) {
+                CPU_INT08U  err_os;
+
+
+                OSEventNameSet(         p_sem,
+                               (INT8U *)p_name,
+                                       &err_os);
+                (void)err_os;                                  /* Err ignored, no err can occur if OSSemCreate() is OK.*/
+            }
+        #else
+            (void)p_name;
+        #endif
+
+        p_kal_lock->SemEventPtr =  p_sem;
+        handle.LockObjPtr       = (void *)p_kal_lock;
+
+        return (handle);
+    }
+    #else
+        (void)p_name;
+        (void)p_cfg;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (handle);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_LockAcquire()
+*
+* Description : Acquire a lock.
+*
+* Argument(s) : lock_handle     Handle of the lock to acquire.
+*
+*               opt             Options available:
+*                                   KAL_OPT_PEND_NONE:          block until timeout expires or lock is available.
+*                                   KAL_OPT_PEND_BLOCKING:      block until timeout expires or lock is available.
+*                                   KAL_OPT_PEND_NON_BLOCKING:  return immediately even if lock is not available.
+*
+*               timeout_ms      Timeout, in milliseconds. A value of 0 will never timeout.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_TIMEOUT            Operation timed-out.
+*                                   RTOS_ERR_ISR                Function was called from an ISR.
+*                                   RTOS_ERR_WOULD_BLOCK        KAL_OPT_PEND_NON_BLOCKING opt specified and
+*                                                               lock is not available.
+*                                   RTOS_ERR_WOULD_OVF          Nesting count would overflow.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_LockAcquire (KAL_LOCK_HANDLE   lock_handle,
+                       KAL_OPT           opt,
+                       CPU_INT32U        timeout_ms,
+                       RTOS_ERR         *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_LOCK_HANDLE_IS_NULL(lock_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+
+        if (DEF_BIT_IS_SET_ANY(opt, ~(KAL_OPT_PEND_NONE | KAL_OPT_PEND_NON_BLOCKING)) == DEF_YES) {
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return;
+        }
+    #endif
+
+    #if (OS_SEM_EN == DEF_ENABLED)
+    {
+        KAL_LOCK    *p_kal_lock;
+        OS_EVENT    *p_sem;
+        CPU_INT32U   timeout_ticks;
+        CPU_INT08U   err_os;
+        CPU_SR_ALLOC();
+
+
+        p_kal_lock = (KAL_LOCK *)lock_handle.LockObjPtr;
+        p_sem      =  p_kal_lock->SemEventPtr;
+
+        if (timeout_ms != KAL_TIMEOUT_INFINITE) {
+            timeout_ticks = KAL_msToTicks(timeout_ms);
+        } else {
+            timeout_ticks = 0u;
+        }
+
+        if (DEF_BIT_IS_SET(p_kal_lock->OptFlags, KAL_OPT_CREATE_REENTRANT) == DEF_YES) {
+            CPU_CRITICAL_ENTER();
+            if (p_kal_lock->OwnerPrio == OSPrioCur) {
+                p_kal_lock->NestingCtr++;
+                if (p_kal_lock->NestingCtr != 0u) {
+                   *p_err = RTOS_ERR_NONE;
+                } else {
+                   *p_err = RTOS_ERR_WOULD_OVF;
+                    p_kal_lock->NestingCtr--;
+                }
+                CPU_CRITICAL_EXIT();
+                return;
+            }
+            CPU_CRITICAL_EXIT();
+        }
+
+        if (DEF_BIT_IS_CLR(opt, KAL_OPT_PEND_NON_BLOCKING) == DEF_YES) {
+            OSSemPend(p_sem,
+                      timeout_ticks,
+                     &err_os);
+            if (err_os == OS_ERR_NONE) {
+               *p_err = RTOS_ERR_NONE;
+            } else {
+               *p_err = KAL_ErrConvert(err_os);
+                return;
+            }
+        } else {
+            #if (OS_SEM_ACCEPT_EN == DEF_ENABLED)               /* If OSSemAccept() is en.                              */
+                CPU_INT16U  ret_val;
+
+
+                ret_val = OSSemAccept(p_sem);
+                if (ret_val != 0u) {
+                   *p_err = RTOS_ERR_NONE;
+                } else {
+                   *p_err = RTOS_ERR_WOULD_BLOCK;
+                    return;
+                }
+            #else                                               /* If OSSemAccept() is dis, cannot exec operation.      */
+               *p_err = RTOS_ERR_NOT_AVAIL;
+                return;
+            #endif
+        }
+
+        if (DEF_BIT_IS_SET(p_kal_lock->OptFlags, KAL_OPT_CREATE_REENTRANT) == DEF_YES) {
+            CPU_CRITICAL_ENTER();
+            p_kal_lock->OwnerPrio  = OSPrioCur;                 /* If lock is re-entrant, set prio to cur.              */
+            p_kal_lock->NestingCtr = 0u;
+            CPU_CRITICAL_EXIT();
+        }
+
+        return;
+    }
+    #else
+        (void)lock_handle;
+        (void)opt;
+        (void)timeout_ms;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_LockRelease()
+*
+* Description : Release a lock.
+*
+* Argument(s) : lock_handle     Handle of the lock to release.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_WOULD_OVF          Semaphore would overflow.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_LockRelease (KAL_LOCK_HANDLE   lock_handle,
+                       RTOS_ERR         *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_LOCK_HANDLE_IS_NULL(lock_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if (OS_SEM_EN == DEF_ENABLED)
+    {
+        KAL_LOCK    *p_kal_lock;
+        OS_EVENT    *p_sem;
+        CPU_INT08U   err_os;
+        CPU_SR_ALLOC();
+
+
+        p_kal_lock = (KAL_LOCK *)lock_handle.LockObjPtr;
+        p_sem      =  p_kal_lock->SemEventPtr;
+
+        if (DEF_BIT_IS_SET(p_kal_lock->OptFlags, KAL_OPT_CREATE_REENTRANT) == DEF_YES) {
+                                                                /* Re-entrant lock.                                     */
+            CPU_CRITICAL_ENTER();
+            if (p_kal_lock->NestingCtr != 0u) {
+                p_kal_lock->NestingCtr--;
+                CPU_CRITICAL_EXIT();
+               *p_err = RTOS_ERR_NONE;
+                return;
+            }
+                                                                /* If lock is re-entrant and is not nested, set ...     */
+            p_kal_lock->OwnerPrio = KAL_LOCK_OWNER_PRIO_NONE;   /* ... OwnerPrio to 'none'.                             */
+            CPU_CRITICAL_EXIT();
+        }
+
+        err_os = OSSemPost(p_sem);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else
+        (void)lock_handle;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_LockDel()
+*
+* Description : Delete a lock.
+*
+* Argument(s) : lock_handle     Handle of the lock to delete.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_ISR                Function was called from an ISR.
+*                                   RTOS_ERR_NOT_SUPPORTED      Re-entrant locks cannot be deleted.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_LockDel (KAL_LOCK_HANDLE   lock_handle,
+                   RTOS_ERR         *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_LOCK_HANDLE_IS_NULL(lock_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if ((OS_SEM_EN     == DEF_ENABLED) && \
+         (OS_SEM_DEL_EN == DEF_ENABLED))                        /* Sems and sems del are avail.                         */
+    {
+        KAL_LOCK    *p_kal_lock;
+        CPU_INT08U   err_os;
+        LIB_ERR      err_lib;
+        CPU_SR_ALLOC();
+
+
+        p_kal_lock = (KAL_LOCK *)lock_handle.LockObjPtr;
+
+        if (DEF_BIT_IS_SET(p_kal_lock->OptFlags, KAL_OPT_CREATE_REENTRANT) == DEF_YES) {
+            CPU_CRITICAL_ENTER();
+            p_kal_lock->OwnerPrio  = KAL_LOCK_OWNER_PRIO_NONE;  /* If lock is re-entrant, set OwnerPrio to 'none'.      */
+            p_kal_lock->NestingCtr = 0u;
+            CPU_CRITICAL_EXIT();
+        }
+        (void)OSSemDel(p_kal_lock->SemEventPtr,
+                       OS_DEL_ALWAYS,
+                      &err_os);
+        if (err_os == OS_ERR_NONE) {
+            Mem_DynPoolBlkFree(       &KAL_DataPtr->LockPool,   /* Free rsrc to pool.                                   */
+                               (void *)p_kal_lock,
+                                      &err_lib);
+            (void)err_lib;                                     /* Err ignored.                                         */
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else                                                       /* Sems or sems del is not avail.                       */
+        (void)lock_handle;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                          SEM API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                            KAL_SemCreate()
+*
+* Description : Create a semaphore, with a count of 0.
+*
+* Argument(s) : p_name          Pointer to name of the semaphore.
+*
+*               p_cfg           Pointer to KAL semaphore configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NOT_SUPPORTED      'p_cfg' parameter was not NULL.
+*                                   RTOS_ERR_ALLOC              Unable to allocate memory for semaphore.
+*                                   RTOS_ERR_CREATE_FAIL        Semaphore creation failed.
+*
+* Return(s)   : Created semaphore's handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_SEM_HANDLE  KAL_SemCreate (const  CPU_CHAR         *p_name,
+                                      KAL_SEM_EXT_CFG  *p_cfg,
+                                      RTOS_ERR         *p_err)
+{
+    KAL_SEM_HANDLE  handle = KAL_SemHandleNull;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+
+        if (p_cfg != DEF_NULL) {                                /* Make sure no unsupported cfg recv.                   */
+           *p_err = RTOS_ERR_NOT_SUPPORTED;
+            return (handle);
+        }
+    #else
+        (void)p_cfg;
+    #endif
+
+    #if (OS_SEM_EN == DEF_ENABLED)
+    {
+        OS_EVENT  *p_sem;
+
+
+       *p_err = RTOS_ERR_NONE;
+
+        p_sem = OSSemCreate(0u);
+        if (p_sem == (OS_EVENT *)0) {
+           *p_err = RTOS_ERR_CREATE_FAIL;
+            return (handle);
+        }
+
+        #if (OS_EVENT_NAME_EN == DEF_ENABLED)
+            if (p_name != DEF_NULL) {
+                CPU_INT08U  err_os;
+
+
+                OSEventNameSet(         p_sem,
+                               (INT8U *)p_name,
+                                       &err_os);
+                (void)err_os;                                  /* Err ignored, no err can occur if OSSemCreate() is OK.*/
+            }
+        #else
+            (void)p_name;
+        #endif
+
+        handle.SemObjPtr = (void *)p_sem;
+
+        return (handle);
+    }
+    #else
+        (void)p_name;
+        (void)p_cfg;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (handle);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemPend()
+*
+* Description : Pend on a semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to pend on.
+*
+*               opt             Options available:
+*                                   KAL_OPT_PEND_NONE:          block until timeout expires or semaphore is available.
+*                                   KAL_OPT_PEND_BLOCKING:      block until timeout expires or semaphore is available.
+*                                   KAL_OPT_PEND_NON_BLOCKING:  return immediately even if semaphore is not available.
+*
+*               timeout_ms      Timeout, in milliseconds. A value of 0 will never timeout.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_ABORT              Pend operation was aborted.
+*                                   RTOS_ERR_TIMEOUT            Operation timed-out.
+*                                   RTOS_ERR_ISR                Function was called from an ISR.
+*                                   RTOS_ERR_WOULD_BLOCK        KAL_OPT_PEND_NON_BLOCKING opt specified and
+*                                                               semaphore is not available.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPend (KAL_SEM_HANDLE   sem_handle,
+                   KAL_OPT          opt,
+                   CPU_INT32U       timeout_ms,
+                   RTOS_ERR        *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_SEM_HANDLE_IS_NULL(sem_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+
+        if (DEF_BIT_IS_SET_ANY(opt, ~(KAL_OPT_PEND_NONE | KAL_OPT_PEND_NON_BLOCKING)) == DEF_YES) {
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return;
+        }
+    #endif
+
+    #if (OS_SEM_EN == DEF_ENABLED)
+    {
+        OS_EVENT    *p_sem;
+        CPU_INT32U   timeout_ticks;
+
+
+        p_sem = (OS_EVENT *)sem_handle.SemObjPtr;
+
+        if (timeout_ms != KAL_TIMEOUT_INFINITE) {
+            timeout_ticks = KAL_msToTicks(timeout_ms);
+        } else {
+            timeout_ticks = 0u;
+        }
+
+        if (DEF_BIT_IS_CLR(opt, KAL_OPT_PEND_NON_BLOCKING) == DEF_YES) {
+            CPU_INT08U  err_os;
+
+
+            OSSemPend(p_sem,
+                      timeout_ticks,
+                     &err_os);
+            if (err_os == OS_ERR_NONE) {
+               *p_err = RTOS_ERR_NONE;
+            } else {
+               *p_err = KAL_ErrConvert(err_os);
+            }
+        } else {
+            #if (OS_SEM_ACCEPT_EN == DEF_ENABLED)               /* If OSSemAccept() is en.                              */
+            {
+                CPU_INT16U  ret_val;
+
+
+                ret_val = OSSemAccept(p_sem);
+                if (ret_val == 0u) {
+                   *p_err = RTOS_ERR_WOULD_BLOCK;
+                }
+            }
+            #else                                               /* If OSSemAccept() is dis, cannot exec operation.      */
+               *p_err = RTOS_ERR_NOT_AVAIL;
+            #endif
+        }
+
+        return;
+    }
+    #else
+        (void)sem_handle;
+        (void)opt;
+        (void)timeout_ms;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemPost()
+*
+* Description : Post a semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to post.
+*
+*               opt             Options available:
+*                                   KAL_OPT_POST_NONE:     wake only the highest priority task pending on semaphore.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_WOULD_OVF          Semaphore would overflow.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPost (KAL_SEM_HANDLE   sem_handle,
+                   KAL_OPT          opt,
+                   RTOS_ERR        *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_SEM_HANDLE_IS_NULL(sem_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+
+        if (opt != KAL_OPT_POST_NONE) {
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return;
+        }
+    #endif
+
+    #if (OS_SEM_EN == DEF_ENABLED)
+    {
+        OS_EVENT    *p_sem;
+        CPU_INT08U   err_os;
+
+
+        p_sem  = (OS_EVENT *)sem_handle.SemObjPtr;
+
+        err_os =  OSSemPost(p_sem);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else
+        (void)sem_handle;
+        (void)opt;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                          KAL_SemPendAbort()
+*
+* Description : Abort given semaphore and resume all the tasks pending on it.
+*
+* Argument(s) : sem_handle      Handle of the sempahore to abort.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPendAbort (KAL_SEM_HANDLE   sem_handle,
+                        RTOS_ERR        *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_SEM_HANDLE_IS_NULL(sem_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if ((OS_SEM_EN            == DEF_ENABLED) && \
+         (OS_SEM_PEND_ABORT_EN == DEF_ENABLED))                 /* Sems and sems pend abort are avail.                  */
+    {
+        OS_EVENT    *p_sem;
+        CPU_INT08U   err_os;
+
+
+        p_sem = (OS_EVENT *)sem_handle.SemObjPtr;
+
+        (void)OSSemPendAbort(p_sem,
+                             OS_PEND_OPT_BROADCAST,
+                            &err_os);
+        if ((err_os == OS_ERR_NONE) ||
+            (err_os != OS_ERR_PEND_ABORT)) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else                                                       /* Sems or sems pend abort is not avail.                */
+        (void)sem_handle;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemSet()
+*
+* Description : Set value of semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to set.
+*
+*               cnt             Count value to set semaphore.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_OS                 Tasks are waiting on semaphore. Cannot set value.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemSet (KAL_SEM_HANDLE   sem_handle,
+                  CPU_INT16U       cnt,
+                  RTOS_ERR        *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ------------------ VALIDATE ARGS ------------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_SEM_HANDLE_IS_NULL(sem_handle) == DEF_YES) {    /* Validate handle.                                     */
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if ((OS_SEM_EN     == DEF_ENABLED) && \
+         (OS_SEM_SET_EN == DEF_ENABLED))                        /* Sems and sems set are avail.                         */
+    {
+        CPU_INT08U  err_os;
+
+
+        OSSemSet((OS_EVENT *)sem_handle.SemObjPtr,
+                             cnt,
+                            &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else                                                       /* Sems or sems set is not avail.                       */
+        (void)sem_handle;
+        (void)cnt;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemDel()
+*
+* Description : Delete a semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to delete.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_ISR                Function was called from an ISR.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemDel (KAL_SEM_HANDLE   sem_handle,
+                  RTOS_ERR         *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_SEM_HANDLE_IS_NULL(sem_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if ((OS_SEM_EN     == DEF_ENABLED) && \
+         (OS_SEM_DEL_EN == DEF_ENABLED))                        /* Sems and sems del are avail.                         */
+    {
+        CPU_INT08U  err_os;
+
+
+        (void)OSSemDel((OS_EVENT *)sem_handle.SemObjPtr,
+                                   OS_DEL_ALWAYS,
+                                  &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else                                                       /* Sems or sems del is not avail.                       */
+        (void)sem_handle;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                          TMR API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                            KAL_TmrCreate()
+*
+* Description : Create a single-shot timer.
+*
+* Argument(s) : p_name          Pointer to name of the timer.
+*
+*               p_callback      Pointer to the callback function that will be called on completion of timer.
+*
+*               p_callback_arg  Argument passed to callback function.
+*
+*               interval_ms     If timer is 'one-shot', delay  used by the timer, in milliseconds.
+*                               If timer is 'periodic', period used by the timer, in milliseconds.
+*
+*               p_cfg           Pointer to KAL timer configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Null pointer passed to function.
+*                                   RTOS_ERR_ALLOC              Unable to allocate memory for resource.
+*                                   RTOS_ERR_INVALID_ARG        Invalid argument passed to function.
+*                                   RTOS_ERR_ISR                Function called from an ISR context.
+*                                   RTOS_ERR_NO_MORE_RSRC       OS cannot allocate timer resource.
+*                                   RTOS_ERR_OS                 Generic OS error.
+*
+* Return(s)   : Created timer handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TMR_HANDLE  KAL_TmrCreate (const  CPU_CHAR   *p_name,
+                               void             (*p_callback)(void  *p_arg),
+                               void              *p_callback_arg,
+                               CPU_INT32U         interval_ms,
+                               KAL_TMR_EXT_CFG   *p_cfg,
+                               RTOS_ERR          *p_err)
+{
+    KAL_TMR_HANDLE  handle = KAL_TmrHandleNull;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+
+        if (p_callback == DEF_NULL) {                           /* Validate callback fnct ptr.                          */
+           *p_err = RTOS_ERR_NULL_PTR;
+            return (handle);
+        }
+
+        if (interval_ms == 0u) {                                /* Validate time.                                       */
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return (handle);
+        }
+
+        if (p_cfg != DEF_NULL) {
+            if (DEF_BIT_IS_SET_ANY(p_cfg->Opt, ~(KAL_OPT_TMR_NONE | KAL_OPT_TMR_PERIODIC)) == DEF_YES) {
+               *p_err = RTOS_ERR_INVALID_ARG;
+                return (handle);
+            }
+        }
+    #endif
+
+    #if (OS_TMR_EN == DEF_ENABLED)
+    {
+        KAL_TMR     *p_tmr;
+        CPU_INT32U   tmr_dly;
+        CPU_INT32U   tmr_period;
+        CPU_INT08U   opt_os;
+        CPU_INT08U   err_os;
+        LIB_ERR      err_lib;
+
+
+        p_tmr  = (KAL_TMR *)Mem_DynPoolBlkGet(&KAL_DataPtr->TmrPool,
+                                              &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_ALLOC;
+            return (handle);
+        }
+
+        p_tmr->CallbackFnct = p_callback;
+        p_tmr->CallbackArg  = p_callback_arg;
+                                                                /* Tmr is 'periodic'.                                   */
+        if ((p_cfg                                            != DEF_NULL) &&
+            (DEF_BIT_IS_SET(p_cfg->Opt, KAL_OPT_TMR_PERIODIC) == DEF_YES)) {
+            opt_os     = OS_TMR_OPT_PERIODIC;
+            tmr_dly    = 0u;
+            tmr_period = KAL_msToTicks(interval_ms);
+        } else {
+            opt_os     = OS_TMR_OPT_ONE_SHOT;                   /* Tmr is 'one-shot'.                                   */
+            tmr_dly    = KAL_msToTicks(interval_ms);
+            tmr_period = 0u;
+        }
+
+        p_tmr->TmrPtr = OSTmrCreate(              tmr_dly,      /* Create tmr obj.                                      */
+                                                  tmr_period,
+                                                  opt_os,
+                                                  KAL_TmrFnctWrapper,
+                                    (void       *)p_tmr,
+                                    (CPU_INT08U *)p_name,
+                                                 &err_os);
+        if (err_os == OS_ERR_NONE) {
+            handle.TmrObjPtr = p_tmr;
+           *p_err            = RTOS_ERR_NONE;
+        } else {
+            Mem_DynPoolBlkFree(&KAL_DataPtr->TmrPool,
+                                p_tmr,
+                               &err_lib);
+            (void)err_lib;
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return (handle);
+    }
+    #else
+        (void)p_name;
+        (void)p_callback;
+        (void)p_callback_arg;
+        (void)interval_ms;
+        (void)p_cfg;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (handle);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                            KAL_TmrStart()
+*
+* Description : Start timer.
+*
+* Argument(s) : tmr_handle      Handle of timer to start.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Null timer handle passed to function.
+*                                   RTOS_ERR_ISR                Function called from an ISR context.
+*                                   RTOS_ERR_INVALID_ARG        Invalid handle passed to function.
+*                                   RTOS_ERR_OS                 Generic OS error.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_TmrStart (KAL_TMR_HANDLE   tmr_handle,
+                    RTOS_ERR        *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_TMR_HANDLE_IS_NULL(tmr_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if (OS_TMR_EN == DEF_ENABLED)
+    {
+        KAL_TMR     *p_tmr;
+        CPU_INT08U   err_os;
+
+
+        p_tmr = (KAL_TMR *)tmr_handle.TmrObjPtr;
+
+        (void)OSTmrStart(p_tmr->TmrPtr,
+                        &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else
+        (void)tmr_handle;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                           Q API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                             KAL_QCreate()
+*
+* Description : Create an empty queue.
+*
+* Argument(s) : p_name          Pointer to name of the queue.
+*
+*               max_msg_qty     Maximum number of message contained in the queue.
+*
+*               p_cfg           Pointer to KAL queue configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_ALLOC              Unable to allocate memory for queue.
+*                                   RTOS_ERR_CREATE_FAIL        Queue creation failed.
+*
+* Return(s)   : Created queue handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_Q_HANDLE  KAL_QCreate (const  CPU_CHAR       *p_name,
+                                  KAL_MSG_QTY     max_msg_qty,
+                                  KAL_Q_EXT_CFG  *p_cfg,
+                                  RTOS_ERR       *p_err)
+{
+    KAL_Q_HANDLE  handle = KAL_QHandleNull;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+        if (p_cfg != DEF_NULL) {                                /* Make sure no unsupported cfg recv.                   */
+           *p_err = RTOS_ERR_NOT_SUPPORTED;
+            return (handle);
+        }
+    #else
+        (void)p_cfg;
+    #endif
+
+    #if ((OS_Q_EN          == DEF_ENABLED) && \
+        ((OS_Q_POST_EN     == DEF_ENABLED) || \
+         (OS_Q_POST_OPT_EN == DEF_ENABLED)))                    /* Qs and at least one of the Q post fnct are avail.    */
+    {
+        void      **p_q_start;
+        OS_EVENT   *p_q_event;
+        LIB_ERR     err_lib;
+
+
+        p_q_start = (void **)Mem_SegAlloc("KAL Q",
+                                           KAL_DataPtr->MemSegPtr,
+                                           sizeof(void *) * max_msg_qty,
+                                          &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_ALLOC;
+            return (handle);
+        }
+
+        p_q_event = OSQCreate(p_q_start,
+                              max_msg_qty);
+        if (p_q_event == (OS_EVENT *)0) {
+           *p_err = RTOS_ERR_CREATE_FAIL;
+            return (handle);
+        }
+
+        #if (OS_EVENT_NAME_EN == DEF_ENABLED)
+            if (p_name != DEF_NULL) {
+                CPU_INT08U  err_os;
+
+
+                OSEventNameSet(              p_q_event,
+                               (CPU_INT08U *)p_name,
+                                            &err_os);
+                (void)err_os;                                  /* Err ignored, no err can occur if OSQCreate() is OK.  */
+            }
+        #else
+            (void)p_name;
+        #endif
+
+        handle.QObjPtr = (void *)p_q_event;
+       *p_err          =  RTOS_ERR_NONE;
+
+        return (handle);
+    }
+    #else                                                       /* Qs or Q post are not avail.                          */
+        (void)p_name;
+        (void)max_msg_qty;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (handle);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                              KAL_QPend()
+*
+* Description : Pend/get first message of queue.
+*
+* Argument(s) : q_handle        Handle of the queue to pend on.
+*
+*               opt             Options available:
+*                                   KAL_OPT_PEND_NONE:          block until timeout expires or message is available.
+*                                   KAL_OPT_PEND_BLOCKING:      block until timeout expires or message is available.
+*                                   KAL_OPT_PEND_NON_BLOCKING:  return immediately with or without message.
+*
+*               timeout_ms      Timeout, in milliseconds. A value of 0 will never timeout.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_TIMEOUT            Operation timed-out.
+*                                   RTOS_ERR_ISR                Function was called from an ISR.
+*                                   RTOS_ERR_WOULD_BLOCK        KAL_OPT_PEND_NON_BLOCKING opt specified and no
+*                                                               message is available.
+*
+* Return(s)   : Pointer to message obtained, if any, if no error.
+*
+*               Null pointer,                        otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  *KAL_QPend (KAL_Q_HANDLE   q_handle,
+                  KAL_OPT        opt,
+                  CPU_INT32U     timeout_ms,
+                  RTOS_ERR      *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(DEF_NULL);
+        }
+
+        if (KAL_Q_HANDLE_IS_NULL(q_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return (DEF_NULL);
+        }
+
+        if (DEF_BIT_IS_SET_ANY(opt, ~(KAL_OPT_PEND_NONE | KAL_OPT_PEND_NON_BLOCKING)) == DEF_YES) {
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return (DEF_NULL);
+        }
+    #endif
+
+    #if ((OS_Q_EN          == DEF_ENABLED) && \
+        ((OS_Q_POST_EN     == DEF_ENABLED) || \
+         (OS_Q_POST_OPT_EN == DEF_ENABLED)))                    /* Qs and at least one of the Q post fnct are avail.    */
+    {
+        OS_EVENT    *p_q_event;
+        void        *p_msg;
+        CPU_INT08U   err_os;
+
+
+        p_q_event = (OS_EVENT *)q_handle.QObjPtr;
+
+        if (DEF_BIT_IS_CLR(opt, KAL_OPT_PEND_NON_BLOCKING) == DEF_YES) {
+            CPU_INT32U  timeout_ticks;
+
+
+                                                                /* Blocking call.                                       */
+            if (timeout_ms != KAL_TIMEOUT_INFINITE) {
+                timeout_ticks = KAL_msToTicks(timeout_ms);
+            } else {
+                timeout_ticks = 0u;
+            }
+
+            p_msg = OSQPend(p_q_event,
+                            timeout_ticks,
+                           &err_os);
+        } else {                                                /* Non-blocking call.                                   */
+            #if (OS_Q_ACCEPT_EN == DEF_ENABLED)
+                p_msg = OSQAccept(p_q_event,
+                                 &err_os);
+            #else
+               *p_err = RTOS_ERR_NOT_AVAIL;
+
+                return (DEF_NULL);
+            #endif
+        }
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return (p_msg);
+    }
+    #else                                                       /* Qs or Q post are not avail.                          */
+        (void)q_handle;
+        (void)opt;
+        (void)timeout_ms;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (DEF_NULL);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                              KAL_QPost()
+*
+* Description : Post message on queue.
+*
+* Argument(s) : q_handle        Handle of the queue on which to post message.
+*
+*               p_msg           Pointer to message to post.
+*
+*               opt             Options available:
+*                                   KAL_OPT_POST_NONE:     wake only the highest priority task pending on queue.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_NO_MORE_RSRC       Queue cannot contain any more message.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_QPost (KAL_Q_HANDLE   q_handle,
+                 void          *p_msg,
+                 KAL_OPT        opt,
+                 RTOS_ERR      *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_Q_HANDLE_IS_NULL(q_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+
+        if (opt != KAL_OPT_POST_NONE) {
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return;
+        }
+    #else
+        (void)opt;
+    #endif
+
+    #if ((OS_Q_EN          == DEF_ENABLED) && \
+        ((OS_Q_POST_EN     == DEF_ENABLED) || \
+         (OS_Q_POST_OPT_EN == DEF_ENABLED)))                    /* Qs and at least one of the Q post fnct are avail.    */
+    {
+        OS_EVENT    *p_q_event;
+        CPU_INT08U   err_os;
+
+
+        p_q_event = (OS_EVENT *)q_handle.QObjPtr;
+
+        #if (OS_Q_POST_OPT_EN == DEF_ENABLED)
+            err_os = OSQPostOpt(p_q_event,
+                                p_msg,
+                                OS_POST_OPT_NONE);
+            if (err_os == OS_ERR_NONE) {
+               *p_err = RTOS_ERR_NONE;
+            } else {
+               *p_err = KAL_ErrConvert(err_os);
+            }
+        #elif (OS_Q_POST_EN == DEF_ENABLED)
+            err_os = OSQPost(p_q_event,
+                             p_msg);
+            if (err_os == OS_ERR_NONE) {
+               *p_err = RTOS_ERR_NONE;
+            } else {
+               *p_err = KAL_ErrConvert(err_os);
+            }
+        #endif
+
+        return;
+    }
+    #else                                                       /* Qs or Q post are not avail.                          */
+        (void)q_handle;
+        (void)p_msg;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                          DLY API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                               KAL_Dly()
+*
+* Description : Delay current task (in milliseconds).
+*
+* Argument(s) : dly_ms          Delay value, in milliseconds.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_Dly (CPU_INT32U  dly_ms)
+{
+    CPU_INT32U  dly_ticks;
+
+
+    if (dly_ms != 0u) {
+        dly_ticks = KAL_msToTicks(dly_ms);
+    } else {
+        dly_ticks = 0u;
+    }
+
+    OSTimeDly(dly_ticks);
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_DlyTick()
+*
+* Description : Delay current task (in ticks).
+*
+* Argument(s) : dly_ticks       Delay value, in ticks.
+*
+*               opt             Options available:
+*                                   KAL_OPT_DLY_NONE:       apply a 'normal' delay.
+*                                   KAL_OPT_DLY:            apply a 'normal' delay.
+*                                   KAL_OPT_DLY_PERIODIC:   apply a periodic delay.
+*
+* Return(s)   : none.
+*
+* Note(s)     : (1) KAL_OPT_DLY_PERIODIC is not supported. Using KAL_OPT_DLY instead.
+*********************************************************************************************************
+*/
+
+void  KAL_DlyTick (KAL_TICK  dly_ticks,
+                   KAL_OPT   opt)
+{
+    (void)opt;
+
+    OSTimeDly(dly_ticks);
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                       TASK REG API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                          KAL_TaskRegCreate()
+*
+* Description : Create a task register.
+*
+* Argument(s) : p_cfg           Pointer to KAL task register configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NOT_SUPPORTED      'p_cfg' parameter was not NULL.
+*                                   RTOS_ERR_ALLOC              Unable to allocate memory for task register.
+*                                   RTOS_ERR_NO_MORE_RSRC       No more task register available.
+*
+* Return(s)   : Created task register's handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TASK_REG_HANDLE  KAL_TaskRegCreate (KAL_TASK_REG_EXT_CFG  *p_cfg,
+                                        RTOS_ERR              *p_err)
+{
+    KAL_TASK_REG_HANDLE  handle = KAL_TaskRegHandleNull;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+
+        if (p_cfg != DEF_NULL) {                                /* Make sure no unsupported cfg recv.                   */
+           *p_err = RTOS_ERR_NOT_SUPPORTED;
+            return (handle);
+        }
+    #else
+        (void)p_cfg;
+    #endif
+
+    #if (OS_TASK_REG_TBL_SIZE > 0u)
+    {
+        KAL_TASK_REG  *p_task_reg;
+        CPU_INT08U     err_os;
+        LIB_ERR        err_lib;
+
+
+        p_task_reg = (KAL_TASK_REG *)Mem_DynPoolBlkGet(&KAL_DataPtr->TaskRegPool,
+                                                       &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_ALLOC;
+            return (handle);
+        }
+
+        p_task_reg->Id = OSTaskRegGetID(&err_os);
+        if (err_os == OS_ERR_NONE) {
+            handle.TaskRegObjPtr = (void *)p_task_reg;
+           *p_err                =  RTOS_ERR_NONE;
+        } else {
+                                                                /* Free rsrc to pool.                                   */
+            Mem_DynPoolBlkFree(       &KAL_DataPtr->TaskRegPool,
+                               (void *)p_task_reg,
+                                      &err_lib);
+            (void)err_lib;                                     /* Err ignored.                                         */
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return (handle);
+    }
+    #else
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (handle);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_TaskRegGet()
+*
+* Description : Get value from a task register.
+*
+* Argument(s) : task_handle     Handle of the task associated to the task register. Current task is used if NULL.
+*
+*               task_reg_handle Handle of the task register to read.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Task register handle is NULL.
+*                                   RTOS_ERR_INVALID_ARG        Handle specified is invalid.
+*
+* Return(s)   : Value read from the task register, if no error.
+*               0,                                 otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+CPU_INT32U  KAL_TaskRegGet (KAL_TASK_HANDLE       task_handle,
+                            KAL_TASK_REG_HANDLE   task_reg_handle,
+                            RTOS_ERR             *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(0u);
+        }
+
+        if (KAL_TASK_REG_HANDLE_IS_NULL(task_reg_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return (0u);
+        }
+    #endif
+
+    #if (OS_TASK_REG_TBL_SIZE > 0u)
+    {
+        KAL_TASK_REG  *p_task_reg;
+        CPU_INT08U     task_prio;
+        CPU_INT32U     ret_val;
+        CPU_INT08U     err_os;
+
+
+        p_task_reg = (KAL_TASK_REG *)task_reg_handle.TaskRegObjPtr;
+
+        if (KAL_TASK_HANDLE_IS_NULL(task_handle) == DEF_YES) {
+            task_prio = OS_PRIO_SELF;                           /* Use cur task if no task handle is provided.          */
+        } else {
+                                                                /* Get prio from task handle provided.                  */
+            task_prio = ((KAL_TASK *)task_handle.TaskObjPtr)->Prio;
+        }
+
+        ret_val = OSTaskRegGet(task_prio,
+                               p_task_reg->Id,
+                              &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return (ret_val);
+    }
+    #else
+        (void)task_handle;
+        (void)task_reg_handle;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (0u);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_TaskRegSet()
+*
+* Description : Set value of task register.
+*
+* Argument(s) : task_handle     Handle of the task associated to the task register. Current task is used if NULL.
+*
+*               task_reg_handle Handle of the task register to write to.
+*
+*               val             Value to write in the task register.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Task register handle is NULL.
+*                                   RTOS_ERR_INVALID_ARG        Handle specified is invalid.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_TaskRegSet (KAL_TASK_HANDLE       task_handle,
+                      KAL_TASK_REG_HANDLE   task_reg_handle,
+                      CPU_INT32U            val,
+                      RTOS_ERR             *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_TASK_REG_HANDLE_IS_NULL(task_reg_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if (OS_TASK_REG_TBL_SIZE > 0u)
+    {
+        KAL_TASK_REG  *p_task_reg;
+        CPU_INT08U     task_prio;
+        CPU_INT08U     err_os;
+
+
+        p_task_reg = (KAL_TASK_REG *)task_reg_handle.TaskRegObjPtr;
+
+        if (KAL_TASK_HANDLE_IS_NULL(task_handle) == DEF_YES) {
+            task_prio = OS_PRIO_SELF;                           /* Use cur task if no task handle is provided.          */
+        } else {
+                                                                /* Get prio from task handle provided.                  */
+            task_prio = ((KAL_TASK *)task_handle.TaskObjPtr)->Prio;
+        }
+
+        OSTaskRegSet(task_prio,
+                     p_task_reg->Id,
+                     val,
+                    &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else
+        (void)task_handle;
+        (void)task_reg_handle;
+        (void)val;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_TickGet()
+*
+* Description : Get value of OS' tick counter.
+*
+* Argument(s) : p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*
+* Return(s)   : OS tick counter's value.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TICK  KAL_TickGet (RTOS_ERR  *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(0u);
+        }
+    #endif
+
+    #if (OS_TIME_GET_SET_EN == DEF_ENABLED)
+    {
+        KAL_TICK  tick_cnt;
+
+
+        tick_cnt = OSTimeGet();
+
+       *p_err = RTOS_ERR_NONE;
+
+        return (tick_cnt);
+    }
+    #else
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (0u);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            LOCAL FUNCTIONS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                         KAL_TmrFnctWrapper()
+*
+* Description : Wrapper function for timer callback.
+*
+* Argument(s) : p_tmr_os        Pointer to OS timer object.
+*
+*               p_arg           Pointer to KAL timer object.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+#if (OS_TMR_EN == DEF_ENABLED)
+static  void  KAL_TmrFnctWrapper (void  *p_tmr_os,
+                                  void  *p_arg)
+{
+    KAL_TMR  *p_tmr;
+
+
+    (void)p_tmr_os;
+
+    p_tmr = (KAL_TMR *)p_arg;
+    p_tmr->CallbackFnct(p_tmr->CallbackArg);
+}
+#endif
+
+
+/*
+*********************************************************************************************************
+*                                            KAL_msToTicks()
+*
+* Description : Convert milliseconds value in tick value.
+*
+* Argument(s) : ms              Millisecond value to convert.
+*
+* Return(s)   : Number of ticks corresponding to the millisecond value, rounded up, if needed.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+static  KAL_TICK  KAL_msToTicks (CPU_INT32U  ms)
+{
+           KAL_TICK    ticks;
+#if  ((OS_TICKS_PER_SEC          >= 1000u) && \
+      (OS_TICKS_PER_SEC %  1000u ==    0u))
+    const  CPU_INT08U  mult = OS_TICKS_PER_SEC / 1000u;
+#endif
+
+
+    #if  ((OS_TICKS_PER_SEC          >= 1000u) && \
+          (OS_TICKS_PER_SEC %  1000u ==    0u))                 /* Optimize calc if possible for often used vals.       */
+        ticks =    ms * mult;
+    #elif (OS_TICKS_PER_SEC ==  100u)
+        ticks =  ((ms +  9u) /  10u);
+    #elif (OS_TICKS_PER_SEC ==   10u)
+        ticks =  ((ms + 99u) / 100u);
+    #else                                                       /* General formula.                                     */
+        ticks = (((ms * OS_TICKS_PER_SEC)  + 1000u - 1u) / 1000u);
+    #endif
+
+    return (ticks);
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_ErrConvert()
+*
+* Description : Convert OS errors in KAL errors.
+*
+* Argument(s) : err_os          Error value used by the OS.
+*
+* Return(s)   : KAL error.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+static  RTOS_ERR  KAL_ErrConvert (CPU_INT08U  err_os)
+{
+    RTOS_ERR  err_rtos;
+
+
+    switch (err_os) {
+        case OS_ERR_NONE:
+             err_rtos = RTOS_ERR_NONE;
+             break;
+
+
+        case OS_ERR_EVENT_TYPE:
+        case OS_ERR_INVALID_OPT:
+        case OS_ERR_ID_INVALID:
+        case OS_ERR_PNAME_NULL:
+        case OS_ERR_PRIO_EXIST:
+        case OS_ERR_PRIO_INVALID:
+        case OS_ERR_TASK_DEL:
+        case OS_ERR_TASK_DEL_IDLE:
+        case OS_ERR_TASK_NOT_EXIST:
+        case OS_ERR_TMR_INACTIVE:
+        case OS_ERR_TMR_INVALID_DLY:
+        case OS_ERR_TMR_INVALID_TYPE:
+        case OS_ERR_TMR_INVALID:
+             err_rtos = RTOS_ERR_INVALID_ARG;
+             break;
+
+
+        case OS_ERR_PEVENT_NULL:
+             err_rtos = RTOS_ERR_NULL_PTR;
+             break;
+
+
+        case OS_ERR_PEND_LOCKED:
+        case OS_ERR_TASK_WAITING:
+        case OS_ERR_TMR_INVALID_PERIOD:
+        case OS_ERR_TMR_INVALID_OPT:
+        case OS_ERR_TMR_INVALID_STATE:
+             err_rtos = RTOS_ERR_OS;
+             break;
+
+
+        case OS_ERR_TIMEOUT:
+             err_rtos = RTOS_ERR_TIMEOUT;
+             break;
+
+
+        case OS_ERR_PEND_ABORT:
+             err_rtos = RTOS_ERR_ABORT;
+             break;
+
+
+        case OS_ERR_Q_EMPTY:
+             err_rtos = RTOS_ERR_WOULD_BLOCK;
+             break;
+
+
+        case OS_ERR_PEND_ISR:
+        case OS_ERR_DEL_ISR:
+        case OS_ERR_NAME_SET_ISR:
+        case OS_ERR_TASK_CREATE_ISR:
+        case OS_ERR_TASK_DEL_ISR:
+        case OS_ERR_TMR_ISR:
+             err_rtos = RTOS_ERR_ISR;
+             break;
+
+
+        case OS_ERR_SEM_OVF:
+             err_rtos = RTOS_ERR_WOULD_OVF;
+             break;
+
+
+        case OS_ERR_Q_FULL:
+        case OS_ERR_NO_MORE_ID_AVAIL:
+        case OS_ERR_TMR_NON_AVAIL:
+             err_rtos = RTOS_ERR_NO_MORE_RSRC;
+             break;
+
+
+        default:
+             err_rtos = RTOS_ERR_OS;
+             break;
+    }
+
+    return (err_rtos);
+}

+ 2663 - 0
KAL/uCOS-III/kal.c

@@ -0,0 +1,2663 @@
+/*
+*********************************************************************************************************
+*                                              uC/Common
+*                                 Common Features for Micrium Stacks
+*
+*                    Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
+*
+*                                 SPDX-License-Identifier: APACHE-2.0
+*
+*               This software is subject to an open source license and is distributed by
+*                Silicon Laboratories Inc. pursuant to the terms of the Apache License,
+*                    Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
+*
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*
+*                             uC/Common - Kernel Abstraction Layer (KAL)
+*                                              uCOS-III
+*
+* Filename : kal.c
+* Version  : V1.02.00
+*********************************************************************************************************
+* Note(s)  : (1) 'goto' statements were used in this software module. Their usage
+*                is restricted to cleanup purposes in exceptional program flow (e.g.
+*                error handling), in compliance with CERT MEM12-C and MISRA C:2012
+*                rules 15.2, 15.3 and 15.4.
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                             INCLUDE FILES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#define  MICRIUM_SOURCE
+#define  KAL_MODULE
+
+#include  "../kal.h"
+#include  <lib_math.h>
+#include  <lib_mem.h>
+#include  <Source/os.h>
+#include  <os_cfg.h>
+#include  <os_cfg_app.h>
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                             LOCAL DEFINES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#define  KAL_CFG_ARG_CHK_EXT_EN                 OS_CFG_ARG_CHK_EN
+
+#define  KAL_CFG_TASK_STK_SIZE_PCT_FULL       90u
+
+#define  KAL_INIT_STATUS_NONE                   0u
+#define  KAL_INIT_STATUS_OK                     1u
+#define  KAL_INIT_STATUS_FAIL                   2u
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            LOCAL CONSTANTS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+KAL_CPP_EXT  const  CPU_INT32U           KAL_Version           =  10000u;
+KAL_CPP_EXT  const  KAL_TICK_RATE_HZ     KAL_TickRate          =  OS_CFG_TICK_RATE_HZ;
+
+KAL_CPP_EXT  const  KAL_TASK_HANDLE      KAL_TaskHandleNull    = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_LOCK_HANDLE      KAL_LockHandleNull    = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_SEM_HANDLE       KAL_SemHandleNull     = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_TMR_HANDLE       KAL_TmrHandleNull     = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_Q_HANDLE         KAL_QHandleNull       = {DEF_NULL};
+KAL_CPP_EXT  const  KAL_TASK_REG_HANDLE  KAL_TaskRegHandleNull = {DEF_NULL};
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                           LOCAL DATA TYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+                                                                /* ------------------ KAL TASK TYPE ------------------- */
+typedef  struct  kal_task {
+           OS_TCB       TCB;                                    /* TCB for OS-III.                                      */
+
+           CPU_STK     *StkBasePtr;                             /* Task stack base ptr.                                 */
+           CPU_INT32U   StkSizeBytes;                           /* Task stack size (in bytes).                          */
+
+    const  CPU_CHAR    *NamePtr;                                /* Task name string.                                    */
+} KAL_TASK;
+
+                                                                /* ------------------- KAL LOCK TYPE ------------------ */
+#if (OS_CFG_MUTEX_EN == DEF_ENABLED)
+typedef  struct  kal_lock {
+    OS_MUTEX    Mutex;                                          /* OS-III mutex obj.                                    */
+    CPU_INT08U  OptFlags;                                       /* Opt flags associated with this lock.                 */
+} KAL_LOCK;
+#endif
+
+                                                                /* ------------------- KAL TMR TYPE ------------------- */
+#if (OS_CFG_TMR_EN == DEF_ENABLED)
+typedef  struct  kal_tmr {
+    OS_TMR    Tmr;                                              /* OS-III tmr obj.                                      */
+
+    void    (*CallbackFnct)(void  *p_arg);                      /* Tmr registered callback fnct.                        */
+    void     *CallbackArg;                                      /* Arg to pass to callback fnct.                        */
+} KAL_TMR;
+#endif
+
+                                                                /* ---------------- KAL TASK REG TYPE ----------------- */
+#if (OS_CFG_TASK_REG_TBL_SIZE > 0u)
+typedef  struct  kal_task_reg {
+    OS_REG_ID  Id;                                              /* Id of the task reg.                                  */
+} KAL_TASK_REG;
+#endif
+
+                                                                /* -------------- KAL INTERNAL DATA TYPE -------------- */
+typedef  struct  kal_data {
+    MEM_SEG       *MemSegPtr;                                   /* Mem Seg to alloc from.                               */
+
+#if (OS_CFG_MUTEX_EN == DEF_ENABLED)
+    MEM_DYN_POOL   MutexPool;                                   /* Dyn mem pool used to alloc mutex.                    */
+#endif
+
+#if (OS_CFG_SEM_EN == DEF_ENABLED)
+    MEM_DYN_POOL   SemPool;                                     /* Dyn mem pool used to alloc sems.                     */
+#endif
+
+#if (OS_CFG_TMR_EN == DEF_ENABLED)
+    MEM_DYN_POOL   TmrPool;                                     /* Dyn mem pool used to alloc tmrs.                     */
+#endif
+
+#if (OS_CFG_TASK_REG_TBL_SIZE > 0u)
+    MEM_DYN_POOL   TaskRegPool;                                 /* Dyn mem pool used to alloc task regs.                */
+#endif
+} KAL_DATA;
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                              LOCAL TABLES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                         LOCAL GLOBAL VARIABLES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+static            KAL_DATA     *KAL_DataPtr    = DEF_NULL;
+
+static            CPU_BOOLEAN   KAL_IsInit     = DEF_NO;
+static  volatile  CPU_INT08U    KAL_InitStatus = KAL_INIT_STATUS_NONE;
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                       LOCAL FUNCTION PROTOTYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#if (OS_CFG_TMR_EN == DEF_ENABLED)
+static  void      KAL_TmrFnctWrapper(void        *p_tmr_os,
+                                     void        *p_arg);
+#endif
+
+static  KAL_TICK  KAL_msToTicks     (CPU_INT32U   ms);
+
+static  RTOS_ERR  KAL_ErrConvert    (OS_ERR       err_os);
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                       LOCAL CONFIGURATION ERRORS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            GLOBAL FUNCTIONS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                         KAL CORE API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                              KAL_Init()
+*
+* Description : Initialize the Kernel Abstraction Layer.
+*
+* Argument(s) : p_cfg       Pointer to KAL configuration structure.
+*
+*               p_err       Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_OS                 Concurrent initialization failed.
+*                                   RTOS_ERR_ALREADY_INIT       Already initialized and p_cfg is not NULL.
+*                                   RTOS_ERR_ALLOC              Memory segment allocation failed.
+*                                   RTOS_ERR_INIT               Memory pool initialization failed.
+*
+* Return(s)   : none.
+*
+* Note(s)     : (1) This function must be called prior to any product initialization function if the
+*                   application needs to specify a memory segment.
+*********************************************************************************************************
+*/
+
+void  KAL_Init (KAL_CFG   *p_cfg,
+                RTOS_ERR  *p_err)
+{
+    MEM_SEG  *p_seg;
+    OS_ERR    err_os;
+    LIB_ERR   err_lib;
+    CPU_SR_ALLOC();
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+    #endif
+
+    CPU_CRITICAL_ENTER();
+    if (KAL_IsInit == DEF_YES) {                                /* Chk if KAL already init. See note #1.                */
+        CPU_INT08U  init_status = KAL_InitStatus;
+
+
+        CPU_CRITICAL_EXIT();
+
+        while (init_status == KAL_INIT_STATUS_NONE) {           /* Wait until init is done before returning.            */
+            OSTimeDly(100u,
+                      OS_OPT_TIME_DLY,
+                     &err_os);
+            (void)err_os;
+            CPU_CRITICAL_ENTER();
+            init_status = KAL_InitStatus;
+            CPU_CRITICAL_EXIT();
+        }
+        if (init_status == KAL_INIT_STATUS_OK) {                /* Check resulting init status.                         */
+            if (p_cfg == DEF_NULL) {
+               *p_err = RTOS_ERR_NONE;                          /* KAL_Init() can be called many times if no cfg.       */
+            } else {
+               *p_err = RTOS_ERR_ALREADY_INIT;                  /* If a cfg is given and KAL is already init, set err.  */
+            }
+        } else {
+           *p_err = RTOS_ERR_OS;                                /* Concurrent init failed.                              */
+        }
+        return;
+    }
+
+    KAL_IsInit = DEF_YES;                                       /* Prevent another init, even in case of err.           */
+    CPU_CRITICAL_EXIT();
+
+    p_seg = DEF_NULL;
+    if (p_cfg != DEF_NULL) {                                    /* Load cfg if given.                                   */
+        p_seg = p_cfg->MemSegPtr;
+    }
+
+    KAL_DataPtr = (KAL_DATA *)Mem_SegAlloc("KAL internal data",
+                                            p_seg,
+                                            sizeof(KAL_DATA),
+                                           &err_lib);
+    if (err_lib != LIB_MEM_ERR_NONE) {
+       *p_err = RTOS_ERR_ALLOC;
+        goto end_err;
+    }
+
+    KAL_DataPtr->MemSegPtr = p_seg;
+
+    #if (OS_CFG_MUTEX_EN == DEF_ENABLED)
+        Mem_DynPoolCreate("KAL mutex pool",
+                          &KAL_DataPtr->MutexPool,
+                           KAL_DataPtr->MemSegPtr,
+                           sizeof(KAL_LOCK),
+                           sizeof(CPU_ALIGN),
+                           0u,
+                           LIB_MEM_BLK_QTY_UNLIMITED,
+                          &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_INIT;
+            goto end_err;
+        }
+    #endif
+
+    #if (OS_CFG_SEM_EN == DEF_ENABLED)
+        Mem_DynPoolCreate("KAL sem pool",
+                          &KAL_DataPtr->SemPool,
+                           KAL_DataPtr->MemSegPtr,
+                           sizeof(OS_SEM),
+                           sizeof(CPU_ALIGN),
+                           0u,
+                           LIB_MEM_BLK_QTY_UNLIMITED,
+                          &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_INIT;
+            goto end_err;
+        }
+    #endif
+
+    #if (OS_CFG_TMR_EN == DEF_ENABLED)
+        Mem_DynPoolCreate("KAL tmr pool",
+                          &KAL_DataPtr->TmrPool,
+                           KAL_DataPtr->MemSegPtr,
+                           sizeof(KAL_TMR),
+                           sizeof(CPU_ALIGN),
+                           0u,
+                           LIB_MEM_BLK_QTY_UNLIMITED,
+                          &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_INIT;
+            goto end_err;
+        }
+    #endif
+
+    #if (OS_CFG_TASK_REG_TBL_SIZE > 0u)
+        Mem_DynPoolCreate("KAL task reg pool",
+                          &KAL_DataPtr->TaskRegPool,
+                           KAL_DataPtr->MemSegPtr,
+                           sizeof(KAL_TASK_REG),
+                           sizeof(CPU_ALIGN),
+                           0u,
+                           LIB_MEM_BLK_QTY_UNLIMITED,
+                          &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_INIT;
+            goto end_err;
+        }
+    #endif
+
+    CPU_CRITICAL_ENTER();
+    KAL_InitStatus = KAL_INIT_STATUS_OK;
+    CPU_CRITICAL_EXIT();
+
+   *p_err = RTOS_ERR_NONE;
+
+    return;
+
+end_err:                                                        /* Init failed. Handle vars for other concurrent init.  */
+    CPU_CRITICAL_ENTER();
+    KAL_InitStatus = KAL_INIT_STATUS_FAIL;                      /* Indicate potential concurrent init that it failed.   */
+    CPU_CRITICAL_EXIT();
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                          KAL_FeatureQuery()
+*
+* Description : Check if specified feature is available.
+*
+* Argument(s) : feature     Feature to query.
+*
+*               opt         Option associated with the feature requested.
+*
+* Return(s)   : DEF_YES, if feature is available.
+*
+*               DEF_NO,  otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+CPU_BOOLEAN  KAL_FeatureQuery (KAL_FEATURE  feature,
+                               KAL_OPT      opt)
+{
+    CPU_BOOLEAN  is_en;
+
+
+    (void)opt;
+
+    is_en = DEF_NO;
+
+    switch (feature) {
+        case KAL_FEATURE_TASK_CREATE:                           /* ---------------------- TASKS ----------------------- */
+             is_en = DEF_YES;
+             break;
+
+
+        case KAL_FEATURE_TASK_DEL:
+             #if (OS_CFG_TASK_DEL_EN == DEF_ENABLED)
+                 is_en = DEF_YES;
+             #endif
+             break;
+
+
+#if (OS_CFG_MUTEX_EN == DEF_ENABLED)                            /* ----------------------- LOCKS ---------------------- */
+        case KAL_FEATURE_LOCK_CREATE:
+        case KAL_FEATURE_LOCK_ACQUIRE:
+        case KAL_FEATURE_LOCK_RELEASE:
+             is_en = DEF_YES;
+             break;
+
+
+        case KAL_FEATURE_LOCK_DEL:
+             #if (OS_CFG_MUTEX_DEL_EN == DEF_ENABLED)
+                 is_en = DEF_YES;
+             #endif
+             break;
+#endif /* OS_CFG_MUTEX_EN */
+
+
+#if (OS_CFG_SEM_EN == DEF_ENABLED)                              /* ----------------------- SEMS ----------------------- */
+        case KAL_FEATURE_SEM_CREATE:
+        case KAL_FEATURE_SEM_PEND:
+        case KAL_FEATURE_SEM_POST:
+             is_en = DEF_YES;
+             break;
+
+
+        case KAL_FEATURE_SEM_ABORT:
+             #if (OS_CFG_SEM_PEND_ABORT_EN == DEF_ENABLED)
+                 is_en = DEF_YES;
+             #endif
+             break;
+
+
+        case KAL_FEATURE_SEM_SET:
+             #if (OS_CFG_SEM_SET_EN == DEF_ENABLED)
+                 is_en = DEF_YES;
+             #endif
+             break;
+
+
+        case KAL_FEATURE_SEM_DEL:
+             #if (OS_CFG_SEM_DEL_EN == DEF_ENABLED)
+                 is_en = DEF_YES;
+             #endif
+             break;
+#endif /* OS_CFG_SEM_EN */
+
+
+        case KAL_FEATURE_TMR:                                   /* ----------------------- TMRS ----------------------- */
+             #if (OS_CFG_TMR_EN == DEF_ENABLED)
+                 is_en = DEF_YES;
+             #endif
+             break;
+
+
+        case KAL_FEATURE_Q_CREATE:                              /* ---------------------- QUEUES ---------------------- */
+        case KAL_FEATURE_Q_PEND:
+        case KAL_FEATURE_Q_POST:
+             #if (OS_CFG_Q_EN == DEF_ENABLED)
+                 is_en = DEF_YES;
+             #endif
+             break;
+
+
+        case KAL_FEATURE_DLY:                                   /* ----------------------- DLYS ----------------------- */
+             is_en = DEF_YES;
+             break;
+
+
+        case KAL_FEATURE_TASK_REG:                              /* ------------------- TASK STORAGE ------------------- */
+             #if (OS_CFG_TASK_REG_TBL_SIZE > 0u)
+                 is_en = DEF_YES;
+             #endif
+             break;
+
+
+        case KAL_FEATURE_TICK_GET:                              /* ------------------- TICK CTR INFO ------------------ */
+             is_en = DEF_YES;
+             break;
+
+
+        default:
+             break;
+    }
+
+    return (is_en);
+}
+
+
+/*
+*********************************************************************************************************
+*                                         TASK API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                            KAL_TaskAlloc()
+*
+* Description : Allocate a task object and its stack.
+*
+* Argument(s) : p_name          Pointer to name of the task.
+*
+*               p_stk_base      Pointer to start of task stack. If NULL, the stack will be allocated from
+*                               the KAL memory segment.
+*
+*               stk_size_bytes  Size (in bytes) of the task stack.
+*
+*               p_cfg           Pointer to KAL task configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_INVALID_ARG        Specified stack size is invalid.
+*                                   RTOS_ERR_NOT_SUPPORTED      'p_cfg' parameter was not NULL.
+*                                   RTOS_ERR_ALLOC              Task stack or control block allocation failed.
+*
+* Return(s)   : Allocated task's handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TASK_HANDLE  KAL_TaskAlloc (const  CPU_CHAR          *p_name,
+                                       void              *p_stk_base,
+                                       CPU_SIZE_T         stk_size_bytes,
+                                       KAL_TASK_EXT_CFG  *p_cfg,
+                                       RTOS_ERR          *p_err)
+{
+    KAL_TASK_HANDLE   handle = KAL_TaskHandleNull;
+    KAL_TASK         *p_task;
+    CPU_ADDR          stk_addr;
+    CPU_ADDR          stk_addr_aligned;
+    CPU_SIZE_T        actual_stk_size_bytes;
+    LIB_ERR           err_lib;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+
+        if (stk_size_bytes < (OS_CFG_STK_SIZE_MIN * sizeof(CPU_STK))) {
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return (handle);
+        }
+
+        if (p_cfg != DEF_NULL) {                                /* Make sure no unsupported cfg recv.                   */
+           *p_err = RTOS_ERR_NOT_SUPPORTED;
+            return (handle);
+        }
+    #else
+        (void)p_cfg;
+    #endif
+
+    if (p_stk_base == DEF_NULL) {                               /* Must alloc task stk on mem seg.                      */
+        stk_addr_aligned = (CPU_ADDR)Mem_SegAllocExt("KAL task stk",
+                                                      KAL_DataPtr->MemSegPtr,
+                                                      stk_size_bytes,
+                                                      CPU_CFG_STK_ALIGN_BYTES,
+                                                      DEF_NULL,
+                                                     &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_ALLOC;
+            return (handle);
+        }
+        actual_stk_size_bytes = stk_size_bytes;
+    } else {
+                                                                /* Align stk ptr, if needed.                            */
+        stk_addr              = (CPU_ADDR)p_stk_base;
+        stk_addr_aligned      =  MATH_ROUND_INC_UP_PWR2(stk_addr, CPU_CFG_STK_ALIGN_BYTES);
+        actual_stk_size_bytes =  stk_size_bytes - (stk_addr_aligned - stk_addr);
+    }
+
+    p_task = (KAL_TASK *)Mem_SegAlloc("KAL task",
+                                       KAL_DataPtr->MemSegPtr,
+                                       sizeof(KAL_TASK),
+                                      &err_lib);
+    if (err_lib != LIB_MEM_ERR_NONE) {
+       *p_err = RTOS_ERR_ALLOC;
+        return (handle);
+    }
+
+    p_task->StkBasePtr   = (CPU_STK *)stk_addr_aligned;
+    p_task->StkSizeBytes =  actual_stk_size_bytes;
+    p_task->NamePtr      =  p_name;
+    handle.TaskObjPtr    = (void *)p_task;
+
+   *p_err = RTOS_ERR_NONE;
+
+    return (handle);
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_TaskCreate()
+*
+* Description : Create and start a task.
+*
+* Argument(s) : task_handle     Handle of the task to create.
+*
+*               p_fnct          Pointer to task function.
+*
+*               p_task_arg      Pointer to argument that will be passed to task function (can be DEF_NULL).
+*
+*               prio            Task priority.
+*
+*               p_cfg           Pointer to KAL task configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_SUPPORTED      'p_cfg' parameter was not NULL.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Invalid argument passed to function.
+*                                   RTOS_ERR_ISR                Function called from an ISR context.
+*
+* Return(s)   : none.
+*
+* Note(s)     : (1) The task must be allocated prior to this call using KAL_TaskAlloc().
+*********************************************************************************************************
+*/
+
+void  KAL_TaskCreate (KAL_TASK_HANDLE     task_handle,
+                      void              (*p_fnct)(void  *p_arg),
+                      void               *p_task_arg,
+                      CPU_INT08U          prio,
+                      KAL_TASK_EXT_CFG   *p_cfg,
+                      RTOS_ERR           *p_err)
+{
+    KAL_TASK      *p_task;
+    CPU_STK_SIZE   stk_size_words;
+    CPU_STK_SIZE   stk_limit;
+    OS_ERR         err_os;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_TASK_HANDLE_IS_NULL(task_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+
+        if (p_cfg != DEF_NULL) {                                /* Make sure no unsupported cfg recv.                   */
+           *p_err = RTOS_ERR_NOT_SUPPORTED;
+            return;
+        }
+    #else
+        (void)p_cfg;
+    #endif
+
+    p_task         = (KAL_TASK *)task_handle.TaskObjPtr;
+    stk_size_words =  p_task->StkSizeBytes / sizeof(CPU_STK);
+    stk_limit      = (stk_size_words * (100u - KAL_CFG_TASK_STK_SIZE_PCT_FULL)) / 100u;
+
+    OSTaskCreate(&p_task->TCB,
+      (CPU_CHAR *)p_task->NamePtr,
+                  p_fnct,
+                  p_task_arg,
+                  prio,
+                  p_task->StkBasePtr,
+                  stk_limit,
+                  stk_size_words,
+                  0u,
+                  0u,
+                  DEF_NULL,
+                 (OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
+                 &err_os);
+    if (err_os == OS_ERR_NONE) {
+       *p_err = RTOS_ERR_NONE;
+    } else {
+       *p_err = KAL_ErrConvert(err_os);
+    }
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_TaskDel()
+*
+* Description : Delete a task.
+*
+* Argument(s) : task_handle     Handle of the task to delete.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Invalid argument passed to function.
+*                                   RTOS_ERR_ISR                Function called from an ISR context.
+*                                   RTOS_ERR_OS                 Generic OS error.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_TaskDel (KAL_TASK_HANDLE   task_handle,
+                   RTOS_ERR         *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_TASK_HANDLE_IS_NULL(task_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if (OS_CFG_TASK_DEL_EN == DEF_ENABLED)
+    {
+        OS_TCB  *p_tcb;
+        OS_ERR   err_os;
+
+
+        p_tcb = &((KAL_TASK *)task_handle.TaskObjPtr)->TCB;     /* Get TCB from task handle provided.                   */
+
+        OSTaskDel(p_tcb,
+                 &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else
+        (void)task_handle;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                         LOCK API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                           KAL_LockCreate()
+*
+* Description : Create a lock, which is unlocked by default.
+*
+* Argument(s) : p_name          Pointer to name of the lock.
+*
+*               p_cfg           Pointer to KAL lock configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_ALLOC              Unable to allocate memory for lock.
+*                                   RTOS_ERR_ISR                Function called from an ISR context.
+*                                   RTOS_ERR_INVALID_ARG        Invalid argument passed to function.
+*
+* Return(s)   : Created lock handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_LOCK_HANDLE  KAL_LockCreate (const  CPU_CHAR          *p_name,
+                                        KAL_LOCK_EXT_CFG  *p_cfg,
+                                        RTOS_ERR          *p_err)
+{
+    KAL_LOCK_HANDLE  handle = KAL_LockHandleNull;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+    #endif
+
+    #if (OS_CFG_MUTEX_EN == DEF_ENABLED)
+    {
+        KAL_LOCK    *p_kal_lock;
+        CPU_INT08U   opt_flags;
+        LIB_ERR      err_lib;
+        OS_ERR       err_os;
+
+
+        p_kal_lock = (KAL_LOCK *)Mem_DynPoolBlkGet(&KAL_DataPtr->MutexPool,
+                                                   &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_ALLOC;
+            return (handle);
+        }
+
+        OSMutexCreate(           &p_kal_lock->Mutex,
+                      (CPU_CHAR *)p_name,
+                                 &err_os);
+        if (err_os == OS_ERR_NONE) {
+            if ((p_cfg                                                != DEF_NULL) &&
+                (DEF_BIT_IS_SET(p_cfg->Opt, KAL_OPT_CREATE_REENTRANT) == DEF_YES)) {
+                opt_flags = KAL_OPT_CREATE_REENTRANT;
+            } else {
+                opt_flags = KAL_OPT_CREATE_NON_REENTRANT;
+            }
+            p_kal_lock->OptFlags =  opt_flags;
+            handle.LockObjPtr    = (void *)p_kal_lock;
+           *p_err                =  RTOS_ERR_NONE;
+        } else {
+            Mem_DynPoolBlkFree(       &KAL_DataPtr->MutexPool,
+                               (void *)p_kal_lock,
+                                      &err_lib);
+            (void)err_lib;                                     /* Err ignored.                                         */
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return (handle);
+    }
+    #else
+        (void)p_name;
+        (void)p_cfg;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (handle);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_LockAcquire()
+*
+* Description : Acquire a lock.
+*
+* Argument(s) : lock_handle     Handle of the lock to acquire.
+*
+*               opt             Options available:
+*                                   KAL_OPT_PEND_NONE:          block until timeout expires or lock is available.
+*                                   KAL_OPT_PEND_BLOCKING:      block until timeout expires or lock is available.
+*                                   KAL_OPT_PEND_NON_BLOCKING:  return immediately even if lock is not available.
+*
+*               timeout_ms      Timeout, in milliseconds. A value of 0 will never timeout.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_ISR                Function called from an ISR context.
+*                                   RTOS_ERR_ABORT              Pend operation was aborted.
+*                                   RTOS_ERR_TIMEOUT            Operation timed-out.
+*                                   RTOS_ERR_OWNERSHIP          Calling task already owns the lock.
+*                                   RTOS_ERR_WOULD_BLOCK        KAL_OPT_PEND_NON_BLOCKING opt specified and
+*                                                               lock is not available.
+*                                   RTOS_ERR_OS                 Generic OS error.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_LockAcquire (KAL_LOCK_HANDLE   lock_handle,
+                       KAL_OPT           opt,
+                       CPU_INT32U        timeout_ms,
+                       RTOS_ERR         *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_LOCK_HANDLE_IS_NULL(lock_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+
+        if (DEF_BIT_IS_SET_ANY(opt, ~(KAL_OPT_PEND_NONE | KAL_OPT_PEND_NON_BLOCKING)) == DEF_YES) {
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return;
+        }
+    #endif
+
+    #if (OS_CFG_MUTEX_EN == DEF_ENABLED)
+    {
+        KAL_LOCK    *p_kal_lock;
+        CPU_INT32U   timeout_ticks;
+        OS_OPT       opt_os;
+        OS_ERR       err_os;
+
+
+        if (timeout_ms != KAL_TIMEOUT_INFINITE) {
+            timeout_ticks = KAL_msToTicks(timeout_ms);
+        } else {
+            timeout_ticks = 0u;
+        }
+
+        opt_os = OS_OPT_NONE;
+        if (DEF_BIT_IS_CLR(opt, KAL_OPT_PEND_NON_BLOCKING) == DEF_YES) {
+            opt_os |= OS_OPT_PEND_BLOCKING;
+        } else {
+            opt_os |= OS_OPT_PEND_NON_BLOCKING;
+        }
+
+        p_kal_lock = (KAL_LOCK *)lock_handle.LockObjPtr;
+        OSMutexPend(&p_kal_lock->Mutex,
+                     timeout_ticks,
+                     opt_os,
+                     DEF_NULL,
+                    &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else if (err_os != OS_ERR_MUTEX_OWNER) {
+           *p_err = KAL_ErrConvert(err_os);
+        } else {
+            if (DEF_BIT_IS_SET(p_kal_lock->OptFlags, KAL_OPT_CREATE_REENTRANT) == DEF_YES) {
+               *p_err = RTOS_ERR_NONE;
+            } else {
+                OSMutexPost(&p_kal_lock->Mutex,                 /* Post mutex to decrement nesting ctr.                 */
+                             OS_OPT_POST_NONE,
+                            &err_os);
+                (void)err_os;
+               *p_err = RTOS_ERR_OWNERSHIP;
+            }
+        }
+
+        return;
+    }
+    #else
+        (void)lock_handle;
+        (void)opt;
+        (void)timeout_ms;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_LockRelease()
+*
+* Description : Release a lock.
+*
+* Argument(s) : lock_handle     Handle of the lock to release.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Task releasing lock does not own lock.
+*                                   RTOS_ERR_ISR                Function called from an ISR context.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_LockRelease (KAL_LOCK_HANDLE   lock_handle,
+                       RTOS_ERR         *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_LOCK_HANDLE_IS_NULL(lock_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if (OS_CFG_MUTEX_EN == DEF_ENABLED)
+    {
+        KAL_LOCK  *p_kal_lock;
+        OS_ERR     err_os;
+
+
+        p_kal_lock = (KAL_LOCK *)lock_handle.LockObjPtr;
+        OSMutexPost(&p_kal_lock->Mutex,
+                     OS_OPT_POST_NONE,
+                    &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else if (err_os != OS_ERR_MUTEX_NESTING) {
+           *p_err = KAL_ErrConvert(err_os);
+        } else {
+            if (DEF_BIT_IS_SET(p_kal_lock->OptFlags, KAL_OPT_CREATE_REENTRANT) == DEF_YES) {
+               *p_err = RTOS_ERR_NONE;
+            } else {
+               *p_err = RTOS_ERR_OS;
+            }
+        }
+
+        return;
+    }
+    #else
+        (void)lock_handle;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_LockDel()
+*
+* Description : Delete a lock.
+*
+* Argument(s) : lock_handle     Handle of the lock to delete.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_ISR                Function was called from an ISR.
+*                                   RTOS_ERR_OS                 Generic OS error.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_LockDel (KAL_LOCK_HANDLE   lock_handle,
+                   RTOS_ERR         *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_LOCK_HANDLE_IS_NULL(lock_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if ((OS_CFG_MUTEX_EN     == DEF_ENABLED) && \
+         (OS_CFG_MUTEX_DEL_EN == DEF_ENABLED))                  /* Mutex and mutex del are avail.                       */
+    {
+        KAL_LOCK  *p_kal_lock;
+        OS_ERR     err_os;
+
+
+        p_kal_lock = (KAL_LOCK *)lock_handle.LockObjPtr;
+
+        (void)OSMutexDel(&p_kal_lock->Mutex,
+                          OS_OPT_DEL_ALWAYS,
+                         &err_os);
+        if (err_os == OS_ERR_NONE) {
+            LIB_ERR  err_lib;
+
+
+            Mem_DynPoolBlkFree(       &KAL_DataPtr->MutexPool,
+                               (void *)p_kal_lock,
+                                      &err_lib);
+            (void)err_lib;
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else                                                       /* Mutex or mutex del is not avail.                     */
+        (void)lock_handle;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                          SEM API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                            KAL_SemCreate()
+*
+* Description : Create a semaphore, with a count of 0.
+*
+* Argument(s) : p_name          Pointer to name of the semaphore.
+*
+*               p_cfg           Pointer to KAL semaphore configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NOT_SUPPORTED      'p_cfg' parameter was not NULL.
+*                                   RTOS_ERR_ALLOC              Unable to allocate memory for semaphore.
+*                                   RTOS_ERR_INVALID_ARG        Invalid argument passed to function.
+*                                   RTOS_ERR_ISR                Function called from an ISR context.
+*
+* Return(s)   : Created semaphore's handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_SEM_HANDLE  KAL_SemCreate (const  CPU_CHAR         *p_name,
+                                      KAL_SEM_EXT_CFG  *p_cfg,
+                                      RTOS_ERR         *p_err)
+{
+    KAL_SEM_HANDLE  handle = KAL_SemHandleNull;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+
+        if (p_cfg != DEF_NULL) {                                /* Make sure no unsupported cfg recv.                   */
+           *p_err = RTOS_ERR_NOT_SUPPORTED;
+            return (handle);
+        }
+    #else
+        (void)p_cfg;
+    #endif
+
+    #if (OS_CFG_SEM_EN == DEF_ENABLED)
+    {
+        OS_SEM   *p_sem;
+        LIB_ERR   err_lib;
+        OS_ERR    err_os;
+
+
+        p_sem = (OS_SEM *)Mem_DynPoolBlkGet(&KAL_DataPtr->SemPool,
+                                            &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_ALLOC;
+            return (handle);
+        }
+
+        OSSemCreate(            p_sem,
+                    (CPU_CHAR *)p_name,
+                                0u,
+                               &err_os);
+        if (err_os == OS_ERR_NONE) {
+            handle.SemObjPtr = (void *)p_sem;
+           *p_err            =  RTOS_ERR_NONE;
+        } else {
+            Mem_DynPoolBlkFree(       &KAL_DataPtr->SemPool,
+                               (void *)p_sem,
+                                      &err_lib);
+            (void)err_lib;
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return (handle);
+    }
+    #else
+        (void)p_name;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (handle);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemPend()
+*
+* Description : Pend on a semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to pend on.
+*
+*               opt             Options available:
+*                                   KAL_OPT_PEND_NONE:          block until timeout expires or semaphore is available.
+*                                   KAL_OPT_PEND_BLOCKING:      block until timeout expires or semaphore is available.
+*                                   KAL_OPT_PEND_NON_BLOCKING:  return immediately even if semaphore is not available.
+*
+*               timeout_ms      Timeout, in milliseconds. A value of 0 will never timeout.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_ABORT              Pend operation was aborted.
+*                                   RTOS_ERR_TIMEOUT            Operation timed-out.
+*                                   RTOS_ERR_ISR                Function was called from an ISR.
+*                                   RTOS_ERR_WOULD_BLOCK        KAL_OPT_PEND_NON_BLOCKING opt specified and
+*                                                               semaphore is not available.
+*                                   RTOS_ERR_OS                 Generic OS error.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPend (KAL_SEM_HANDLE   sem_handle,
+                   KAL_OPT          opt,
+                   CPU_INT32U       timeout_ms,
+                   RTOS_ERR        *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_SEM_HANDLE_IS_NULL(sem_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+
+        if (DEF_BIT_IS_SET_ANY(opt, ~(KAL_OPT_PEND_NONE | KAL_OPT_PEND_NON_BLOCKING)) == DEF_YES) {
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return;
+        }
+    #endif
+
+    #if (OS_CFG_SEM_EN == DEF_ENABLED)
+    {
+        CPU_INT32U  timeout_ticks;
+        OS_OPT      opt_os;
+        OS_ERR      err_os;
+
+
+        if (timeout_ms != KAL_TIMEOUT_INFINITE) {
+            timeout_ticks = KAL_msToTicks(timeout_ms);
+        } else {
+            timeout_ticks = 0u;
+        }
+
+        opt_os = OS_OPT_NONE;
+        if (DEF_BIT_IS_CLR(opt, KAL_OPT_PEND_NON_BLOCKING) == DEF_YES) {
+            opt_os |= OS_OPT_PEND_BLOCKING;
+        } else {
+            opt_os |= OS_OPT_PEND_NON_BLOCKING;
+        }
+
+        OSSemPend((OS_SEM *)sem_handle.SemObjPtr,
+                            timeout_ticks,
+                            opt_os,
+                            DEF_NULL,
+                           &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else
+        (void)sem_handle;
+        (void)opt;
+        (void)timeout_ms;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemPost()
+*
+* Description : Post a semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to post.
+*
+*               opt             Options available:
+*                                   KAL_OPT_POST_NONE:     wake only the highest priority task pending on semaphore.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_WOULD_OVF          Semaphore would overflow.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPost (KAL_SEM_HANDLE   sem_handle,
+                   KAL_OPT          opt,
+                   RTOS_ERR        *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_SEM_HANDLE_IS_NULL(sem_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+
+        if (opt != KAL_OPT_POST_NONE) {
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return;
+        }
+    #endif
+
+    #if (OS_CFG_SEM_EN == DEF_ENABLED)
+    {
+        OS_ERR  err_os;
+
+
+        OSSemPost((OS_SEM *)sem_handle.SemObjPtr,
+                            OS_OPT_POST_1,
+                           &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else
+        (void)sem_handle;
+        (void)opt;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                          KAL_SemPendAbort()
+*
+* Description : Abort given semaphore and resume all the tasks pending on it.
+*
+* Argument(s) : sem_handle      Handle of the sempahore to abort.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle specified is invalid.
+*                                   RTOS_ERR_ISR                Function called from an ISR context.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemPendAbort (KAL_SEM_HANDLE   sem_handle,
+                        RTOS_ERR        *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_SEM_HANDLE_IS_NULL(sem_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if ((OS_CFG_SEM_EN            == DEF_ENABLED) && \
+         (OS_CFG_SEM_PEND_ABORT_EN == DEF_ENABLED))
+    {
+        OS_ERR  err_os;
+
+
+        (void)OSSemPendAbort((OS_SEM *)sem_handle.SemObjPtr,
+                                       OS_OPT_PEND_ABORT_ALL,
+                                      &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else
+        (void)sem_handle;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemSet()
+*
+* Description : Set value of semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to set.
+*
+*               cnt             Count value to set semaphore.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle specified is invalid.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemSet (KAL_SEM_HANDLE   sem_handle,
+                  CPU_INT16U       cnt,
+                  RTOS_ERR        *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ------------------ VALIDATE ARGS ------------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_SEM_HANDLE_IS_NULL(sem_handle) == DEF_YES) {    /* Validate handle.                                     */
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if ((OS_CFG_SEM_EN      == DEF_ENABLED) && \
+         (OS_CFG_SEM_SET_EN  == DEF_ENABLED))
+    {
+        OS_ERR  err_os;
+
+
+        OSSemSet((OS_SEM *)sem_handle.SemObjPtr,
+                           cnt,
+                          &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else
+        (void)sem_handle;
+        (void)cnt;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_SemDel()
+*
+* Description : Delete a semaphore.
+*
+* Argument(s) : sem_handle      Handle of the semaphore to delete.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle specified is invalid.
+*                                   RTOS_ERR_ISR                Function was called from an ISR.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_SemDel (KAL_SEM_HANDLE   sem_handle,
+                  RTOS_ERR        *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_SEM_HANDLE_IS_NULL(sem_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if ((OS_CFG_SEM_EN     == DEF_ENABLED) && \
+         (OS_CFG_SEM_DEL_EN == DEF_ENABLED))
+    {
+        OS_SEM  *p_sem;
+        OS_ERR   err_os;
+
+
+        p_sem = (OS_SEM *)sem_handle.SemObjPtr;
+
+        (void)OSSemDel(p_sem,
+                       OS_OPT_DEL_ALWAYS,
+                      &err_os);
+        if (err_os == OS_ERR_NONE) {
+            LIB_ERR  err_lib;
+
+
+            Mem_DynPoolBlkFree(       &KAL_DataPtr->SemPool,
+                               (void *)p_sem,
+                                      &err_lib);
+            (void)err_lib;
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else
+        (void)sem_handle;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                          TMR API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                            KAL_TmrCreate()
+*
+* Description : Create a single-shot timer.
+*
+* Argument(s) : p_name          Pointer to name of the timer.
+*
+*               p_callback      Pointer to the callback function that will be called on completion of timer.
+*
+*               p_callback_arg  Argument passed to callback function.
+*
+*               interval_ms     If timer is 'one-shot', delay  used by the timer, in milliseconds.
+*                               If timer is 'periodic', period used by the timer, in milliseconds.
+*
+*               p_cfg           Pointer to KAL timer configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Null pointer passed to function.
+*                                   RTOS_ERR_ALLOC              Unable to allocate memory for semaphore.
+*                                   RTOS_ERR_INVALID_ARG        Invalid argument passed to function.
+*                                   RTOS_ERR_ISR                Function called from an ISR context.
+*                                   RTOS_ERR_OS                 Generic OS error.
+*
+* Return(s)   : Created timer handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TMR_HANDLE  KAL_TmrCreate (const  CPU_CHAR          *p_name,
+                                      void             (*p_callback)(void  *p_arg),
+                                      void              *p_callback_arg,
+                                      CPU_INT32U         interval_ms,
+                                      KAL_TMR_EXT_CFG   *p_cfg,
+                                      RTOS_ERR          *p_err)
+{
+    KAL_TMR_HANDLE  handle = KAL_TmrHandleNull;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+
+        if (p_callback == DEF_NULL) {                           /* Validate callback fnct ptr.                          */
+           *p_err = RTOS_ERR_NULL_PTR;
+            return (handle);
+        }
+
+        if (interval_ms == 0u) {                                /* Validate time.                                       */
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return (handle);
+        }
+
+        if (p_cfg != DEF_NULL) {
+            if (DEF_BIT_IS_SET_ANY(p_cfg->Opt, ~(KAL_OPT_TMR_NONE | KAL_OPT_TMR_PERIODIC)) == DEF_YES) {
+               *p_err = RTOS_ERR_INVALID_ARG;
+                return (handle);
+            }
+        }
+    #endif
+
+    #if (OS_CFG_TMR_EN == DEF_ENABLED)
+    {
+        KAL_TMR     *p_tmr;
+        CPU_INT32U   tmr_dly;
+        CPU_INT32U   tmr_period;
+        OS_OPT       opt_os;
+        KAL_TICK     ticks;
+        OS_ERR       err_os;
+        LIB_ERR      err_lib;
+        #if  ((OS_CFG_TMR_TASK_RATE_HZ         >= 1000u) && \
+              (OS_CFG_TMR_TASK_RATE_HZ % 1000u ==    0u))
+        const  CPU_INT08U   mult = OS_CFG_TMR_TASK_RATE_HZ / 1000u;
+        #endif
+
+
+        p_tmr  = (KAL_TMR *)Mem_DynPoolBlkGet(&KAL_DataPtr->TmrPool,
+                                              &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_ALLOC;
+            return (handle);
+        }
+
+        p_tmr->CallbackFnct = p_callback;
+        p_tmr->CallbackArg  = p_callback_arg;
+                                                                /* Calc nbr of tmr ticks (rounded up nearest int).      */
+        #if  ((OS_CFG_TMR_TASK_RATE_HZ         >= 1000u) && \
+              (OS_CFG_TMR_TASK_RATE_HZ % 1000u ==    0u))       /* Optimize calc if possible for often used vals.       */
+            ticks =    interval_ms * mult;
+        #elif (OS_CFG_TMR_TASK_RATE_HZ ==  100u)
+            ticks =  ((interval_ms +  9u) /  10u);
+        #elif (OS_CFG_TMR_TASK_RATE_HZ ==   10u)
+            ticks =  ((interval_ms + 99u) / 100u);
+        #else                                                   /* General formula.                                     */
+            ticks = (((interval_ms * OS_CFG_TMR_TASK_RATE_HZ)  + 1000u - 1u) / 1000u);
+        #endif
+                                                                /* Tmr is 'periodic'.                                   */
+        if ((p_cfg                                            != DEF_NULL) &&
+            (DEF_BIT_IS_SET(p_cfg->Opt, KAL_OPT_TMR_PERIODIC) == DEF_YES)) {
+            opt_os     = OS_OPT_TMR_PERIODIC;
+            tmr_dly    = 0u;
+            tmr_period = ticks;
+        } else {
+            opt_os     = OS_OPT_TMR_ONE_SHOT;                   /* Tmr is 'one-shot'.                                   */
+            tmr_dly    = ticks;
+            tmr_period = 0u;
+        }
+
+        OSTmrCreate(           &p_tmr->Tmr,                     /* Create tmr obj.                                      */
+                    (CPU_CHAR *)p_name,
+                                tmr_dly,
+                                tmr_period,
+                                opt_os,
+                                KAL_TmrFnctWrapper,
+                    (void     *)p_tmr,
+                               &err_os);
+        if (err_os == OS_ERR_NONE) {
+            handle.TmrObjPtr = p_tmr;
+           *p_err            = RTOS_ERR_NONE;
+        } else {
+            Mem_DynPoolBlkFree(&KAL_DataPtr->TmrPool,
+                                p_tmr,
+                               &err_lib);
+            (void)err_lib;
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return (handle);
+    }
+    #else
+        (void)p_name;
+        (void)p_callback;
+        (void)p_callback_arg;
+        (void)interval_ms;
+        (void)p_cfg;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (handle);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                            KAL_TmrStart()
+*
+* Description : Start timer.
+*
+* Argument(s) : tmr_handle      Handle of timer to start.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Null timer handle passed to function.
+*                                   RTOS_ERR_ISR                Function called from an ISR context.
+*                                   RTOS_ERR_OS                 Generic OS error.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_TmrStart (KAL_TMR_HANDLE   tmr_handle,
+                    RTOS_ERR        *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_TMR_HANDLE_IS_NULL(tmr_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if (OS_CFG_TMR_EN == DEF_ENABLED)
+    {
+        KAL_TMR  *p_tmr;
+        OS_ERR    err_os;
+
+
+        p_tmr = (KAL_TMR *)tmr_handle.TmrObjPtr;
+
+        OSTmrStart(&p_tmr->Tmr,
+                   &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else
+        (void)tmr_handle;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                           Q API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                             KAL_QCreate()
+*
+* Description : Create an empty queue.
+*
+* Argument(s) : p_name          Pointer to name of the queue.
+*
+*               max_msg_qty     Maximum number of message contained in the queue.
+*
+*               p_cfg           Pointer to KAL queue configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NOT_SUPPORTED      'p_cfg' parameter was not NULL.
+*                                   RTOS_ERR_ALLOC              Unable to allocate memory for queue.
+*                                   RTOS_ERR_ISR                Function called from an ISR context.
+*                                   RTOS_ERR_INVALID_ARG        Argument passed to function is invalid.
+*
+* Return(s)   : Created queue handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_Q_HANDLE  KAL_QCreate (const  CPU_CHAR       *p_name,
+                                  KAL_MSG_QTY     max_msg_qty,
+                                  KAL_Q_EXT_CFG  *p_cfg,
+                                  RTOS_ERR       *p_err)
+{
+    KAL_Q_HANDLE  handle = KAL_QHandleNull;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+
+        if (p_cfg != DEF_NULL) {                                /* Make sure no unsupported cfg recv.                   */
+           *p_err = RTOS_ERR_NOT_SUPPORTED;
+            return (handle);
+        }
+    #else
+        (void)p_cfg;
+    #endif
+
+    #if (OS_CFG_Q_EN == DEF_ENABLED)
+    {
+        OS_Q     *p_q;
+        LIB_ERR   err_lib;
+        OS_ERR    err_os;
+
+
+        p_q = (OS_Q *)Mem_SegAlloc("KAL Q",
+                                    KAL_DataPtr->MemSegPtr,
+                                    sizeof(OS_Q),
+                                   &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_ALLOC;
+            return (handle);
+        }
+
+        OSQCreate(            p_q,
+                  (CPU_CHAR *)p_name,
+                              max_msg_qty,
+                             &err_os);
+        if (err_os == OS_ERR_NONE) {
+            handle.QObjPtr = (void *)p_q;
+           *p_err          =  RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return (handle);
+    }
+    #else
+        (void)p_name;
+        (void)max_msg_qty;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (handle);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                              KAL_QPend()
+*
+* Description : Pend/get first message of queue.
+*
+* Argument(s) : q_handle        Handle of the queue to pend on.
+*
+*               opt             Options available:
+*                                   KAL_OPT_PEND_NONE:          block until timeout expires or message is available.
+*                                   KAL_OPT_PEND_BLOCKING:      block until timeout expires or message is available.
+*                                   KAL_OPT_PEND_NON_BLOCKING:  return immediately with or without message.
+*
+*               timeout_ms      Timeout, in milliseconds. A value of 0 will never timeout.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_ABORT              Pend operation was aborted.
+*                                   RTOS_ERR_TIMEOUT            Operation timed-out.
+*                                   RTOS_ERR_ISR                Function was called from an ISR.
+*                                   RTOS_ERR_WOULD_BLOCK        KAL_OPT_PEND_NON_BLOCKING opt specified and no
+*                                                               message is available.
+*                                   RTOS_ERR_OS                 Generic OS error.
+*
+* Return(s)   : Pointer to message obtained, if any, if no error.
+*
+*               Null pointer,                        otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  *KAL_QPend (KAL_Q_HANDLE   q_handle,
+                  KAL_OPT        opt,
+                  CPU_INT32U     timeout_ms,
+                  RTOS_ERR      *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(DEF_NULL);
+        }
+
+        if (KAL_Q_HANDLE_IS_NULL(q_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return (DEF_NULL);
+        }
+
+        if (DEF_BIT_IS_SET_ANY(opt, ~(KAL_OPT_PEND_NONE | KAL_OPT_PEND_NON_BLOCKING)) == DEF_YES) {
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return (DEF_NULL);
+        }
+    #endif
+
+    #if (OS_CFG_Q_EN == DEF_ENABLED)
+    {
+        void         *p_msg;
+        CPU_INT32U    timeout_ticks;
+        OS_MSG_SIZE   msg_size;
+        OS_OPT        opt_os;
+        OS_ERR        err_os;
+
+
+        if (timeout_ms != KAL_TIMEOUT_INFINITE) {
+            timeout_ticks = KAL_msToTicks(timeout_ms);
+        } else {
+            timeout_ticks = 0u;
+        }
+
+        opt_os = OS_OPT_NONE;
+        if (DEF_BIT_IS_CLR(opt, KAL_OPT_PEND_NON_BLOCKING) == DEF_YES) {
+            opt_os |= OS_OPT_PEND_BLOCKING;
+        } else {
+            opt_os |= OS_OPT_PEND_NON_BLOCKING;
+        }
+
+        p_msg = OSQPend((OS_Q *)q_handle.QObjPtr,
+                                timeout_ticks,
+                                opt_os,
+                               &msg_size,
+                                DEF_NULL,
+                               &err_os);
+        (void)msg_size;
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return (p_msg);
+    }
+    #else
+        (void)q_handle;
+        (void)opt;
+        (void)timeout_ms;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (DEF_NULL);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                              KAL_QPost()
+*
+* Description : Post message on queue.
+*
+* Argument(s) : q_handle        Handle of the queue on which to post message.
+*
+*               p_msg           Pointer to message to post.
+*
+*               opt             Options available:
+*                                   KAL_OPT_POST_NONE:     wake only the highest priority task pending on queue.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Handle contains a NULL/invalid pointer.
+*                                   RTOS_ERR_INVALID_ARG        Handle or options specified is invalid.
+*                                   RTOS_ERR_NO_MORE_RSRC       Queue cannot contain any more message,
+*                                                               no more message available.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_QPost (KAL_Q_HANDLE   q_handle,
+                 void          *p_msg,
+                 KAL_OPT        opt,
+                 RTOS_ERR      *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_Q_HANDLE_IS_NULL(q_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+
+        if (opt != KAL_OPT_POST_NONE) {
+           *p_err = RTOS_ERR_INVALID_ARG;
+            return;
+        }
+    #else
+        (void)opt;
+    #endif
+
+    #if (OS_CFG_Q_EN == DEF_ENABLED)                            /* Qs are available.                                    */
+    {
+        OS_ERR  err_os;
+
+
+        OSQPost((OS_Q *)q_handle.QObjPtr,
+                        p_msg,
+                        0u,
+                        OS_OPT_POST_1,
+                       &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else
+        (void)q_handle;
+        (void)p_msg;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                          DLY API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                               KAL_Dly()
+*
+* Description : Delay current task (in milliseconds).
+*
+* Argument(s) : dly_ms          Delay value, in milliseconds.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_Dly (CPU_INT32U  dly_ms)
+{
+    CPU_INT32U  dly_ticks;
+    OS_ERR      err_os;
+
+
+    dly_ticks = KAL_msToTicks(dly_ms);
+
+    OSTimeDly(dly_ticks,
+              OS_OPT_TIME_DLY,
+             &err_os);
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
+        switch (err_os) {
+            case OS_ERR_NONE:
+            case OS_ERR_TIME_ZERO_DLY:
+                 break;
+
+            case OS_ERR_OPT_INVALID:
+            case OS_ERR_SCHED_LOCKED:
+            case OS_ERR_TIME_DLY_ISR:
+            default:
+                 CPU_SW_EXCEPTION(;);
+                 break;
+        }
+    #else
+        (void)err_os;                                          /* Ignore err from OSTimeDly().                         */
+    #endif
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_DlyTick()
+*
+* Description : Delay current task (in ticks).
+*
+* Argument(s) : dly_ticks       Delay value, in ticks.
+*
+*               opt             Options available:
+*                                   KAL_OPT_DLY_NONE:       apply a 'normal' delay.
+*                                   KAL_OPT_DLY:            apply a 'normal' delay.
+*                                   KAL_OPT_DLY_PERIODIC:   apply a periodic delay.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_DlyTick (KAL_TICK  dly_ticks,
+                   KAL_OPT   opt)
+{
+    OS_OPT  opt_os;
+    OS_ERR  err_os;
+
+
+    if (DEF_BIT_IS_SET(opt, KAL_OPT_DLY_PERIODIC) == DEF_YES) {
+        opt_os = OS_OPT_TIME_PERIODIC;
+    } else {
+        opt_os = OS_OPT_TIME_DLY;
+    }
+
+    OSTimeDly(dly_ticks,
+              opt_os,
+             &err_os);
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
+        switch (err_os) {
+            case OS_ERR_NONE:
+            case OS_ERR_TIME_ZERO_DLY:
+                 break;
+
+            case OS_ERR_OPT_INVALID:
+            case OS_ERR_SCHED_LOCKED:
+            case OS_ERR_TIME_DLY_ISR:
+            default:
+                 CPU_SW_EXCEPTION(;);
+                 break;
+        }
+    #else
+        (void)err_os;                                          /* Ignore err from OSTimeDly().                         */
+    #endif
+
+    return;
+}
+
+
+/*
+*********************************************************************************************************
+*                                       TASK REG API FUNCTIONS
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                          KAL_TaskRegCreate()
+*
+* Description : Create a task register.
+*
+* Argument(s) : p_cfg           Pointer to KAL task register configuration structure.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NOT_SUPPORTED      'p_cfg' parameter was not NULL.
+*                                   RTOS_ERR_ALLOC              Unable to allocate memory for task register.
+*                                   RTOS_ERR_NO_MORE_RSRC       No more task register available.
+*
+* Return(s)   : Created task register's handle.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TASK_REG_HANDLE  KAL_TaskRegCreate (KAL_TASK_REG_EXT_CFG  *p_cfg,
+                                        RTOS_ERR              *p_err)
+{
+    KAL_TASK_REG_HANDLE  handle = KAL_TaskRegHandleNull;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(handle);
+        }
+
+        if (p_cfg != DEF_NULL) {                                /* Make sure no unsupported cfg recv.                   */
+           *p_err = RTOS_ERR_NOT_SUPPORTED;
+            return (handle);
+        }
+    #else
+        (void)p_cfg;
+    #endif
+
+    #if (OS_CFG_TASK_REG_TBL_SIZE > 0u)
+    {
+        KAL_TASK_REG  *p_task_reg;
+        LIB_ERR        err_lib;
+        OS_ERR         err_os;
+
+
+        p_task_reg = (KAL_TASK_REG *)Mem_DynPoolBlkGet(&KAL_DataPtr->TaskRegPool,
+                                                       &err_lib);
+        if (err_lib != LIB_MEM_ERR_NONE) {
+           *p_err = RTOS_ERR_ALLOC;
+            return (handle);
+        }
+
+        p_task_reg->Id = OSTaskRegGetID(&err_os);
+        if (err_os == OS_ERR_NONE) {
+            handle.TaskRegObjPtr = (void *)p_task_reg;
+           *p_err                =  RTOS_ERR_NONE;
+        } else {
+                                                                /* Free rsrc to pool.                                   */
+            Mem_DynPoolBlkFree(       &KAL_DataPtr->TaskRegPool,
+                               (void *)p_task_reg,
+                                      &err_lib);
+            (void)err_lib;                                     /* Err ignored.                                         */
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return (handle);
+    }
+    #else
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (handle);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_TaskRegGet()
+*
+* Description : Get value from a task register.
+*
+* Argument(s) : task_handle     Handle of the task associated to the task register. Current task is used if NULL.
+*
+*               task_reg_handle Handle of the task register to read.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Task register handle is NULL.
+*                                   RTOS_ERR_INVALID_ARG        Handle specified is invalid.
+*
+* Return(s)   : Value read from the task register, if no error.
+*               0,                                 otherwise.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+CPU_INT32U  KAL_TaskRegGet (KAL_TASK_HANDLE       task_handle,
+                            KAL_TASK_REG_HANDLE   task_reg_handle,
+                            RTOS_ERR             *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(0u);
+        }
+
+        if (KAL_TASK_REG_HANDLE_IS_NULL(task_reg_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return (0u);
+        }
+    #endif
+
+    #if (OS_CFG_TASK_REG_TBL_SIZE > 0u)
+    {
+        KAL_TASK_REG  *p_task_reg;
+        OS_TCB        *p_task_tcb;
+        CPU_INT32U     ret_val;
+        OS_ERR         err_os;
+
+
+        p_task_reg = (KAL_TASK_REG *)task_reg_handle.TaskRegObjPtr;
+
+        if (KAL_TASK_HANDLE_IS_NULL(task_handle) == DEF_YES) {
+            p_task_tcb = OSTCBCurPtr;                           /* Use cur task if no task handle is provided.          */
+        } else {
+                                                                /* Get TCB from task handle provided.                   */
+            p_task_tcb = &((KAL_TASK *)task_handle.TaskObjPtr)->TCB;
+        }
+
+        ret_val = OSTaskRegGet(p_task_tcb,
+                               p_task_reg->Id,
+                              &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return (ret_val);
+    }
+    #else
+        (void)task_handle;
+        (void)task_reg_handle;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return (0u);
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_TaskRegSet()
+*
+* Description : Set value of task register.
+*
+* Argument(s) : task_handle     Handle of the task associated to the task register. Current task is used if NULL.
+*
+*               task_reg_handle Handle of the task register to write to.
+*
+*               val             Value to write in the task register.
+*
+*               p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*                                   RTOS_ERR_NOT_AVAIL          Configuration does not allow operation.
+*                                   RTOS_ERR_NULL_PTR           Task register handle is NULL.
+*                                   RTOS_ERR_INVALID_ARG        Handle specified is invalid.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+void  KAL_TaskRegSet (KAL_TASK_HANDLE       task_handle,
+                      KAL_TASK_REG_HANDLE   task_reg_handle,
+                      CPU_INT32U            val,
+                      RTOS_ERR             *p_err)
+{
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(;);
+        }
+
+        if (KAL_TASK_REG_HANDLE_IS_NULL(task_reg_handle) == DEF_YES) {
+           *p_err = RTOS_ERR_NULL_PTR;
+            return;
+        }
+    #endif
+
+    #if (OS_CFG_TASK_REG_TBL_SIZE > 0u)
+    {
+        KAL_TASK_REG  *p_task_reg;
+        OS_TCB        *p_task_tcb;
+        OS_ERR         err_os;
+
+
+        p_task_reg = (KAL_TASK_REG *)task_reg_handle.TaskRegObjPtr;
+
+        if (KAL_TASK_HANDLE_IS_NULL(task_handle) == DEF_YES) {
+            p_task_tcb = OSTCBCurPtr;                           /* Use cur task if no task handle is provided.          */
+        } else {
+                                                                /* Get TCB from task handle provided.                   */
+            p_task_tcb = &((KAL_TASK *)task_handle.TaskObjPtr)->TCB;
+        }
+
+        OSTaskRegSet(       p_task_tcb,
+                            p_task_reg->Id,
+                    (OS_REG)val,
+                           &err_os);
+        if (err_os == OS_ERR_NONE) {
+           *p_err = RTOS_ERR_NONE;
+        } else {
+           *p_err = KAL_ErrConvert(err_os);
+        }
+
+        return;
+    }
+    #else
+        (void)task_handle;
+        (void)task_reg_handle;
+        (void)val;
+
+       *p_err = RTOS_ERR_NOT_AVAIL;
+
+        return;
+    #endif
+}
+
+
+/*
+*********************************************************************************************************
+*                                             KAL_TickGet()
+*
+* Description : Get value of OS' tick counter.
+*
+* Argument(s) : p_err           Pointer to variable that will receive the return error code from this function:
+*
+*                                   RTOS_ERR_NONE               No error.
+*
+* Return(s)   : OS tick counter's value.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+KAL_TICK  KAL_TickGet (RTOS_ERR  *p_err)
+{
+    KAL_TICK  tick_cnt;
+    OS_ERR    err_os;
+
+
+    #if (KAL_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                 /* ---------------- VALIDATE ARGUMENTS ---------------- */
+        if (p_err == DEF_NULL) {                                /* Validate err ptr.                                    */
+            CPU_SW_EXCEPTION(0u);
+        }
+    #endif
+
+    tick_cnt = OSTimeGet(&err_os);
+    if (err_os == OS_ERR_NONE) {
+       *p_err = RTOS_ERR_NONE;
+    } else {
+       *p_err = KAL_ErrConvert(err_os);
+    }
+
+    return (tick_cnt);
+}
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                            LOCAL FUNCTIONS
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                         KAL_TmrFnctWrapper()
+*
+* Description : Wrapper function for timer callback.
+*
+* Argument(s) : p_tmr_os        Pointer to OS timer object.
+*
+*               p_arg           Pointer to KAL timer object.
+*
+* Return(s)   : none.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+#if (OS_CFG_TMR_EN == DEF_ENABLED)
+static  void  KAL_TmrFnctWrapper (void  *p_tmr_os,
+                                  void  *p_arg)
+{
+    KAL_TMR  *p_tmr;
+
+
+    (void)p_tmr_os;
+
+    p_tmr = (KAL_TMR *)p_arg;
+    p_tmr->CallbackFnct(p_tmr->CallbackArg);
+}
+#endif
+
+
+/*
+*********************************************************************************************************
+*                                            KAL_msToTicks()
+*
+* Description : Convert milliseconds value in tick value.
+*
+* Argument(s) : ms              Millisecond value to convert.
+*
+* Return(s)   : Number of ticks corresponding to the millisecond value, rounded up, if needed.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+static  KAL_TICK  KAL_msToTicks (CPU_INT32U  ms)
+{
+           KAL_TICK    ticks;
+#if  ((OS_CFG_TICK_RATE_HZ         >= 1000u) && \
+      (OS_CFG_TICK_RATE_HZ % 1000u ==    0u))
+    const  CPU_INT08U  mult = OS_CFG_TICK_RATE_HZ / 1000u;
+#endif
+
+
+    #if  ((OS_CFG_TICK_RATE_HZ         >= 1000u) && \
+          (OS_CFG_TICK_RATE_HZ % 1000u ==    0u))               /* Optimize calc if possible for often used vals.       */
+        ticks =    ms * mult;
+    #elif (OS_CFG_TICK_RATE_HZ ==  100u)
+        ticks =  ((ms +  9u) /  10u);
+    #elif (OS_CFG_TICK_RATE_HZ ==   10u)
+        ticks =  ((ms + 99u) / 100u);
+    #else                                                       /* General formula.                                     */
+        ticks = (((ms * OS_CFG_TICK_RATE_HZ)  + 1000u - 1u) / 1000u);
+    #endif
+
+    return (ticks);
+}
+
+
+/*
+*********************************************************************************************************
+*                                           KAL_ErrConvert()
+*
+* Description : Convert OS errors in KAL errors.
+*
+* Argument(s) : err_os          Error value used by the OS.
+*
+* Return(s)   : KAL error.
+*
+* Note(s)     : none.
+*********************************************************************************************************
+*/
+
+static  RTOS_ERR  KAL_ErrConvert (OS_ERR  err_os)
+{
+    RTOS_ERR  err_rtos;
+
+
+    switch (err_os) {
+        case OS_ERR_NONE:
+        case OS_ERR_PEND_ABORT_NONE:
+        case OS_ERR_TIME_ZERO_DLY:
+             err_rtos = RTOS_ERR_NONE;
+             break;
+
+
+        case OS_ERR_MUTEX_NOT_OWNER:
+        case OS_ERR_NAME:
+        case OS_ERR_OBJ_TYPE:
+        case OS_ERR_OPT_INVALID:
+        case OS_ERR_PRIO_INVALID:
+        case OS_ERR_Q_SIZE:
+        case OS_ERR_REG_ID_INVALID:
+        case OS_ERR_STK_INVALID:
+        case OS_ERR_STK_SIZE_INVALID:
+        case OS_ERR_STK_LIMIT_INVALID:
+        case OS_ERR_TASK_DEL_IDLE:
+        case OS_ERR_TASK_INVALID:
+        case OS_ERR_TCB_INVALID:
+        case OS_ERR_TMR_INVALID_PERIOD:
+             err_rtos = RTOS_ERR_INVALID_ARG;
+             break;
+
+
+        case OS_ERR_OBJ_PTR_NULL:
+        case OS_ERR_PTR_INVALID:
+             err_rtos = RTOS_ERR_NULL_PTR;
+             break;
+
+
+        case OS_ERR_ILLEGAL_CREATE_RUN_TIME:
+        case OS_ERR_MUTEX_NESTING:
+        case OS_ERR_OBJ_DEL:
+        case OS_ERR_SCHED_LOCKED:
+        case OS_ERR_STATE_INVALID:
+        case OS_ERR_STATUS_INVALID:
+        case OS_ERR_TASK_WAITING:
+        case OS_ERR_TMR_INACTIVE:
+        case OS_ERR_TMR_INVALID_DLY:
+        case OS_ERR_TMR_INVALID_STATE:
+        case OS_ERR_TMR_INVALID:
+             err_rtos = RTOS_ERR_OS;
+             break;
+
+
+        case OS_ERR_TIMEOUT:
+             err_rtos = RTOS_ERR_TIMEOUT;
+             break;
+
+
+        case OS_ERR_PEND_ABORT:
+             err_rtos = RTOS_ERR_ABORT;
+             break;
+
+
+        case OS_ERR_PEND_WOULD_BLOCK:
+             err_rtos = RTOS_ERR_WOULD_BLOCK;
+             break;
+
+
+        case OS_ERR_CREATE_ISR:
+        case OS_ERR_DEL_ISR:
+        case OS_ERR_PEND_ISR:
+        case OS_ERR_PEND_ABORT_ISR:
+        case OS_ERR_POST_ISR:
+        case OS_ERR_SET_ISR:
+        case OS_ERR_TASK_CREATE_ISR:
+        case OS_ERR_TASK_DEL_ISR:
+        case OS_ERR_TIME_DLY_ISR:
+        case OS_ERR_TMR_ISR:
+             err_rtos = RTOS_ERR_ISR;
+             break;
+
+
+        case OS_ERR_SEM_OVF:
+             err_rtos = RTOS_ERR_WOULD_OVF;
+             break;
+
+
+        case OS_ERR_MSG_POOL_EMPTY:
+        case OS_ERR_NO_MORE_ID_AVAIL:
+        case OS_ERR_Q_MAX:
+             err_rtos = RTOS_ERR_NO_MORE_RSRC;
+             break;
+
+
+        case OS_ERR_MUTEX_OWNER:
+             err_rtos = RTOS_ERR_OWNERSHIP;
+             break;
+
+
+        default:
+             err_rtos = RTOS_ERR_OS;
+             break;
+    }
+
+    return (err_rtos);
+}

+ 202 - 0
LICENSE

@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.

+ 28 - 0
NOTICE

@@ -0,0 +1,28 @@
+ATTENTION ALL USERS OF THIS REPOSITORY:
+
+The original work found in this repository is provided by Silicon Labs under the
+Apache License, Version 2.0.
+
+Any third party may contribute derivative works to the original work in which
+modifications are clearly identified as being licensed under:
+
+  (1) the Apache License, Version 2.0 or a compatible open source license; or
+  (2) under a proprietary license with a copy of such license deposited.
+
+All posted derivative works must clearly identify which license choice has been
+elected.
+
+No such posted derivative works will be considered to be a “Contribution” under
+the Apache License, Version 2.0.
+
+SILICON LABS MAKES NO WARRANTY WITH RESPECT TO ALL POSTED THIRD PARTY CONTENT
+AND DISCLAIMS ALL OTHER WARRANTIES OR LIABILITIES, INCLUDING ALL WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, OWNERSHIP,
+NON-INFRINGEMENT, AND NON-MISAPPROPRIATION.
+
+In the event a derivative work is desired to be submitted to Silicon Labs as a
+“Contribution” under the Apache License, Version 2.0, a “Contributor” must give
+written email notice to micrium@weston-embedded.com. Unless an email response in
+the affirmative to accept the derivative work as a “Contribution”, such email
+submission should be considered to have not been incorporated into the original
+work.

+ 81 - 0
common.h

@@ -0,0 +1,81 @@
+/*
+*********************************************************************************************************
+*                                              uC/Common
+*                                 Common Features for Micrium Stacks
+*
+*                    Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
+*
+*                                 SPDX-License-Identifier: APACHE-2.0
+*
+*               This software is subject to an open source license and is distributed by
+*                Silicon Laboratories Inc. pursuant to the terms of the Apache License,
+*                    Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
+*
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*
+*                                   uC/Common - Common Definitions
+*
+* Filename : common.h
+* Version  : V1.02.00
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                               MODULE
+*
+* Note(s) : (1) This library header file is protected from multiple pre-processor inclusion through
+*               use of the library module present pre-processor macro definition.
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#ifndef  COMMON_MODULE_PRESENT                                  /* See Note #1.                                         */
+#define  COMMON_MODULE_PRESENT
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                                DEFINES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                     COMMON MODULE VERSION NUMBER
+*
+* Note(s) : (1) (a) The common module software version is denoted as follows :
+*
+*                       Vx.yy.zz
+*
+*                           where
+*                                   V               denotes 'Version' label
+*                                   x               denotes     major software version revision number
+*                                   yy              denotes     minor software version revision number
+*                                   zz              denotes sub-minor software version revision number
+*
+*               (b) The software version label #define is formatted as follows :
+*
+*                       ver = x.yyzz * 100 * 100
+*
+*                           where
+*                                   ver             denotes software version number scaled as an integer value
+*                                   x.yyzz          denotes software version number, where the unscaled integer
+*                                                       portion denotes the major version number & the unscaled
+*                                                       fractional portion denotes the (concatenated) minor
+*                                                       version numbers
+*********************************************************************************************************
+*/
+
+#define  COMMON_VERSION                                10200u   /* See Note #1.                                         */
+
+
+#endif /* COMMON_MODULE_PRESENT */
+

+ 105 - 0
common_err.h

@@ -0,0 +1,105 @@
+/*
+*********************************************************************************************************
+*                                              uC/Common
+*                                 Common Features for Micrium Stacks
+*
+*                    Copyright 2013-2020 Silicon Laboratories Inc. www.silabs.com
+*
+*                                 SPDX-License-Identifier: APACHE-2.0
+*
+*               This software is subject to an open source license and is distributed by
+*                Silicon Laboratories Inc. pursuant to the terms of the Apache License,
+*                    Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
+*
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*
+*                                   uC/Common - Generic error codes
+*
+* Filename : common_err.h
+* Version  : V1.02.00
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                               MODULE
+*
+* Note(s) : (1) This library header file is protected from multiple pre-processor inclusion through
+*               use of the library module present pre-processor macro definition.
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+#ifndef  COMMON_ERR_MODULE_PRESENT                              /* See Note #1.                                         */
+#define  COMMON_ERR_MODULE_PRESENT
+
+
+/*
+*********************************************************************************************************
+*********************************************************************************************************
+*                                             DATA TYPES
+*********************************************************************************************************
+*********************************************************************************************************
+*/
+
+/*
+*********************************************************************************************************
+*                                           COMMON ERR CODES
+*
+* Note(s) : (1) Caller should NEVER rely on the order/numerical value of ANY of these enum items. Their
+*               order within the enum may change and other enum item may be added anywhere, impacting
+*               the numerical values of other enum items.
+*
+*           (2) A function MUST return the most accurate error it can. For example, if a NULL pointer is
+*               passed to a function requiring a non-NULL pointer, it should return the RTOS_ERR_NULL_PTR
+*               error and NOT RTOS_ERR_INVALID_ARG. A function should only return RTOS_ERR_INVALID_ARG
+*               if no other error code can better describe the error that occurred.
+*********************************************************************************************************
+*/
+
+typedef  enum  rtos_err {
+    RTOS_ERR_NONE,                                              /* No err.                                              */
+
+                                                                /* ------------------ FEATURE SUPPORT ----------------- */
+    RTOS_ERR_NOT_AVAIL,                                         /* Feature not avail (due to cfg val(s).                */
+    RTOS_ERR_NOT_SUPPORTED,                                     /* Feature not supported.                               */
+
+                                                                /* ------------------- INVALID ARGS ------------------- */
+    RTOS_ERR_INVALID_ARG,                                       /* Invalid arg or consequence of invalid arg.           */
+    RTOS_ERR_NULL_PTR,                                          /* Null ptr.                                            */
+    RTOS_ERR_INVALID_STR_LEN,                                   /* Len of str passed is invalid.                        */
+    RTOS_ERR_INVALID_CREDENTIALS,                               /* Credentials used are invalid.                        */
+    RTOS_ERR_NOT_FOUND,                                         /* Requested item could not be found.                   */
+
+                                                                /* ---------------- CREATION/ALLOCATION --------------- */
+    RTOS_ERR_ALLOC,                                             /* Generic alloc err.                                   */
+    RTOS_ERR_CREATE_FAIL,                                       /* Gen create obj err.                                  */
+    RTOS_ERR_NO_MORE_RSRC,                                      /* Rsrc not avail to perform the operation.             */
+    RTOS_ERR_INIT,                                              /* Init failed.                                         */
+    RTOS_ERR_ALREADY_INIT,                                      /* Module has already been init'd.                      */
+    RTOS_ERR_ALREADY_EXISTS,                                    /* Item already exists.                                 */
+
+                                                                /* ------------------- PEND/ACQUIRE ------------------- */
+    RTOS_ERR_ABORT,                                             /* Operation aborted.                                   */
+    RTOS_ERR_TIMEOUT,                                           /* Operation timed out.                                 */
+
+                                                                /* ------------------- POST/RELEASE ------------------- */
+    RTOS_ERR_WOULD_BLOCK,                                       /* Non-blocking operation would block.                  */
+    RTOS_ERR_OWNERSHIP,                                         /* Ownership err.                                       */
+    RTOS_ERR_WOULD_OVF,                                         /* Item would overflow.                                 */
+
+                                                                /* -------------------- OS-RELATED -------------------- */
+    RTOS_ERR_ISR,                                               /* Illegal call from ISR.                               */
+    RTOS_ERR_OS,                                                /* Generic OS err.                                      */
+
+                                                                /* ----------------------- MISC ----------------------- */
+    RTOS_ERR_PERMISSION                                         /* Operation not allowed.                               */
+} RTOS_ERR;
+
+#endif /* COMMON_ERR_MODULE_PRESENT */
+

+ 7 - 0
readme.md

@@ -0,0 +1,7 @@
+# uC/Common for RT-Thread
+
+https://github.com/SiliconLabs/uC-Common
+
+µC/Common is a module that regroups components used by various Micrium products. It currently includes a Kernel Abstraction Layer (KAL), allowing products to make abstraction of the kernel that is used. µC/Common is designed to be included in any project using µC/FS, µC/USB-Device, µC/USB-Host or µC/TCP-IP.
+
+### For the complete documentation, visit https://doc.micrium.com/display/ucos/