Добавление новой функции в bluetooth (ble)

Я хочу вызвать функцию (void int_To_Arr(uint32_t x,int number_bit)) после ввода x и num_bit, но я не знаю, где ее разместить. Должен ли я положить его в ProjectZero_createTask (void)? Кроме того, ниже приведен код для мигания светодиода, но теперь необходимо объединить их обоих (светодиод мигает + один) в одном коде. Должен ли я включить все эти PWMConfig/thefrequency/interrupt(светодиодный код) в код ble?

/* Standard Includes */
#include <stdint.h>//also other libraries
void redirect();
/
/* Timer_A PWM Configuration Parameter */
Timer_A_PWMConfig pwmConfig=
{       TIMER_A_CLOCKSOURCE_SMCLK,
        TIMER_A_CLOCKSOURCE_DIVIDER_1,
        12000, //1000
        TIMER_A_CAPTURECOMPARE_REGISTER_1,
        TIMER_A_OUTPUTMODE_RESET_SET,
        900 //50
};
int main(void)
{
    /* Stop WDT  */
    MAP_WDT_A_holdTimer();

     /* Selecting P1.2 and P1.3 in UART mode */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
            GPIO_PIN1 | GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION);

    /* Setting DCO to 12MHz */
    CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);

        /* Configuring UART Module */
    MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig);

    /* Enable UART module */
    MAP_UART_enableModule(EUSCI_A0_BASE);

    /* Configuring GPIO2.4 as peripheral output for PWM  and P6.7 for button
     * interrupt */
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4,
        GPIO_PRIMARY_MODULE_FUNCTION);
    redirect();


    /* Configuring P1.0 as output */
    MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
    MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);


    /* Configuring Timer_A to have a period of approximately 500ms and
     * an initial duty cycle of 10% of that (3200 ticks)  */
    //MAP_Interrupt_enableSleepOnIsrExit();
    MAP_Interrupt_enableInterrupt(INT_TA0_0);
    MAP_Timer_A_generatePWM(TIMER_A0_BASE,&pwmConfig);
    MAP_Timer_A_clearInterruptFlag(TIMER_A0_BASE);
    MAP_Timer_A_enableInterrupt(TIMER_A0_BASE);
    MAP_Timer_A_enableCaptureCompareInterrupt(TIMER_A0_BASE,TIMER_A_CAPTURECOMPARE_REGISTER_0);

    /* Enabling MASTER interrupts */
    MAP_Interrupt_enableMaster(); 

    /* Sleeping when not in use */
    while (1)
    {
    }
}

 int time=0;
const int BIT_LENGTH = 33;
int period;
int times[33]; //{x}
int values[32];//{y}

void int_To_Arr(uint32_t x,int number_bit){
    int i = 0; 
    period = BIT_LENGTH * 67  ;   // 15fps -> 1/15=66.67m

    for (i = 0; i < number_bit ; i++) {
        if (((x >> i) & 1) == 0)    /* shift right by i-bits, check on/off */
            values[i] = 1000;       /* assign to values[i] based on result */
        else
            values[i] = 11000;
        times[i] = BIT_LENGTH * i;  /* set times[i] */
    }             
}

void TA0_0_IRQHandler(void)
{
    int i,value;
    MAP_Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE,
             TIMER_A_CAPTURECOMPARE_REGISTER_0);

    time=time+1;
    if(time>=period){
        time=0;
        MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
    }

    for(i=0;times[i]!=-1;i++){
        if(times[i]>time){
            break;
        }
        value=values[i];
    }        MAP_Timer_A_setCompareValue(TIMER_A0_BASE,TIMER_A_CAPTURECOMPARE_REGISTER_1, value);
}

/* This function connects the output of TA0.1 to pin P2.1 */
void redirect(void){
  ......
}

ниже находится project_Zero.c (bluetooth)

/* Standard Defines */ 
#include <string.h> 
#include <stdlib.h> 
 #include<stdbool.h>
  #include <pthread.h>
  #include <mqueue.h>
 #include <semaphore.h> 
/******************************************************************************* * LOCAL FUNCTIONS ******************************************************************************/
static void ProjectZero_init(void);
static void* ProjectZero_taskFxn(void *arg0);
static void* ProjectZero_updateSNP_taskFxn(void *arg0); static void* ProjectZero_buttonTaskFxn(void *arg0);
static void ProjectZero_initServices(void);
static void ProjectZero_asyncCB(uint8_t cmd1, void *pParams); static void ProjectZero_processSNPEventCB(uint16_t event,
snpEventParam_t *param);

 static void buttonDebounceCallbackFxn(Timer_Handle myHandle); static void user_handleButtonPress(button_state_t *pState); static void buttonCallbackFxnBUTTON0(uint_least8_t index);
static void buttonCallbackFxnBUTTON1(uint_least8_t index);
static void updateSNPFxn(Timer_Handle myHandle);
static void ProjectZero_processLEDServiceCB(uint8_t charID);
static void ProjectZero_processLEDServicecccdCB(uint8_t charID, uint16_t value); static void ProjectZero_processButtonServiceCB(uint8_t charID);
static void ProjectZero_processButtonServicecccdCB(uint8_t charID,
uint16_t value);
static void ProjectZero_processDataServiceCB(uint8_t charID);
static void ProjectZero_processDataServicecccdCB(uint8_t charID, uint16_t value);
/******************************************************************************* * PROFILE CALLBACKS ******************************************************************************/
/*
* LED Characteristic value change callback */
BLEProfileCallbacks_t ProjectZero_LEDServiceCBs = { ProjectZero_processLEDServiceCB, ProjectZero_processLEDServicecccdCB };
/*
* Button Characteristic value change callback */
BLEProfileCallbacks_t ProjectZero_ButtonServiceCBs = { ProjectZero_processButtonServiceCB, ProjectZero_processButtonServicecccdCB };

 /*
* Data Characteristic value change callback */
BLEProfileCallbacks_t ProjectZero_DataServiceCBs = { ProjectZero_processDataServiceCB, ProjectZero_processDataServicecccdCB };
/******************************************************************************* * PUBLIC FUNCTIONS ******************************************************************************/
/*******************************************************************************
* @fn ProjectZero_createTask *
* @brief Task creation function for the Simple BLE Peripheral.
*
* @param None. *
* @return None. ******************************************************************************/
void ProjectZero_createTask(void) {
pthread_attr_t pAttrs;
struct sched_param priParam; int retc;
int detachState;
pthread_attr_init(&pAttrs);
priParam.sched_priority = PROJECT_ZERO_TASK_PRIORITY;

 detachState = PTHREAD_CREATE_DETACHED;
retc = pthread_attr_setdetachstate(&pAttrs, detachState);
if (retc != 0) {
while (1) ;
}
pthread_attr_setschedparam(&pAttrs, &priParam);
retc |= pthread_attr_setstacksize(&pAttrs, PROJECT_ZERO_TASK_STACK_SIZE);
if (retc != 0) {
while (1) ;
}
retc = pthread_create(&pzTask, &pAttrs, ProjectZero_taskFxn, NULL);
if (retc != 0) {
while (1) ;
} }

 /*******************************************************************************
* @fn updateSNP_createTask *
* @brief Task creation function to update the SNP.
*
* @param None. *
* @return None. ******************************************************************************/
void updateSNP_createTask(void) {
pthread_attr_t pAttrs;
struct sched_param priParam; int retc;
int detachState;
pthread_attr_init(&pAttrs);
priParam.sched_priority = PROJECT_ZERO_TASK_PRIORITY;
detachState = PTHREAD_CREATE_DETACHED;
retc = pthread_attr_setdetachstate(&pAttrs, detachState);
if (retc != 0) {
while (1) ;
}

 pthread_attr_setschedparam(&pAttrs, &priParam);
retc |= pthread_attr_setstacksize(&pAttrs, PROJECT_ZERO_TASK_STACK_SIZE);
if (retc != 0) {
while (1) ;
}
retc = pthread_create(&snpTask, &pAttrs, ProjectZero_updateSNP_taskFxn, NULL);
if (retc != 0) {
while (1) ;
}
/* Semaphore used to start the SNP update */
sem_init(&updateSNPSemHandle, 1, 0); }
/******************************************************************************* * @fn buttonTask_createTask
*
* @brief Task creation function to notify a button press.

 *
* @param None.
*
* @return None. ******************************************************************************/
void buttonTask_createTask(void) {
pthread_attr_t pAttrs;
struct sched_param priParam; int retc;
int detachState;
struct mq_attr attr;
/* Create RTOS Queue */
attr.mq_flags = 0;
attr.mq_maxmsg = 64;
attr.mq_msgsize = sizeof(button_state_t); attr.mq_curmsgs = 0;
pthread_attr_init(&pAttrs);
priParam.sched_priority = PROJECT_ZERO_TASK_PRIORITY;
detachState = PTHREAD_CREATE_DETACHED;
retc = pthread_attr_setdetachstate(&pAttrs, detachState);
if (retc != 0) {
while (1)

 ; }
pthread_attr_setschedparam(&pAttrs, &priParam);
retc |= pthread_attr_setstacksize(&pAttrs, PROJECT_ZERO_TASK_STACK_SIZE);
if (retc != 0) {
while (1) ;
}
buttonQueueSend = mq_open("ButtonQueue", O_RDWR | O_CREAT | O_NONBLOCK, 0664, &attr);
buttonQueueRec = mq_open("ButtonQueue", O_RDWR | O_CREAT, 0664, &attr);
retc = pthread_create(&buttonTask, &pAttrs, ProjectZero_buttonTaskFxn, NULL);
if (retc != 0) {
while (1) ;
}
/* Semaphore used to start the SNP update */ sem_init(&updateSNPSemHandle, 1, 0);

 }

static void ProjectZero_init(void) {
Timer_Params timerParams; PWM_Params pwmParams; struct mq_attr attr;
/* Create RTOS Queue */ attr.mq_flags = 0;
attr.mq_maxmsg = 64; attr.mq_msgsize = sizeof(uint32_t); attr.mq_curmsgs = 0;
pzQueueRec = mq_open("ProjectZero", O_RDWR | O_CREAT, 0664, &attr); pzQueueSend = mq_open("ProjectZero", O_RDWR | O_CREAT | O_NONBLOCK, 0664,
@fn ProjectZero_init
@brief Called during initialization and contains application specific initialization (ie. hardware initialization/setup, table initialization, power up notification, etc), and profile initialization/setup.
@param None.
@return None.

 &attr);
/* Zeroing out initial value array */ memset(initVal, 0x00, 40);
/* Register Key Handler */
GPIO_setCallback(Board_BUTTON0, buttonCallbackFxnBUTTON0); GPIO_enableInt(Board_BUTTON0); GPIO_setCallback(Board_BUTTON1, buttonCallbackFxnBUTTON1); GPIO_enableInt(Board_BUTTON1);
/* Write to the UART. */ Display_print0(displayOut, 0, 0,
"--------- Project Zero Example ---------"); Display_print0(
displayOut, 0, 0,
"Initializing the user task, hardware, BLE stack and services.");
/* Register to receive notifications from LED service if characteristics have been written to */
LEDService_registerAppCBs(&ProjectZero_LEDServiceCBs);
/* Register to receive notifications from Button service if characteristics have been written to */
ButtonService_registerAppCBs(&ProjectZero_ButtonServiceCBs);
/* Register to receive notifications from Data service if characteristics have been written to */

 DataService_registerAppCBs(&ProjectZero_DataServiceCBs);
/* Create the debounce clock objects for Button 0 and Button 1 */ Timer_Params_init(&timerParams);
/* Setting up clock parameters */
timerParams.period = 50000;
timerParams.periodUnits = TIMER_PERIOD_US; timerParams.timerCallback = buttonDebounceCallbackFxn; timerParams.timerMode = TIMER_ONESHOT_CB; GPIO_setConfig(Board_BUTTON0,
(GPIO_PinConfig) (GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING)); GPIO_setConfig(Board_BUTTON1,
(GPIO_PinConfig) (GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING));
/* Initialize to 50 ms timeout when it is started */ button0DebounceTimer = Timer_open(3, &timerParams); button1DebounceTimer = Timer_open(4, &timerParams);
/* Second button */
timerParams.period = 3000000; timerParams.timerCallback = updateSNPFxn;
/* Initialize to 3 seconds timeout when timer is started. */ updateSNPTimer = Timer_open(0, &timerParams);
/* Creating the PWM Instances */ PWM_Params_init(&pwmParams);

     pwmParams.periodUnits = PWM_PERIOD_COUNTS; 
pwmParams.idleLevel = PWM_IDLE_LOW; 
pwmParams.dutyUnits = PWM_DUTY_COUNTS; 
pwmParams.periodValue = PWM_PERIOD_MAX;
    /* Make the LED red on by default */ 
pwmParams.dutyValue = PWM_PERIOD_MAX; 
pwmRed = PWM_open(Board_PWM0, &pwmParams);
/* Make the LED blue off by default */ pwmParams.dutyValue = 0;
pwmBlue = PWM_open(Board_PWM2, &pwmParams);
/* Make the LED green off by default */ pwmParams.dutyValue = 0;
pwmGreen = PWM_open(Board_PWM1, &pwmParams);
PWM_start(pwmRed); PWM_start(pwmGreen); PWM_start(pwmBlue);
}
/******************************************************************************* * @fn ProjectZero_updateSNP_taskFxn
*
* @brief Application task entry point fto update the SNP.
* ******************************************************************************/

 static void* ProjectZero_updateSNP_taskFxn(void *arg0) {
SBL_Params params; SBL_Image image; uint8_t sblStatus;
while (1) {
if (sem_wait(&updateSNPSemHandle) == 0) {
/* Deactivate Application task */ pthread_cancel(pzTask); pthread_cancel(buttonTask);
/* Close NP so SBL can use serial port */ SAP_close();
/* Initialize SBL parameters and open port to target device */ SBL_initParams(&params);
params.targetInterface = SBL_DEV_INTERFACE_UART; params.localInterfaceID = Board_UART1;
params.resetPinID = Board_DP0; params.blPinID = Board_DP2;
/* If SBL cannot be opened the process cannot proceed */ if ((sblStatus = SBL_open(&params)) == SBL_SUCCESS)
{
/* Reset target and force into SBL code */

 SBL_openTarget();
Display_print0(displayOut, 0, 0, "Programming the CC26xx... ");
/* Notify user that we are updating the SNP */ GPIO_write(Board_LED0, Board_LED_OFF);
/* Turn ON all LEDs */
PWM_setDuty(pwmRed, PWM_PERIOD_MAX); PWM_setDuty(pwmGreen, PWM_PERIOD_MAX); PWM_setDuty(pwmBlue, PWM_PERIOD_MAX);
/* Flash new image to target */
image.imgType = SBL_IMAGE_TYPE_INT; image.imgInfoLocAddr = (uint32_t) &SNP_code[0]; image.imgLocAddr = (uint32_t) &SNP_code[0]; image.imgTargetAddr = SNP_IMAGE_START; sblStatus = SBL_writeImage(&image);
/* Reset target and exit SBL code */ SBL_closeTarget();
/* Close SBL port to target device */
SBL_close(); }
if (sblStatus != SBL_SUCCESS) {

 Display_print0(displayOut, 0, 0, "Programming failed!"); }
else {
Display_print0(displayOut, 0, 0, "Programming passed!"); }
Display_print0(displayOut, 0, 0, "Resetting device.");
usleep(100000);
/* SNP force reset */
MAP_SysCtl_rebootDevice(); }
} }
static void* ProjectZero_buttonTaskFxn(void *arg0) {
uint32_t prio = 0; button_state_t curMessage;
while (1) {
mq_receive(buttonQueueRec, (void*) &curMessage, sizeof(button_state_t), (unsigned int*) &prio);
user_handleButtonPress(&curMessage);

 } }
/******************************************************************************* * @fn ProjectZero_taskFxn
*
* @brief Application task entry point for the Simple BLE Peripheral.
*
******************************************************************************/ static void* ProjectZero_taskFxn(void *arg0)
{
uint32_t pzEvent = 0; struct timespec ts; uint8_t enableAdv = 1; uint8_t disableAdv = 0; uint32_t prio = 0;
/* Initialize State Machine */ projectZeroState = PROJECT_ZERO_RESET;
/* Initialize application */ ProjectZero_init();
/* Application main loop */ while (1)
{
switch (projectZeroState) {

 case PROJECT_ZERO_RESET: {
/* Make sure CC26xx is not in BSL */ GPIO_write(Board_DP0, Board_LED_OFF); GPIO_write(Board_DP2, Board_LED_ON);
usleep(10000);
GPIO_write(Board_DP0, Board_LED_ON);
/* Initialize UART port parameters within SAP parameters */ SAP_initParams(SAP_PORT_REMOTE_UART, &sapParams);
sapParams.port.remote.mrdyPinID = Board_MRDY; sapParams.port.remote.srdyPinID = Board_SRDY; sapParams.port.remote.boardID = Board_UART1;
/* Setup NP module */ SAP_open(&sapParams);
/* Register Application thread's callback to receive asynchronous requests from the NP. */
SAP_setAsyncCB(ProjectZero_asyncCB);
/* Reset the NP, and await a powerup indication.
Clear any pending power indications received prior to this reset call */
clock_gettime(CLOCK_REALTIME, &ts);

 ts.tv_sec += 1;
mq_timedreceive(pzQueueRec, (void*) &pzEvent, sizeof(uint32_t), (unsigned int*) &prio, &ts);
SAP_reset();
WaitForConnection: pzEvent = 0;
mq_receive(pzQueueRec, (void*) &pzEvent, sizeof(uint32_t),
(unsigned int*) &prio);
if (pzEvent == PROJECT_ZERO_EVT_PUI) {
/* Read BD ADDR */
SAP_setParam(SAP_PARAM_HCI, SNP_HCI_OPCODE_READ_BDADDR, 0, NULL);
/* Setup Services - Service creation is blocking so no need to pend */
ProjectZero_initServices();
projectZeroState = PROJECT_ZERO_START_ADV; }
else {
goto WaitForConnection; }
}

 break;
case PROJECT_ZERO_START_ADV: {
/* Turn on user LED to indicate advertising */ GPIO_write(Board_LED0, Board_LED_ON);
/* Set advertising data. */
SAP_setServiceParam(SNP_GGS_SERV_ID, SNP_GGS_DEVICE_NAME_ATT,
sizeof(updateSNPDevName), updateSNPDevName);
SAP_setParam(SAP_PARAM_ADV, SAP_ADV_DATA_NOTCONN, sizeof(advertData), advertData);
/* Set Scan Response data. */ SAP_setParam(SAP_PARAM_ADV, SAP_ADV_DATA_SCANRSP,
sizeof(scanRspData), scanRspData);
/* Enable Advertising and await NP response */ SAP_setParam(SAP_PARAM_ADV, SAP_ADV_STATE, 1, &enableAdv);
WaitForAdvEnable: pzEvent = 0;
mq_receive(pzQueueRec, (void*) &pzEvent, sizeof(uint32_t),
(unsigned int*) &prio);
if (pzEvent != PROJECT_ZERO_EVT_ADV_ENB) {

 goto WaitForAdvEnable; }
/* Wait for connection or button press to cancel advertisement */ WaitForAdvCancel: pzEvent = 0;
mq_receive(pzQueueRec, (void*) &pzEvent, sizeof(uint32_t),
(unsigned int*) &prio);
if (pzEvent == PROJECT_ZERO_EVT_ADV_END) {
projectZeroState = PROJECT_ZERO_START_ADV; }
else if (pzEvent == PROJECT_ZERO_EVT_CONN_EST) {
projectZeroState = PROJECT_ZERO_CONNECTED; }
else {
goto WaitForAdvCancel; }
}
break;
case PROJECT_ZERO_CONNECTED:
/* Before connecting, NP will send the stop ADV message */ WaitForAdvEnd: pzEvent = 0;

 mq_receive(pzQueueRec, (void*) &pzEvent, sizeof(uint32_t), (unsigned int*) &prio);
if (pzEvent != PROJECT_ZERO_EVT_ADV_END) {
goto WaitForAdvEnd; }
/* Events that can happen during connection - Client Disconnection - AP Disconnection */
WaitForAdvEndSent: pzEvent = 0;
mq_receive(pzQueueRec, (void*) &pzEvent, sizeof(uint32_t),
(unsigned int*) &prio);
if (pzEvent != PROJECT_ZERO_EVT_CONN_TERM) {
goto WaitForAdvEndSent; }
/* Client has disconnected from server */ SAP_setParam(SAP_PARAM_CONN, SAP_CONN_STATE, sizeof(connHandle),
(uint8_t *) &connHandle);
WaitForConTerm: pzEvent = 0;
mq_receive(pzQueueRec, (void*) &pzEvent, sizeof(uint32_t),
(unsigned int*) &prio);
if (pzEvent != PROJECT_ZERO_EVT_CONN_TERM)

 {
goto WaitForConTerm;
}
projectZeroState = PROJECT_ZERO_CANCEL_ADV;
break;
case PROJECT_ZERO_CANCEL_ADV:
/* Cancel Advertisement */
SAP_setParam(SAP_PARAM_ADV, SAP_ADV_STATE, 1, &disableAdv);
WaitForCancel: pzEvent = 0;
mq_receive(pzQueueRec, (void*) &pzEvent, sizeof(uint32_t),
(unsigned int*) &prio);
if (pzEvent != PROJECT_ZERO_EVT_ADV_END) {
goto WaitForCancel; }
projectZeroState = PROJECT_ZERO_IDLE; break;
case PROJECT_ZERO_IDLE:
/* Turn off user LED to indicate stop advertising */ GPIO_write(Board_LED0, Board_LED_OFF); projectZeroState = PROJECT_ZERO_START_ADV;

 break;
default: break;
} }
}
/*******************************************************************************
* @fn user_handleButtonPress *
* @brief Handle a debounced button press or release in Task context.
* Invoked by the taskFxn based on a message received from a callback. *
* @param pState pointer to button_state_t message sent from debounce Swi. *
* @return None. ******************************************************************************/
static void user_handleButtonPress(button_state_t *pState) {
/* Update the service with the new value.
Will automatically send notification/indication if enabled. */
switch (pState->pinId) {
case Board_BUTTON0:
ButtonService_setParameter(BS_BUTTON0_ID, sizeof(pState->state), &pState->state);
break;

 case Board_BUTTON1:
ButtonService_setParameter(BS_BUTTON1_ID, sizeof(pState->state),
break; }
}
&pState->state);
/*******************************************************************************
* @fn ProjectZero_initServices *
* @brief Configure SNP and register services.
*
* @param None. *
* @return None. ******************************************************************************/
static void ProjectZero_initServices(void) {
/* Initialization of characteristics in LED_Service that can provide data */ LEDService_setParameter(LS_LED0_ID, LS_LED0_LEN, initVal); LEDService_addService();
/* Initialization of characteristics in Button_Service that can * provide data */
ButtonService_setParameter(BS_BUTTON0_ID, BS_BUTTON0_LEN, initVal); ButtonService_setParameter(BS_BUTTON1_ID, BS_BUTTON1_LEN, initVal); ButtonService_addService();

 /* Initialization of characteristics in Button_Service that can * provide data */
DataService_setParameter(DS_STRING_ID, sizeof(initString), initString); DataService_setParameter(DS_STREAM_ID, DS_STREAM_LEN, initVal); DataService_addService();
SAP_registerEventCB(ProjectZero_processSNPEventCB, 0xFFFF); }
/*
* This is a callback operating in the NPI task.
* These are events this application has registered for. */
static void ProjectZero_processSNPEventCB(uint16_t event, snpEventParam_t *param)
{
uint32_t eventPend;
switch (event)
{
case SNP_CONN_EST_EVT: {
snpConnEstEvt_t * connEstEvt = (snpConnEstEvt_t *) param;
/* Update peer address string */
connHandle = connEstEvt->connHandle; ProfileUtil_convertBdAddr2Str(&peerstr[peerstrIDX], connEstEvt->pAddr);

 /* Notify state machine of established connection */
eventPend = PROJECT_ZERO_EVT_CONN_EST; mq_send(pzQueueSend, (void*) &eventPend, sizeof(uint32_t), 1);
}
break;
case SNP_CONN_TERM_EVT: {
connHandle = PROJECT_ZERO_DEFAULT_CONN_HANDLE;
/* Notify state machine of disconnection event */
eventPend = PROJECT_ZERO_EVT_CONN_TERM; mq_send(pzQueueSend, (void*) &eventPend, sizeof(uint32_t), 1);
}
break;
case SNP_ADV_STARTED_EVT: {
snpAdvStatusEvt_t *advEvt = (snpAdvStatusEvt_t *) param; if (advEvt->status == SNP_SUCCESS)
{
/* Notify state machine of Advertisement Enabled */
eventPend = PROJECT_ZERO_EVT_ADV_ENB; mq_send(pzQueueSend, (void*) &eventPend, sizeof(uint32_t), 1);
} else {
eventPend = PROJECT_ZERO_ERROR;
mq_send(pzQueueSend, (void*) &eventPend, sizeof(uint32_t), 1);

 } }
break;
case SNP_ADV_ENDED_EVT: {
snpAdvStatusEvt_t *advEvt = (snpAdvStatusEvt_t *) param; if (advEvt->status == SNP_SUCCESS)
{
/* Notify state machine of Advertisement Disabled */
eventPend = PROJECT_ZERO_EVT_ADV_END; mq_send(pzQueueSend, (void*) &eventPend, sizeof(uint32_t), 1);
} }
break;
default: break;
} }
/*
* This is a callback operating in the NPI task. These are asynchronous
* indications. */
static void ProjectZero_asyncCB(uint8_t cmd1, void *pParams) {
uint32_t eventPend;

 switch (SNP_GET_OPCODE_HDR_CMD1(cmd1)) {
case SNP_DEVICE_GRP:
{
switch (cmd1)
{
case SNP_POWER_UP_IND:
eventPend = PROJECT_ZERO_EVT_PUI;
mq_send(pzQueueSend, (void*) &eventPend, sizeof(uint32_t), 1); break;
case SNP_HCI_CMD_RSP: {
snpHciCmdRsp_t *hciRsp = (snpHciCmdRsp_t *) pParams; switch (hciRsp->opcode)
{
case SNP_HCI_OPCODE_READ_BDADDR:
ProfileUtil_convertBdAddr2Str(&nwpstr[nwpstrIDX], hciRsp->pData);
break; default:
break; }
}
break;
case SNP_EVENT_IND:

 eventPend = PROJECT_ZERO_EVT_ADV_ENB; mq_send(pzQueueSend, (void*) &eventPend, sizeof(uint32_t), 1); break;
default: break;
} }
break;
default: break;
} }
/*******************************************************************************
* @fn buttonDebounceSwiFxn *
* @brief Callback from timer module on timeout, determines new state
* after debouncing *
* @param buttonId The pin being debounced *
* @return none ******************************************************************************/
static void buttonDebounceCallbackFxn(Timer_Handle myHandle) {
}
/******************************************************************************* * @fn updateSNPFxn

 *
* @brief Callback from Timer module on timeout, starts the SNP Update *
* @param paramId - not used. *
* @return none ******************************************************************************/
static void updateSNPFxn(Timer_Handle myHandle) {
/* Change to UPDATE_SNP */
projectZeroState = PROJECT_ZERO_UPDATE_SNP;
/* Disable buttons interrupts while we update the SNP */ GPIO_disableInt(Board_BUTTON0); GPIO_disableInt(Board_BUTTON1);
/* Post to start the update task */
sem_post(&updateSNPSemHandle); }
/*******************************************************************************
* @fn buttonCallbackFxnBUTTON0 *
* @brief Callback from GPIO driver on interrupt
*
* @param none *
* @return none

 ******************************************************************************/ void buttonCallbackFxnBUTTON0(uint_least8_t index)
{
/* Disable interrupt on the pin */ GPIO_disableInt(Board_BUTTON0); Timer_start(button0DebounceTimer);
}
/*******************************************************************************
* @fn buttonCallbackFxnBUTTON1 *
* @brief Callback from GPIO driver on interrupt
*
* @param none *
* @return none ******************************************************************************/
void buttonCallbackFxnBUTTON1(uint_least8_t index) {
/* Disable interrupt on the pin */ GPIO_disableInt(Board_BUTTON1); Timer_start(button1DebounceTimer);
}
/*

0 ответов

Другие вопросы по тегам