/*******************************************************************************
* Project:      Amped'RF Bluetooth
* File name:    Config.h
* Description:  Configuration settings
*
* Copyright (c) 2016 Amped'RF Inc., AR Technology  All rights reserved.
*******************************************************************************/
#ifndef _SDK_CONFIG_H_
#define _SDK_CONFIG_H_


//------------------------------------------------------------------------------
//  OS Configuration (do not modify)
//------------------------------------------------------------------------------
#define OS_NO_OF_TCB                     20
#define OS_SHORT_SIGNAL_SIZE             80 // In Bytes
#define OS_LONG_SIGNAL_SIZE             370 // In Bytes
#define OS_BUFFER_SIGNAL_SIZE             2 // In Bytes
#define OS_HEAP_SIZE                    800 // In Bytes
#define OS_NO_OF_SHORT_SIGNALS           40
#define OS_NO_OF_LONG_SIGNALS            10
#define OS_NO_OF_BUFFER_SIGNALS           1
#define OS_TM_TIMER_TASKPRIO              5 // Task Priority 1 -255
#define OS_APPLICATION_HIGH_TASKPRIO     30 // application high priority
#define OS_AMP_TASKPRIO                  55
#define OS_APPLICATION_TASKPRIO          OS_DEFAULT_PRIO
#define OS_APPLICATION_LOW_TASKPRIO      OS_LOW_PRIO
#define TM_TIMER_MAX                     30


//------------------------------------------------------------------------------
//  Flash DataBase Data record IDs
//------------------------------------------------------------------------------
#define TMFM_1ST_CONFIG_ID  0x1001  // 1st config variable ID
#define TMFM_1ST_DYNAMIC_ID 0x2001  // Dynamic only record ID base
#define TMFM_1ST_CUSTOM_ID  0x3001  // Custom record ID base
#define TMFM_1ST_USER_ID    0x4001  // User record ID base
#define VAR_ID_SDK_BASE     0x5001  // Base ID for SDK Variables


//------------------------------------------------------------------------------
// Flash Manager variables
//------------------------------------------------------------------------------
enum {
    TM_FLASH_MODEM_DB_INIT = TMFM_1ST_USER_ID,
    TM_FLASH_BOND_STATUS,
    TM_FLASH_SMART_CABLE_SETUP,
    TM_FLASH_SMART_PRINTER_SETUP,
    TM_FLASH_PRINTER_CONFIG,
    TM_FLASH_MAIN_BAUD_RATE,
    TM_FLASH_LOCAL_NAME,
    TM_FLASH_REMOTE_COMMAND,
    TM_FLASH_VOLUME,
    TM_FLASH_LAST_CONNECTION,
    TM_FLASH_LAST_USER_ID
};

/***************************************
* Define Dynamic Config constants here *
****************************************/

#define CONFIG_MAX_VARNAME_SIZE 24  // Max size of config name variables

#define CONFIG_ATTR_HIDE     0x80   // hide variable
#define CONFIG_ATTR_HEX      0x40   // display as hex
#define CONFIG_ATTR_RO       0x20   // read only
#define CONFIG_ATTR_MASK     0x1F   // mask
enum {
    CONFIG_TYPE_STRING=0,
    CONFIG_TYPE_BOOL,
    CONFIG_TYPE_UINT8,
    CONFIG_TYPE_UINT16,
    CONFIG_TYPE_UINT32,
    CONFIG_TYPE_BDADDR,
    CONFIG_TYPE_BAUDRATE,
    CONFIG_TYPE_PARITY,     // none, odd, even
    CONFIG_TYPE_DATABITS,   // 7p, 8, 8p. 8w, 9
    CONFIG_TYPE_STOPBITS,   // .5, 1, 1.5, 2
    CONFIG_TYPE_UINT4,      // 0 - 15
    CONFIG_TYPE_CPU_MHZ,
    CONFIG_TYPE_HCI_BAUDRATE,
    CONFIG_TYPE_COD,
    CONFIG_TYPE_GPIO,       // none, 0-15
    CONFIG_TYPE_MASTER_SLAVE,
    CONFIG_TYPE_HSE_MHZ,    // 13 or 26
    CONFIG_TYPE_UUID_FILTER,
    CONFIG_TYPE_ACC_VERSION,
    CONFIG_TYPE_NUM
};


typedef struct {
    uint8   Hide    : 1;
    uint8   Hex     : 1;
    uint8   RO      : 1;
    uint8   Type    : 5;
} tConfigAttr;


typedef struct {
    uint16      Id;
    char *      Name;
    char *      Setting;
    tConfigAttr Attr;
} tConfigVar;

extern tConfigVar ConfigVar[];
extern uint16 ConfigVarMax;

/**********************************
* Define config variable IDs here *
***********************************/
enum {
    VAR_ID_BuildVersion = TMFM_1ST_CONFIG_ID,
    VAR_ID_FlashVersion,
    VAR_ID_BD_ADDR,
    VAR_ID_DeviceName,
    VAR_ID_StreamingSerial,
    VAR_ID_DefaultPIN,
    VAR_ID_UartBaudrate,
    VAR_ID_UartDataBits,
    VAR_ID_UartStopBits,
    VAR_ID_UartParity,
    VAR_ID_UartTimeout,

    VAR_ID_AutoSniff,
    VAR_ID_AutoSniffTimeout,
    VAR_ID_AutoSniffInterval,

    VAR_ID_HostShallowSleepEnable,
    VAR_ID_HostDeepSleepEnable,
    VAR_ID_GPIO_HostKeepAwake,
    VAR_ID_GPIO_HostWakeup,

    VAR_ID_UseSmallPackets,
    VAR_ID_EnableAFH,
    VAR_ID_EnablePowerControl,
    VAR_ID_L2CAP_HostFlowControl,
    VAR_ID_ATReply,
    VAR_ID_QOS_LATENCY,
    VAR_ID_CPU_MHZ,
    VAR_ID_HCI_BAUDRATE,
    VAR_ID_EnableSPI,
    VAR_ID_SPIMode,
    VAR_ID_EnableI2C,
    VAR_ID_COD,
    VAR_ID_LINK_DESKEY,
    VAR_ID_UART_DESKEY,
    VAR_ID_MultipointMode,

    VAR_ID_LinkSecurity,
    VAR_ID_HostEvents,
    VAR_ID_BondingAllowed,
    VAR_ID_PageScan,
    VAR_ID_InquiryScan,
    VAR_ID_UseExtLPO,
    VAR_ID_HSE_MHZ,
    VAR_ID_EnableEncryption,
    VAR_ID_DefaultSecurity,
    VAR_ID_DefaultAuthentication,
    VAR_ID_AllowSniff,
    VAR_ID_EnableIAP,
    VAR_ID_iAPAppID,
    VAR_ID_iAPProtocolStringMain,
    VAR_ID_iAPProtocolStringAlt,
    VAR_ID_CPI2CMode,
    VAR_ID_SPP_128UUID,
    VAR_ID_EnableRPN,
    VAR_ID_HardwareType,
    VAR_ID_EnableRmtEscapeSeq,  //remote command escape sequence
    VAR_ID_SimpleRemoteLingo,   //IAP SimpleRemoteLingo
    VAR_ID_CreditMax,
    VAR_ID_DiscoveryTimeout,
    VAR_ID_DiscoveryDelay,
    VAR_ID_EnableServiceCheck,
    VAR_ID_ServiceCheckOp,
    VAR_ID_ServiceCheckRspOp,
    VAR_ID_PageScanInterlaced,
    VAR_ID_MITMEvent,
    VAR_ID_AltCPGPIO,
    VAR_ID_InMtuSize,
    VAR_ID_OutMtuSize,
    VAR_ID_AppleAccName,
    VAR_ID_AppleAccManufacturer,
    VAR_ID_AppleAccModelNumber,
    VAR_ID_AppleAccSerialNumber,
    VAR_ID_AppleAccVersionFW,
    VAR_ID_AppleAccVersionHW,
    VAR_ID_EnableSPPRcv,
    VAR_ID_EnableIAPRcv,
    TMFM_LAST_CONFIG_ID
};
#define VAR_ID_COUNT  (TMFM_LAST_CONFIG_ID - TMFM_1ST_CONFIG_ID)



/******************************************
*  Helpful Defines for config variables   *
*******************************************/
#define TM_ALLOW_SNIFF              (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_AllowSniff) ? true : false)
#define TM_HOST_SHALLOW_SLEEP_ENABLE  (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_HostShallowSleepEnable) ? true : false)
#define TM_HOST_DEEP_SLEEP_ENABLE   (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_HostDeepSleepEnable) ? true : false)
#define TM_GPIO_HOST_KEEP_AWAKE     (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_GPIO_HostKeepAwake))
#define TM_GPIO_HOST_WAKEUP         (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_GPIO_HostWakeup))
#define TM_CpuMHz                   (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_CPU_MHZ))
#define TM_HSE_MHZ                  (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_HSE_MHZ))
#define TM_HCI_BAUDRATE             (*(uint32 *)TM_GetFlashReadPtr(VAR_ID_HCI_BAUDRATE))

#define TM_AUTO_SNIFF_ENABLE        (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_AutoSniff))
#define TM_AUTO_SNIFF_TIMEOUT       (*(uint16 *)TM_GetFlashReadPtr(VAR_ID_AutoSniffTimeout))
#define TM_AUTO_SNIFF_INTERVAL      (*(uint16 *)TM_GetFlashReadPtr(VAR_ID_AutoSniffInterval))
#define TM_BOND_TIMEOUT             (*(uint16 *)TM_GetFlashReadPtr(VAR_ID_BondTimeout))

#define TM_LINK_SECURITY            (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_LinkSecurity)   ?  true : false)
#define TM_HOST_EVENTS              (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_HostEvents)     ?  true : false)
#define TM_BONDING_ALLOWED          (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_BondingAllowed) ?  true : false)
#define TM_PAGE_SCAN                (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_PageScan)       ?  true : false)
#define TM_INQUIRY_SCAN             (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_InquiryScan)    ?  true : false)
#define TM_USE_EXT_LPO              (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_UseExtLPO)      ?  true : false)
#define TM_DEVICE_NAME              ((char *)TM_GetFlashReadPtr(VAR_ID_DeviceName))
#define TM_ENCRYPTION_ENABLED       (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_EnableEncryption) ? true : false)
#define TM_DEFAULT_SECURITY         (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_DefaultSecurity))
#define TM_DEFAULT_AUTHENTICATION   (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_DefaultAuthentication))
#define TM_DEFAULT_PIN              ((char *)TM_GetFlashReadPtr(VAR_ID_DefaultPIN))
#define TM_LAST_CONNECTION          ((tSIG_ReconnectInfo *)TM_GetFlashReadPtr(TM_FLASH_LAST_CONNECTION))
#define TM_ENABLE_IAP               (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_EnableIAP)           ?  true : false)
#define TM_SPP128UUID               (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_SPP_128UUID)         ?  true : false)
#define TM_RFCOMM_RPN               (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_EnableRPN)           ?  true : false)
#define TM_EnableRmtEscapeSequence  (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_EnableRmtEscapeSeq)  ?  true : false)
#define TM_EnableSimpleRemoteLingo  (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_SimpleRemoteLingo)   ?  true : false)
#define TM_ENABLE_SPI               (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_EnableSPI)           ?  true : false)
#define TM_CREDIT_MAX               (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_CreditMax))
#define TM_PAGE_SCAN_INTERLACED     (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_PageScanInterlaced)  ?  true : false)
#define TM_MITM_EVENT               (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_MITMEvent)           ?  true : false)
#define TM_ALT_CP_GPIO              (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_AltCPGPIO)           ?  true : false)
#define TM_DEFAULT_HCI_BAUDRATE     (TM_HOST_DEEP_SLEEP_ENABLE ? MIN(TM_HCI_BAUDRATE, 921600) : TM_HCI_BAUDRATE)
#define SDC_LM_DATA_BODY_SIZE       (*(uint16 *)TM_GetFlashReadPtr(VAR_ID_InMtuSize))
#define SDC_TO_LM_DATA_BUFFER_SIZE  (*(uint16 *)TM_GetFlashReadPtr(VAR_ID_OutMtuSize))
#define TM_APPLE_ACC_NAME           ((char *)TM_GetFlashReadPtr(VAR_ID_AppleAccName))
#define TM_APPLE_ACC_MANUFACTURER   ((char *)TM_GetFlashReadPtr(VAR_ID_AppleAccManufacturer))
#define TM_APPLE_ACC_MODEL_NUMBER   ((char *)TM_GetFlashReadPtr(VAR_ID_AppleAccModelNumber))
#define TM_APPLE_ACC_SERIAL_NUMBER  ((char *)TM_GetFlashReadPtr(VAR_ID_AppleAccSerialNumber))

#define TM_ENABLE_SPPRECV            (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_EnableSPPRcv)         ?  true : false)
#define TM_ENABLE_IAPRECV            (*(uint8 *)TM_GetFlashReadPtr(VAR_ID_EnableIAPRcv)         ?  true : false)


// added by Kelly 24/12/2010
#define IO_CAPABILITY_DISPLAY_ONLY          0x00
#define IO_CAPABILITY_DISPLAY_YES_NO        0x01
#define IO_CAPABILITY_KEYBOARD_ONLY         0x02
#define IO_CAPABILITY_NO_INPUT_NO_OUTPUT    0x03
// end


// Prototypes for btos library
bool    TM_GetBdAddr(char *s, uint8 *BdAddr);
bool    TM_GetStoredBdAddr(uint8 *pBD_ADDR);
uint16  TM_GetNumBdAddr(void);


#endif // _SDK_CONFIG_H_
