/*******************************************************************************
* Project:      Amped'RF Bluetooth
* File name:    GKI_NativeOS.h
* Description:  OS abstraction header for Blue OS.
*
* Note: Modules are defined as a task with an associated msg queue
*
* Copyright (c) 2012 Amped'RF Inc., AR Technology  All rights reserved.
*******************************************************************************/
#ifndef _GKI_NATIVE_OS_H_
#define _GKI_NATIVE_OS_H_

#include "SDK_BlueOS.h"

#define tGKI_TaskId                 tBP_TaskId
#define tGKI_TaskPrio               tBP_TaskPrio
#define tGKI_DataSize               tBP_DataSize
#define tGKI_SignalNo               tBP_SignalNo
#define tGKI_TaskName               tBP_TaskName
#define tGKI_ModuleId               tBP_ModuleId
#define tGKI_Critical               tBP_Critical
#define tGKI_PoolNotifyFunc         tBP_PoolNotifyFunc
#define tGKI_SignalHead             tBP_SignalHead
#define tGKI_SignalData             tBP_SignalData
#define tGKI_Signal                 tBP_Signal
#define tpGKI_Signal                tpBP_Signal
#define tGKI_MemBlock               tBP_MemBlock
#define tpGKI_MemBlock              tpBP_MemBlock
#define tGKI_Pool                   tBP_Pool
#define tpGKI_Pool                  tpBP_Pool
#define tGKI_MemPool                tBP_MemPool
#define tpGKI_MemPool               tpBP_MemPool
#define tGKI_Queue                  tBP_Queue
#define GKI_AllocMemory             BP_AllocMemory
#define GKI_ReleaseMemory           BP_ReleaseMemory
#define GKI_GetFromPool             BP_GetFromPool
#define GKI_ReturnToPool            BP_ReturnToPool
#define GKI_InitQueue               BP_InitQueue
//#define GKI_enqueue                 GKI_enqueue
//#define GKI_enqueue_head            GKI_enqueue_head
//#define GKI_dequeue                 GKI_dequeue
#define GKI_AllocSignal             BP_AllocSignal
#define GKI_Send                    BP_Send
#define GKI_IsrAllocSignal          BP_IsrAllocSignal
#define GKI_IsrSend                 BP_IsrSend
#define GKI_ReleaseSignal           BP_ReleaseSignal
#define GKI_TimerRegisterRequest    BP_TimerRegisterRequest
#define GKI_TimerCancel             BP_TimerCancel
#define GKI_disable_interrupt()     __disable_interrupt()
#define GKI_enable_interrupt()      __enable_interrupt()
#define GKI_get_interrupt_state()   __get_interrupt_state()
#define GKI_set_interrupt_state(cs) __set_interrupt_state(cs)
#define GKI_enter_critical()        GKI_get_interrupt_state(); GKI_disable_interrupt()
#define GKI_exit_critical(cs)       GKI_set_interrupt_state(cs)
#define GKI_YieldFromISR()
#define GKI_GenerateSystemReset()   NVIC_GenerateSystemReset()

#define GKI_get_tick_count          RTC_GetCounter
#define GKI_putstring               SerialPutString
#define GKI_MemoryValid(mem)        ((u32)mem>=0x20000000 && (u32)mem<=0x2000FFFF)


extern u32 it_CalibratingHSE;
void GKI_set_tick_timeout(u32 v);
void UART_SetBaudrate(u16 u, u32 baudrate);
void GKI_WaitMS(u32 ms);


//typedef char*  tBP_Name;
//typedef uint8* tBP_StackPtr;
typedef void    (*tGKI_InitFunc)(void);
//typedef void    (*tGKI_ReceiveFunc)(tGKI_Signal*);
typedef void    (*tGKI_IdleFunc)(void);
//typedef void    (*tGKI_InterceptFunc)(tGKI_Signal*);
typedef void    (*tGKI_FatalFunc)(uint32 Reason, char *pFileName, uint16 LineNo);
typedef void    (*tGKI_ShutdownFunc)(uint32 Reason);
//typedef bool    (*tGKI_BackgroundJobFunc)(uint32 Argument);


void TM_TimerRegisterRequest(uint32 Transac, uint16 ReqId, uint32 MsTmr,
                                   tOS_SignalNo SigNo );
void TM_CancelTmrRequest(uint16 RegId);

u32 GKI_get_tick_count(void);


#define ENTER_CRITICAL()        uint32 TM_ICR = __get_interrupt_state(); __disable_interrupt()
#define EXIT_CRITICAL()         __set_interrupt_state(TM_ICR);




#endif // _GKI_NATIVE_OS_H_
