From 165bcc4a0708ff3252fe73156eace36b5980dbf9 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 27 Mar 2008 12:33:31 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@249 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/ARM7-LPC214x-G++/main.cpp | 52 ++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'demos/ARM7-LPC214x-G++/main.cpp') diff --git a/demos/ARM7-LPC214x-G++/main.cpp b/demos/ARM7-LPC214x-G++/main.cpp index b3c4f8e45..1d8acfb5e 100644 --- a/demos/ARM7-LPC214x-G++/main.cpp +++ b/demos/ARM7-LPC214x-G++/main.cpp @@ -18,7 +18,9 @@ */ #include + #include +#include #include #include @@ -29,9 +31,10 @@ using namespace chibios_rt; * LED blinking sequences. */ #define SLEEP 0 -#define STOP 1 -#define BITCLEAR 2 -#define BITSET 3 +#define GOTO 1 +#define STOP 2 +#define BITCLEAR 3 +#define BITSET 4 typedef struct { uint8_t action; @@ -43,7 +46,8 @@ bitop_t LED1_sequence[] = {BITCLEAR, 0x00000400}, {SLEEP, 200}, {BITSET, 0x00000400}, - {SLEEP, 1800} + {SLEEP, 1800}, + {GOTO, 0} }; bitop_t LED2_sequence[] = @@ -52,7 +56,8 @@ bitop_t LED2_sequence[] = {BITCLEAR, 0x00000800}, {SLEEP, 200}, {BITSET, 0x00000800}, - {SLEEP, 800} + {SLEEP, 1800}, + {GOTO, 1} }; bitop_t LED3_sequence[] = @@ -60,13 +65,14 @@ bitop_t LED3_sequence[] = {BITCLEAR, 0x80000000}, {SLEEP, 200}, {BITSET, 0x80000000}, - {SLEEP, 300} + {SLEEP, 300}, + {GOTO, 0} }; /** - * LED blinker thread class. + * Blinker thread class. It can drive LEDs or other output pins. */ -class BlinkerThread : chibios_rt::BaseThread { +class BlinkerThread : BaseThread { private: WorkingArea(wa, 64); bitop_t *base, *curr, *top; @@ -79,6 +85,9 @@ protected: case SLEEP: Sleep(curr->value); break; + case GOTO: + curr = &base[curr->value]; + continue; case STOP: return 0; case BITCLEAR: @@ -88,23 +97,17 @@ protected: IO0SET = curr->value; break; } - if (++curr >= top) - curr = base; + curr++; } } public: - BlinkerThread(bitop_t *sequence, int n) : BaseThread(NORMALPRIO, 0, wa, sizeof wa) { + BlinkerThread(bitop_t *sequence) : BaseThread(NORMALPRIO, 0, wa, sizeof wa) { base = curr = sequence; - top = sequence + n; } }; -extern "C" { - msg_t TestThread(void *p); -} - /* * Executed as event handler at 500mS intervals. */ @@ -130,11 +133,18 @@ int main(int argc, char **argv) { evtStart(&evt); /* Starts the event timer. */ chEvtRegister(&evt.et_es, &el0, 0); /* Registers on the timer event source. */ - BlinkerThread blinker1(LED1_sequence, sizeof(LED1_sequence) / sizeof(bitop_t)); - BlinkerThread blinker2(LED2_sequence, sizeof(LED2_sequence) / sizeof(bitop_t)); - BlinkerThread blinker3(LED3_sequence, sizeof(LED3_sequence) / sizeof(bitop_t)); - - while(1) + /* + * Starts serveral instances of the BlinkerThread class, each one operating + * on a different LED. + */ + BlinkerThread blinker1(LED1_sequence); + BlinkerThread blinker2(LED2_sequence); + BlinkerThread blinker3(LED3_sequence); + + /* + * Serves timer events. + */ + while (true) Event::Wait(ALL_EVENTS, evhndl); return 0; -- cgit v1.2.3