/*******************************************************************************
* Project:      Amped'RF Bluetooth
* File name:    SDK_Common.h
* Description:  Common header
*
* Copyright (c) 2016 Amped'RF Technology Inc, All rights reserved.
*******************************************************************************/
#ifndef _SDK_COMMON_H_
#define _SDK_COMMON_H_

#include <stdio.h>
#include <intrinsics.h>
#include "string.h"
#include "stdlib.h"
#include "GKI_Headers.h"
#include "SDK_Version.h"

#define LM_NAME_SIZE        15
#define SIGNAL_UNHANDLED    0
#define SIGNAL_HANDLED      1

//------------------------------------------------------------------------------
//  Macros
//------------------------------------------------------------------------------
#define TC_UNUSED(Parameter) (Parameter = Parameter)
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define TOLOWER(c)   ((c) >= 'A' && (c) <= 'Z' ? (c)-'A'+'a' : (c))
#define ABS(x)  ((x) > 0 ? (x) : -(x))
#define NOP asm(" nop\n");

typedef enum{
    eUUID_SPP=0,
    eUUID_IAP,
    eUUID_HEADSET,
    eUUID_GATEWAY,
    eUUID_HID
}eUUID;
extern eUUID uuid;


typedef struct {
  uint8    Byte[6];
} tBdAddr;                 // 48 bit IEEE

typedef uint8  tPageScanRepMode;
typedef uint8  tPageScanPeriodMode;
typedef uint8  tPageScanMode;

typedef uint16 tClkOffset;
typedef uint32 tCod;
//typedef uint32 tBP_SignalNo;


typedef struct tBufferHeader {
  uint8  *pData;            // This must match tSysBufHdr structure
  uint32 Transac;           // This must match tSysBufHdr structure
}tBufferHeader;

typedef struct tSysBufHdr
{
  uint8               *pData;  // This must match tBufferHeader structure
  uint32              Transac; // This must match tBufferHeader structure
  struct tSysBufHdr   *pNext;
  uint16              DataLen;
}tSysBufHdr;

// Signals
#define SIG_BTU_BASE            7000
#define SIG_APPLICATION_BASE    40000
#define SIG_CUSTOM_BASE         50000
#define SIG_DEVKIT_BASE         60000
#define SIG_SDK_BASE            60000

// Starting value of Persistant veriable IDs
#define TM_TMRID_SDK_BASE       0xC000

#include "SDK_BP_Signals.h"
#include "SDK_AMP_Signals.h"
#include "SDK_AT_Signals.h"
#include "SDK_Config.h"
#include "OS_BTIStruct.h"
#include "SDK_AmpStruct.h"
#include "OS_Def.h"
#include "OS_BTIStruct.h"
#include "OS_btos_interface.h"
#include "SDK_ErrorHandler.h"
#include "SDK_os.h"
#include "SDK_Alias.h"
#include "SDK_BTI.h"

int     SDK_ReceiveSignal(tOS_Signal *pSignal);
char  * SDK_GetSignalName(unsigned short iSig);
void    TM_FlashWriteDone(uint16 Id);
void  * TM_GetFlashReadPtr(uint16 Id);
void    TM_FlashWordWrite(u32 XtargetAdd, u32 Xdata);
void    TM_DeleteFlashId(uint16 Id);

#endif // _SDK_COMMON_H_
