CMSIS Example - Mail and Timer

來源:互聯網
上載者:User

標籤:des   style   blog   color   os   art   

12    #include <stdint.h>3    4    #include "bsp-fifisdr.h"5    6    #include "lpclib.h"7    #include "task-gui.h"8    9    10    #define GUI_QUEUE_LENGTH                        (4)11    12    13    typedef struct {14        uint8_t opcode;15    } GUI_Message;16    17    18    /** Message opcodes for GUI task. */19    enum {20        GUI_OPCODE_LED_TICK,21    };22    23    24    /** Identifiers for OS timers. */25    enum {26        GUI_TIMERMAGIC_LED,27    };28    29    30    /** Local task context. */31    static struct {32        osMailQId queue;33        osTimerId ledTick;34        int led;35    } gui;36    37    38    39    static void GUI_osalCallback (void const *pArgument)40    {41        (void) pArgument;42    43        if (gui.queue == NULL) {44            return;45        }46    47        GUI_Message *pMessage = osMailAlloc(gui.queue, 0);48    49        if (pMessage == NULL) {50            return;51        }52    53        pMessage->opcode = GUI_OPCODE_LED_TICK;54        osMailPut(gui.queue, pMessage);55    }56    57    58    osMailQDef(guiQueue, GUI_QUEUE_LENGTH, GUI_Message);59    osTimerDef(led, GUI_osalCallback);60    61    void GUI_task (const void *pArgs)62    {63        (void) pArgs;64        GUI_Message *pMessage;65        osEvent event;66    67    68        gui.queue = osMailCreate(osMailQ(guiQueue), NULL);69    70        gui.ledTick = osTimerCreate(osTimer(led), osTimerPeriodic, (void *)GUI_TIMERMAGIC_LED);71        osTimerStart(gui.ledTick, 500);72    73        while (1) {74            /* Is there a new message? */75            event = osMailGet(gui.queue, osWaitForever);76            if (event.status == osEventMail) {77                pMessage = (GUI_Message *)event.value.p;78                switch (pMessage->opcode) {79                case GUI_OPCODE_LED_TICK:80                    gui.led = gui.led ^ 1;81                    BSP_setLed(gui.led);82                    break;83                }84    85                osMailFree(gui.queue, pMessage);86            }87        }88    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.