码迷,mamicode.com
首页 > 其他好文 > 详细

CMSIS Example - Mail and Timer

时间:2014-07-19 08:33:01      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   os   art   

1
2    #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    }

CMSIS Example - Mail and Timer,布布扣,bubuko.com

CMSIS Example - Mail and Timer

标签:des   style   blog   color   os   art   

原文地址:http://www.cnblogs.com/shangdawei/p/3854411.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!