CC2640定义一个周期性事件的步骤


1、定义一个时钟结构体 
    static Clock_Struct clk_spa;
2、将周期性事件ID传递给时钟处理程序的内存
    // Application events
    #define SP_STATE_CHANGE_EVT                  0
    #define SP_CHAR_CHANGE_EVT                   1
    #define SP_KEY_CHANGE_EVT                    2
    #define SP_ADV_EVT                           3
    //添加自定义事件ID
    #define SPA_EVT                              10//不要和其他事件ID重复
    spClockEventData_t arg_SPA =
        { .event = SPA_EVT };
3、定义执行的周期函数
    static void SPA_performPeriodicTask(void)
    {
        static int aa = 0;
        Display_printf(dispHandle, 20, 0, "========%d============",aa++);
    }
4、在处理传入的GAP事件的函数中添加时钟初始化函数,参数1000毫秒,其余参数看函数声明
    static void SimplePeripheral_processGapMessage(gapEventHdr_t *pMsg){
        //--------------------------------------------
        // Create one-shot clock event.
        Util_constructClock(&clk_spa, SimplePeripheral_clockHandler,
                1000, 0, true,
                    (UArg) &arg_SPA);
    }
5、在时钟超时处理函数中添加
    static void SimplePeripheral_clockHandler(UArg arg){
        //---------------------------------------------
        else if (pData->event == SPA_EVT)
        {
            //Start the next period
            Util_startClock(&clk_spa);
            //Post event queueMsg
            SimplePeripheral_enqueueMsg(SPA_EVT, NULL);
        }
    }

6、在处理的消息的函数中添加case
    static void SimplePeripheral_processAppMsg(spEvt_t *pMsg){
        //---------------------------------------------
        case SPA_EVT:
            SPA_performPeriodicTask();
            break;
    }

7、也可以把再次启动函数放到执行函数中,这样就执行完成以后再次启动执行
    static void SPA_performPeriodicTask(void)
    {
        static int aa = 0;
        Display_printf(dispHandle, 20, 0, "========%d============",aa++);
        Util_startClock(&clk_spa);
    }
    
8、运行截图

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章