aboutsummaryrefslogtreecommitdiffstats
path: root/demos/STM32/RT-STM32F407-DISCOVERY-G++/main.cpp
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2018-04-24 09:45:27 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2018-04-24 09:45:27 +0000
commitf6c360002daa5b9c18386f5d14ce22d3184a7b3f (patch)
tree941a7f22afe398b6267bee08c60f1251f4f46efb /demos/STM32/RT-STM32F407-DISCOVERY-G++/main.cpp
parent389d66c31a859a08c02b03565b50801bc93b592d (diff)
downloadChibiOS-f6c360002daa5b9c18386f5d14ce22d3184a7b3f.tar.gz
ChibiOS-f6c360002daa5b9c18386f5d14ce22d3184a7b3f.tar.bz2
ChibiOS-f6c360002daa5b9c18386f5d14ce22d3184a7b3f.zip
Updated C++ demo.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11954 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'demos/STM32/RT-STM32F407-DISCOVERY-G++/main.cpp')
-rw-r--r--demos/STM32/RT-STM32F407-DISCOVERY-G++/main.cpp103
1 files changed, 77 insertions, 26 deletions
diff --git a/demos/STM32/RT-STM32F407-DISCOVERY-G++/main.cpp b/demos/STM32/RT-STM32F407-DISCOVERY-G++/main.cpp
index 6c09344f4..02cf79a15 100644
--- a/demos/STM32/RT-STM32F407-DISCOVERY-G++/main.cpp
+++ b/demos/STM32/RT-STM32F407-DISCOVERY-G++/main.cpp
@@ -22,6 +22,33 @@
using namespace chibios_rt;
/*
+ * Message server thread class. It receives messages and does nothing except
+ * reply after the specified time.
+ */
+class MessageServerThread : public BaseStaticThread<256> {
+
+protected:
+ void main(void) override {
+
+ setName("server");
+
+ while (true) {
+ ThreadReference sender = waitMessage();
+ time_msecs_t msecs = (time_msecs_t)sender.getMessage();
+ sleep(TIME_MS2I(msecs));
+ sender.releaseMessage(0);
+ }
+ }
+
+public:
+ MessageServerThread(void) : BaseStaticThread<256>() {
+ }
+};
+
+/* Reference to the server thread.*/
+static ThreadReference sref;
+
+/*
* 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
@@ -32,50 +59,63 @@ using namespace chibios_rt;
#define STOP 2
#define BITCLEAR 3
#define BITSET 4
+#define MESSAGE 5
typedef struct {
uint8_t action;
- uint32_t value;
+ union {
+ msg_t msg;
+ uint32_t value;
+ ioline_t line;
+ };
} seqop_t;
// Flashing sequence for LED3.
static const seqop_t LED3_sequence[] =
{
- {BITSET, PAL_PORT_BIT(GPIOD_LED3)},
- {SLEEP, 800},
- {BITCLEAR, PAL_PORT_BIT(GPIOD_LED3)},
- {SLEEP, 200},
- {GOTO, 0}
+ {BITSET, LINE_LED3},
+ {SLEEP, 800},
+ {BITCLEAR, LINE_LED3},
+ {SLEEP, 200},
+ {GOTO, 0}
};
// Flashing sequence for LED4.
static const seqop_t LED4_sequence[] =
{
- {BITSET, PAL_PORT_BIT(GPIOD_LED4)},
- {SLEEP, 600},
- {BITCLEAR, PAL_PORT_BIT(GPIOD_LED4)},
- {SLEEP, 400},
- {GOTO, 0}
+ {BITSET, LINE_LED4},
+ {SLEEP, 600},
+ {BITCLEAR, LINE_LED4},
+ {SLEEP, 400},
+ {GOTO, 0}
};
// Flashing sequence for LED5.
static const seqop_t LED5_sequence[] =
{
- {BITSET, PAL_PORT_BIT(GPIOD_LED5)},
- {SLEEP, 400},
- {BITCLEAR, PAL_PORT_BIT(GPIOD_LED5)},
- {SLEEP, 600},
- {GOTO, 0}
+ {BITSET, LINE_LED5},
+ {SLEEP, 400},
+ {BITCLEAR, LINE_LED5},
+ {SLEEP, 600},
+ {GOTO, 0}
};
// Flashing sequence for LED6.
static const seqop_t LED6_sequence[] =
{
- {BITSET, PAL_PORT_BIT(GPIOD_LED6)},
- {SLEEP, 200},
- {BITCLEAR, PAL_PORT_BIT(GPIOD_LED6)},
- {SLEEP, 800},
- {GOTO, 0}
+ {BITSET, LINE_LED6},
+ {SLEEP, 200},
+ {BITCLEAR, LINE_LED6},
+ {SLEEP, 800},
+ {GOTO, 0}
+};
+
+// Message sequence.
+static const seqop_t msg_sequence[] =
+{
+ {MESSAGE, 50},
+ {SLEEP, 1000},
+ {GOTO, 0}
};
/*
@@ -88,7 +128,7 @@ private:
const seqop_t *base, *curr; // Thread local variables.
protected:
- virtual void main(void) {
+ void main(void) override {
setName("sequencer");
@@ -103,10 +143,13 @@ protected:
case STOP:
return;
case BITCLEAR:
- palClearPort(GPIOD, curr->value);
+ palClearLine(curr->line);
break;
case BITSET:
- palSetPort(GPIOD, curr->value);
+ palSetLine(curr->line);
+ break;
+ case MESSAGE:
+ sref.sendMessage(curr->msg);
break;
}
curr++;
@@ -126,7 +169,7 @@ public:
class TesterThread : public BaseStaticThread<256> {
protected:
- virtual void main(void) {
+ void main(void) override {
setName("tester");
@@ -142,10 +185,12 @@ public:
/* Static threads instances.*/
static TesterThread tester;
+static MessageServerThread server_thread;
static SequencerThread blinker1(LED3_sequence);
static SequencerThread blinker2(LED4_sequence);
static SequencerThread blinker3(LED5_sequence);
static SequencerThread blinker4(LED6_sequence);
+static SequencerThread sender1(msg_sequence);
/*
* Application entry point.
@@ -171,13 +216,19 @@ int main(void) {
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
/*
+ * Starting the message server thread, storing the returned reference.
+ */
+ sref = server_thread.start(NORMALPRIO + 20);
+
+ /*
* Starts several instances of the SequencerThread class, each one operating
- * on a different LED.
+ * on a different sequence.
*/
blinker1.start(NORMALPRIO + 10);
blinker2.start(NORMALPRIO + 10);
blinker3.start(NORMALPRIO + 10);
blinker4.start(NORMALPRIO + 10);
+ sender1.start(NORMALPRIO + 10);
/*
* Serves timer events.