Added descriptions and code simplified
This commit is contained in:
parent
567cfe388f
commit
5270aa500f
|
@ -474,8 +474,6 @@ static void dma2d_test(void) {
|
||||||
/* Command line related. */
|
/* Command line related. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
#define RTT2MS(ticks) ((ticks) / (STM32_HCLK / 1000UL))
|
|
||||||
|
|
||||||
#if HAL_USE_SERIAL_USB
|
#if HAL_USE_SERIAL_USB
|
||||||
/* Virtual serial port over USB.*/
|
/* Virtual serial port over USB.*/
|
||||||
SerialUSBDriver SDU1;
|
SerialUSBDriver SDU1;
|
||||||
|
|
|
@ -66,33 +66,37 @@ static char buffer_a, buffer_b, buffer_c;
|
||||||
|
|
||||||
static const char text[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n";
|
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) {
|
static char read_front(void) {
|
||||||
|
|
||||||
const char *front;
|
const char *front;
|
||||||
msg_t error;
|
msg_t error;
|
||||||
|
char c;
|
||||||
|
|
||||||
/* Wait until a new front buffer gets available with prepared data */
|
/* Wait until a new front buffer gets available with prepared data */
|
||||||
chSysLock();
|
error = tribufWaitReadyTimeout(&tribuf_handler, reader_timeout);
|
||||||
error = tribufWaitReadyTimeoutS(&tribuf_handler, reader_timeout);
|
if (error == MSG_OK) {
|
||||||
if (error == MSG_TIMEOUT) {
|
|
||||||
chSysUnlock();
|
|
||||||
return (reader_timeout == TIME_IMMEDIATE) ? '.' : '@';
|
|
||||||
}
|
|
||||||
chSysUnlock();
|
|
||||||
|
|
||||||
/* Retrieve the new front buffer */
|
/* Retrieve the new front buffer */
|
||||||
tribufSwapFront(&tribuf_handler);
|
tribufSwapFront(&tribuf_handler);
|
||||||
front = (const char *)tribufGetFront(&tribuf_handler);
|
front = (const char *)tribufGetFront(&tribuf_handler);
|
||||||
|
|
||||||
/* Read data from the new front buffer */
|
/* Read data from the new front buffer */
|
||||||
return front[0];
|
c = front[0];
|
||||||
|
} else {
|
||||||
|
c = '.'; /* Timeout placeholder */
|
||||||
|
}
|
||||||
|
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) {
|
static void write_back(char c) {
|
||||||
|
|
||||||
|
@ -123,9 +127,11 @@ static THD_FUNCTION(reader_thread, arg) {
|
||||||
old_priority = chThdGetPriorityX();
|
old_priority = chThdGetPriorityX();
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
/* Read from the fron buffer and print the retrieved character */
|
||||||
c = read_front();
|
c = read_front();
|
||||||
chprintf(chout, "%c", c);
|
chprintf(chout, "%c", c);
|
||||||
|
|
||||||
|
/* Change priority, suspend or delay */
|
||||||
osalSysLock();
|
osalSysLock();
|
||||||
palTogglePad(GPIOG, GPIOG_LED3_GREEN);
|
palTogglePad(GPIOG, GPIOG_LED3_GREEN);
|
||||||
if (old_priority != reader_priority) {
|
if (old_priority != reader_priority) {
|
||||||
|
@ -160,9 +166,11 @@ static THD_FUNCTION(writer_thread, arg) {
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
for (i = 0; i < sizeof(text); ++i) {
|
for (i = 0; i < sizeof(text); ++i) {
|
||||||
|
/* Write the next character on the current back buffer */
|
||||||
c = text[i];
|
c = text[i];
|
||||||
write_back(c);
|
write_back(c);
|
||||||
|
|
||||||
|
/* Change priority, suspend or delay */
|
||||||
osalSysLock();
|
osalSysLock();
|
||||||
palTogglePad(GPIOG, GPIOG_LED4_RED);
|
palTogglePad(GPIOG, GPIOG_LED4_RED);
|
||||||
if (old_priority != writer_priority) {
|
if (old_priority != writer_priority) {
|
||||||
|
|
|
@ -8,20 +8,23 @@ The demo runs on an ST STM32F429I-Discovery board.
|
||||||
|
|
||||||
** The Demo **
|
** The Demo **
|
||||||
|
|
||||||
A simple command shell is activated on virtual serial port SD1.
|
This demo shows how to use a triple buffer handler, with one writer thread and
|
||||||
TODO
|
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 **
|
** Build Procedure **
|
||||||
|
|
||||||
The demo has been tested by using the free Codesourcery GCC-based toolchain
|
The demo has been tested by using the free GNU Tools ARM Embedded toolchain
|
||||||
and YAGARTO. just modify the TRGT line in the makefile in order to use
|
and ChibiStudio. Just modify the TRGT line in the makefile in order to use
|
||||||
different GCC toolchains.
|
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
|
|
||||||
|
|
|
@ -38,10 +38,10 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(TRIBUF_USE_WAIT) || defined(__DOXYGEN__)
|
|
||||||
/**
|
/**
|
||||||
* @brief Triple buffers use blocking functions.
|
* @brief Triple buffers use blocking functions.
|
||||||
*/
|
*/
|
||||||
|
#if !defined(TRIBUF_USE_WAIT) || defined(__DOXYGEN__)
|
||||||
#define TRIBUF_USE_WAIT TRUE
|
#define TRIBUF_USE_WAIT TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue