/*******************************************************************************
* Project:      Amped'RF Bluetooth
* File name:    App_Utility.c
* Description:  Useful utility functions
*
* Copyright (c) 2012 Amped'RF Inc., AR Technology  All rights reserved.
*
*******************************************************************************/
#include "Common.h"
#include "App_Util.h"
#include "hcidefs.h"



/*******************************************************************************
* Function Name  : SetupGapDiscoveryOff
* Description    : Set discovery to OFF
*******************************************************************************/
void SetupGapDiscoveryOff()
{
    tOS_Signal *pNewSignal = NULL;
    tSIG_AMPGapDeviceSetup *pAMPGapDeviceSetup = NULL;
    pNewSignal = OS_AllocSignal(SIG_AMP_GAP_DEVICE_SETUP, sizeof(tSIG_AMPGapDeviceSetup));
    pAMPGapDeviceSetup = (tSIG_AMPGapDeviceSetup *)OS_GetSignalDataPtr(pNewSignal);
    memset(pAMPGapDeviceSetup, 0, sizeof(tSIG_AMPGapDeviceSetup));

    // Fill in the message fields and send the message
    pAMPGapDeviceSetup->Transac = 0x00;
    pAMPGapDeviceSetup->DiscoverableMode = 0x00;
    pAMPGapDeviceSetup->DiscoverableDuration = HCI_DEF_INQUIRYSCAN_WINDOW;
    pAMPGapDeviceSetup->DiscoverableInterval = HCI_DEF_INQUIRYSCAN_INTERVAL;
    pAMPGapDeviceSetup->ConnectableMode = 0x01;
    pAMPGapDeviceSetup->ConnectableDuration = HCI_DEF_PAGESCAN_WINDOW;
    pAMPGapDeviceSetup->ConnectableInterval = HCI_DEF_PAGESCAN_INTERVAL;
    pAMPGapDeviceSetup->CodMinor = 0x04;
    pAMPGapDeviceSetup->CodMajor = 0x04;
    pAMPGapDeviceSetup->CodServices = 0x24;
    OS_Send(OS_AMP, pNewSignal);
}



/*******************************************************************************
* Function Name  : WriteConfigVarFlag
* Description    : Write a config flag variable
*******************************************************************************/
void WriteConfigVarFlag(uint16 Id, uint8 flag)
{
    *(uint8 *)TM_GetFlashWritePtr(Id, 1) = flag;
    TM_FlashWriteDone(Id);
}



/*******************************************************************************
* Function Name  : AppleCPSleep
* Description    : Froces the Apple CP to sleep
********************************************************************************/
#ifdef APPLE_CP_SLEEP
static void AppleCPSleep(void)
{
  //Write Authentication Control:PROC_CONTROL = 4
  SendToAuthenticationControl(FORCE_SLEEP); // force Apple CP to sleep now
}
#endif

//
//=============================================================================
