aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-03-28 16:13:17 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-03-28 16:13:17 +0000
commit64f96a5128c0358044efd962e0bcf7caee917348 (patch)
tree48c8793908fdd895df3a09c2e96f44ef89e338fc
parent42a90cc8cebf186c64bbae50a16a90a9979b80f4 (diff)
downloadChibiOS-64f96a5128c0358044efd962e0bcf7caee917348.tar.gz
ChibiOS-64f96a5128c0358044efd962e0bcf7caee917348.tar.bz2
ChibiOS-64f96a5128c0358044efd962e0bcf7caee917348.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@252 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--demos/ARM7-LPC214x-G++/main.cpp20
-rw-r--r--src/lib/ch.hpp15
2 files changed, 28 insertions, 7 deletions
diff --git a/demos/ARM7-LPC214x-G++/main.cpp b/demos/ARM7-LPC214x-G++/main.cpp
index b96a8271f..37147fe91 100644
--- a/demos/ARM7-LPC214x-G++/main.cpp
+++ b/demos/ARM7-LPC214x-G++/main.cpp
@@ -30,6 +30,8 @@ using namespace chibios_rt;
/*
* LED blink sequences.
* NOTE: Sequences must always be terminated by a GOTO instruction.
+ * NOTE: The sequencer language could be easily improved but this is outside
+ * the scope of this demo.
*/
#define SLEEP 0
#define GOTO 1
@@ -42,6 +44,7 @@ typedef struct {
uint32_t value;
} seqop_t;
+// Flashing sequence for LED1.
static const seqop_t LED1_sequence[] =
{
{BITCLEAR, 0x00000400},
@@ -51,6 +54,7 @@ static const seqop_t LED1_sequence[] =
{GOTO, 0}
};
+// Flashing sequence for LED2.
static const seqop_t LED2_sequence[] =
{
{SLEEP, 1000},
@@ -61,6 +65,7 @@ static const seqop_t LED2_sequence[] =
{GOTO, 1}
};
+// Flashing sequence for LED3.
static const seqop_t LED3_sequence[] =
{
{BITCLEAR, 0x80000000},
@@ -70,8 +75,10 @@ static const seqop_t LED3_sequence[] =
{GOTO, 0}
};
-/**
+/*
* Sequencer thread class. It can drive LEDs or other output pins.
+ * Any sequencer is just an instance of this class, all the details are
+ * totally encapsulated and hidden to the application level.
*/
class SequencerThread : EnhancedThread<64> {
private:
@@ -79,7 +86,6 @@ private:
protected:
virtual msg_t Main(void) {
-
while (true) {
switch(curr->action) {
case SLEEP:
@@ -102,15 +108,14 @@ protected:
}
public:
- SequencerThread(const seqop_t *sequence):
- EnhancedThread<64>("sequencer", NORMALPRIO, 0) {
+ SequencerThread(const seqop_t *sequence) : EnhancedThread<64>("sequencer") {
base = curr = sequence;
}
};
/*
- * Executed as event handler at 500mS intervals.
+ * Executed as an event handler at 500mS intervals.
*/
static void TimerHandler(eventid_t id) {
@@ -120,6 +125,7 @@ static void TimerHandler(eventid_t id) {
/*
* Entry point, the interrupts are disabled on entry.
+ * This is the real "application".
*/
int main(int argc, char **argv) {
static const evhandler_t evhndl[] = {
@@ -130,9 +136,9 @@ int main(int argc, char **argv) {
System::Init(); // ChibiOS/RT goes live here.
- evtInit(&evt, 500); // Initializes an event timer object.
+ evtInit(&evt, 500); // Initializes an event timer.
evtStart(&evt); // Starts the event timer.
- chEvtRegister(&evt.et_es, &el0, 0); // Registers on the timer event source.
+ chEvtRegister(&evt.et_es, &el0, 0); // Registers a listener on the source.
/*
* Starts serveral instances of the SequencerThread class, each one operating
diff --git a/src/lib/ch.hpp b/src/lib/ch.hpp
index 177e9bb46..4b4ef196e 100644
--- a/src/lib/ch.hpp
+++ b/src/lib/ch.hpp
@@ -195,11 +195,26 @@ namespace chibios_rt {
public:
const char *name;
+ /**
+ * Full constructor. It allows to set a priority level for the new thread
+ * and specify the special option flags.
+ */
EnhancedThread(const char *tname, tprio_t prio, tmode_t mode) :
BaseThread(prio, mode, wa, sizeof wa) {
name = tname;
}
+
+ /**
+ * Simplified constructor, it allows to create a thread by simply
+ * specifying a name. In is assumed /p NORMALPRIO as initial priority
+ * and no special option flags.
+ */
+ EnhancedThread(const char *tname) :
+ BaseThread(NORMALPRIO, 0, wa, sizeof wa) {
+
+ name = tname;
+ }
};
#ifdef CH_USE_SEMAPHORES