aboutsummaryrefslogtreecommitdiffstats
path: root/demos/STM32
diff options
context:
space:
mode:
authorTexZK <texzk@email.it>2015-07-08 21:57:53 +0200
committerTexZK <texzk@email.it>2015-07-08 21:57:53 +0200
commit5270aa500f88e13ae2f9cebded4271d52d08706c (patch)
tree6591594bdc3c563021aee2a0838d0dbf7a654855 /demos/STM32
parent567cfe388f25ae32621ac3f2d7d27b94cab617be (diff)
downloadChibiOS-Contrib-5270aa500f88e13ae2f9cebded4271d52d08706c.tar.gz
ChibiOS-Contrib-5270aa500f88e13ae2f9cebded4271d52d08706c.tar.bz2
ChibiOS-Contrib-5270aa500f88e13ae2f9cebded4271d52d08706c.zip
Added descriptions and code simplified
Diffstat (limited to 'demos/STM32')
-rw-r--r--demos/STM32/RT-STM32F429-DISCOVERY-DMA2D/main.c2
-rw-r--r--demos/STM32/RT-STM32F429-DISCOVERY-TRIBUF/main.c40
-rw-r--r--demos/STM32/RT-STM32F429-DISCOVERY-TRIBUF/readme.txt29
3 files changed, 40 insertions, 31 deletions
diff --git a/demos/STM32/RT-STM32F429-DISCOVERY-DMA2D/main.c b/demos/STM32/RT-STM32F429-DISCOVERY-DMA2D/main.c
index a8f8007..d0b07d3 100644
--- a/demos/STM32/RT-STM32F429-DISCOVERY-DMA2D/main.c
+++ b/demos/STM32/RT-STM32F429-DISCOVERY-DMA2D/main.c
@@ -474,8 +474,6 @@ static void dma2d_test(void) {
/* Command line related. */
/*===========================================================================*/
-#define RTT2MS(ticks) ((ticks) / (STM32_HCLK / 1000UL))
-
#if HAL_USE_SERIAL_USB
/* Virtual serial port over USB.*/
SerialUSBDriver SDU1;
diff --git a/demos/STM32/RT-STM32F429-DISCOVERY-TRIBUF/main.c b/demos/STM32/RT-STM32F429-DISCOVERY-TRIBUF/main.c
index 145e068..25ffd87 100644
--- a/demos/STM32/RT-STM32F429-DISCOVERY-TRIBUF/main.c
+++ b/demos/STM32/RT-STM32F429-DISCOVERY-TRIBUF/main.c
@@ -66,33 +66,37 @@ static char buffer_a, buffer_b, buffer_c;
static const char text[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n";
-/*
- * Reads from the front buffer.
+/**
+ * @brief Reads from the front buffer.
+ *
+ * @return Buffered character from @p text or special symbol.
+ * @retval '.' No new front buffer within timeout.
*/
static char read_front(void) {
const char *front;
msg_t error;
+ char c;
/* Wait until a new front buffer gets available with prepared data */
- chSysLock();
- error = tribufWaitReadyTimeoutS(&tribuf_handler, reader_timeout);
- if (error == MSG_TIMEOUT) {
- chSysUnlock();
- return (reader_timeout == TIME_IMMEDIATE) ? '.' : '@';
+ error = tribufWaitReadyTimeout(&tribuf_handler, reader_timeout);
+ if (error == MSG_OK) {
+ /* Retrieve the new front buffer */
+ tribufSwapFront(&tribuf_handler);
+ front = (const char *)tribufGetFront(&tribuf_handler);
+
+ /* Read data from the new front buffer */
+ c = front[0];
+ } else {
+ c = '.'; /* Timeout placeholder */
}
- chSysUnlock();
-
- /* Retrieve the new front buffer */
- tribufSwapFront(&tribuf_handler);
- front = (const char *)tribufGetFront(&tribuf_handler);
-
- /* Read data from the new front buffer */
- return front[0];
+ return c;
}
/*
- * Overwrites the back buffer with the provided character.
+ * @brief Overwrites the back buffer with the provided character.
+ *
+ * @param[in] c Character to store into the current back buffer.
*/
static void write_back(char c) {
@@ -123,9 +127,11 @@ static THD_FUNCTION(reader_thread, arg) {
old_priority = chThdGetPriorityX();
for (;;) {
+ /* Read from the fron buffer and print the retrieved character */
c = read_front();
chprintf(chout, "%c", c);
+ /* Change priority, suspend or delay */
osalSysLock();
palTogglePad(GPIOG, GPIOG_LED3_GREEN);
if (old_priority != reader_priority) {
@@ -160,9 +166,11 @@ static THD_FUNCTION(writer_thread, arg) {
for (;;) {
for (i = 0; i < sizeof(text); ++i) {
+ /* Write the next character on the current back buffer */
c = text[i];
write_back(c);
+ /* Change priority, suspend or delay */
osalSysLock();
palTogglePad(GPIOG, GPIOG_LED4_RED);
if (old_priority != writer_priority) {
diff --git a/demos/STM32/RT-STM32F429-DISCOVERY-TRIBUF/readme.txt b/demos/STM32/RT-STM32F429-DISCOVERY-TRIBUF/readme.txt
index 7a0b396..cc7f406 100644
--- a/demos/STM32/RT-STM32F429-DISCOVERY-TRIBUF/readme.txt
+++ b/demos/STM32/RT-STM32F429-DISCOVERY-TRIBUF/readme.txt
@@ -8,20 +8,23 @@ The demo runs on an ST STM32F429I-Discovery board.
** The Demo **
-A simple command shell is activated on virtual serial port SD1.
-TODO
+This demo shows how to use a triple buffer handler, with one writer thread and
+one reader thread.
+The writer thread puts a character into the current back buffer, thus swapping
+the back buffer with the orphan buffer for a new write. The writer then sleeps
+for a specified delay in milliseconds.
+The reader thread gets waits (if there is a timeout) until the orphan buffer
+contains available data, becoming the new front buffer. The character is read
+from the new front buffer and printed. The reader then sleeps for a specified
+delay in milliseconds.
+A simple command shell is activated on virtual serial port SD1 or SDU1.
+Via command line it is possible to start, stop, set the delay, and set the
+thread priority of the reader and writer threads.
+The reader can also be assigned a wait timeout in milliseconds, with special
+cases of "*" for infinite timeout, and "-" (or 0 ms) for none.
** Build Procedure **
-The demo has been tested by using the free Codesourcery GCC-based toolchain
-and YAGARTO. just modify the TRGT line in the makefile in order to use
+The demo has been tested by using the free GNU Tools ARM Embedded toolchain
+and ChibiStudio. Just modify the TRGT line in the makefile in order to use
different GCC toolchains.
-
-** Notes **
-
-Some files used by the demo are not part of ChibiOS/RT but are copyright of
-ST Microelectronics and are licensed under a different license.
-Also note that not all the files present in the ST library are distributed
-with ChibiOS/RT, you can find the whole library on the ST web site:
-
- http://www.st.com