aboutsummaryrefslogtreecommitdiffstats
path: root/demos/ARM7-LPC214x-G++/main.cpp
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-03-27 12:33:31 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-03-27 12:33:31 +0000
commit165bcc4a0708ff3252fe73156eace36b5980dbf9 (patch)
tree713cd625a9645d3313a773f696e3ad09df58b93b /demos/ARM7-LPC214x-G++/main.cpp
parentef14f74f92fb52d0028eb36b7b48b7e7c4ef52c4 (diff)
downloadChibiOS-165bcc4a0708ff3252fe73156eace36b5980dbf9.tar.gz
ChibiOS-165bcc4a0708ff3252fe73156eace36b5980dbf9.tar.bz2
ChibiOS-165bcc4a0708ff3252fe73156eace36b5980dbf9.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@249 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'demos/ARM7-LPC214x-G++/main.cpp')
-rw-r--r--demos/ARM7-LPC214x-G++/main.cpp52
1 files changed, 31 insertions, 21 deletions
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 <ch.hpp>
+
#include <evtimer.h>
+#include <test.h>
#include <lpc214x.h>
#include <lpc214x_serial.h>
@@ -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;