• CC2640R2F&TI-RTOS 拿到 TI CC2640R2F 开发板 第四件事就是 修改第三件事信号量超时改为 事件 超时,并增加 事件控制 ,用于控制LED 闪烁时间或者关闭


    /*
     * data_process.c
     *
     *  Created on: 2018年7月5日
     *      Author: admin
     */
    
    
    #include "board_led.h"
    #include "board_uart.h"
    
    #include "data_process.h"
    
    
    // Task configuration
    #define LF_TASK_PRIORITY      1
    #define LF_TASK_STACK_SIZE   512
    
    // Task configuration
    Task_Struct lfTask;
    Char lfTaskStack[LF_TASK_STACK_SIZE];
    
    Event_Handle eventLedFickerHandle;
    
    
    
    /*********************************************************************
     * @fn      LedFicker_createTask
     *
     * @brief   Task creation function for the led ficker.
     *
     * @param   None.
     *
     * @return  None.
     */
    void LedFicker_createTask(void)
    {
      Task_Params taskParams;
    
      // Configure task
      Task_Params_init(&taskParams);
      taskParams.stack = lfTaskStack;
      taskParams.stackSize = LF_TASK_STACK_SIZE;
      taskParams.priority  = LF_TASK_PRIORITY;
    
      Task_construct(&lfTask, LedFicker_taskFxn, &taskParams, NULL);
    }
    
    /*********************************************************************
     * @fn      LedFicker_taskFxn
     *
     * @brief   Application task entry point for the Led Ficker.
     *
     * @param   a0, a1 - not used.
     *
     * @return  None.
     */
    static void LedFicker_taskFxn(UArg a0, UArg a1)
    {/* LED 闪烁任务,默认200ms闪烁一次,可以通过事件通知的方式更改LED闪烁频率 */
    
        uint32_t events;
        uint32_t timeoutInTicks = 200 * (1000/Clock_tickPeriod);
    
        Event_Params eventParams;
        Event_Struct structEvent; /* Memory allocated at build time */
    
        Event_Params_init(&eventParams);
        Event_construct(&structEvent, &eventParams);
    
        /* It's optional to store the handle */
        eventLedFickerHandle = Event_handle(&structEvent);
    
        if (eventLedFickerHandle == NULL) {
            /* PIN_open() failed */
            bspDebugPrintf( true,"eventLedFickerHandle Init false.
    " );
            while (1);
        }
        else
        {
          bspDebugPrintf( true,"eventLedFickerHandle Init ok.
    " );
        }
    
        // Application main loop
        for (;;)
        {
    
            /* Wait for an event to be posted */
            events = Event_pend(eventLedFickerHandle,
                                Event_Id_NONE,
                                LED_FICKER_OFF_EVT |
                                LED_FICKER_100MS_EVT |
                                LED_FICKER_1S_EVT,
                                timeoutInTicks);
    
            //翻转LED灯
            ledBoardToggle( ledBlueBoard );
            ledBoardToggle( ledRedBoard );
    
            if (events & LED_FICKER_OFF_EVT)
            {
                timeoutInTicks = BIOS_WAIT_FOREVER;/* 超时时间改为永久,这样就关闭了LED */
    
                //关闭LED灯
                ledBoardOff( ledBlueBoard );
                ledBoardOff( ledRedBoard );
            }
    
            if (events & LED_FICKER_100MS_EVT)
            {
                timeoutInTicks =  100 * (1000/Clock_tickPeriod);/* 超时时间改为100ms,这样LED就会100ms翻转一次 */
            }
    
            if (events & LED_FICKER_1S_EVT)
            {
                timeoutInTicks = 1000 * (1000/Clock_tickPeriod);/* 超时时间改为1s,这样LED就会1s翻转一次 */
            }
    
        }
    }
    
    void eventLedFicker_post( uint32_t event )
    {
        if( eventLedFickerHandle )
            Event_post(eventLedFickerHandle, event);
    }
    /*
     * data_process.h
     *
     *  Created on: 2018年7月5日
     *      Author: admin
     */
    
    #ifndef APPLICATION_DATA_PROCESS_H_
    #define APPLICATION_DATA_PROCESS_H_
    
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/knl/Event.h>
    #include <ti/sysbios/BIOS.h>
    
    #define LED_FICKER_OFF_EVT            Event_Id_00 /* led 闪烁关闭 */
    #define LED_FICKER_100MS_EVT          Event_Id_01 /* led 100MS 闪烁一次 */
    #define LED_FICKER_1S_EVT             Event_Id_02 /* led 1S 闪烁一次 */
    
    void LedFicker_createTask(void);
    
    static void LedFicker_taskFxn(UArg a0, UArg a1);
    
    void eventLedFicker_post( uint32_t event );
    
    #endif /* APPLICATION_DATA_PROCESS_H_ */

    官方教程链接

    BLE5-Stack User’s Guide

    CC2640R2F / CC2640 / CC2650入门和常见问题解答

  • 相关阅读:
    VScode 最新eslint设置
    vue部署在二级目录
    实现网页比12像素小
    css一个很好用的hover显示
    VSCode设置
    vue发布后的一些问题
    设置cssrem,设置emmet
    js时间与时间戳之间的转换操作,返回天、小时、分,全家桶
    Error resolving template [xxx], template might not exist or might not be exist
    解决jenkins shell执行sonar-scanner提示命令存在的问题
  • 原文地址:https://www.cnblogs.com/suozhang/p/9269427.html
Copyright © 2020-2023  润新知