IRQ driven RX on UART0
See examples/terminal/ for usage
This commit is contained in:
parent
64a1e5598b
commit
9d80dc441f
7 changed files with 217 additions and 1 deletions
12
examples/terminal/FreeRTOSConfig.h
Normal file
12
examples/terminal/FreeRTOSConfig.h
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/* Terminal FreeRTOSConfig overrides.
|
||||
|
||||
This is intended as an example of overriding some of the default FreeRTOSConfig settings,
|
||||
which are otherwise found in FreeRTOS/Source/include/FreeRTOSConfig.h
|
||||
*/
|
||||
|
||||
/* The serial driver depends on counting semaphores */
|
||||
#define configUSE_COUNTING_SEMAPHORES 1
|
||||
|
||||
/* Use the defaults for everything else */
|
||||
#include_next<FreeRTOSConfig.h>
|
||||
|
||||
3
examples/terminal/Makefile
Normal file
3
examples/terminal/Makefile
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
PROGRAM=terminal
|
||||
EXTRA_COMPONENTS=extras/serial-driver
|
||||
include ../../common.mk
|
||||
37
examples/terminal/terminal.c
Normal file
37
examples/terminal/terminal.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* Serial terminal example
|
||||
* UART RX is interrupt driven
|
||||
* Read characters until \n and echo back
|
||||
*
|
||||
* This sample code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <espressif/esp_common.h>
|
||||
#include <serial_driver.h>
|
||||
|
||||
#define BUFFER_SIZE (81)
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
char buffer[BUFFER_SIZE];
|
||||
uint32_t i = 0;
|
||||
sdk_uart_div_modify(0, UART_CLK_FREQ / 115200);
|
||||
while(1) {
|
||||
char ch;
|
||||
// The thread will block here until there is data available
|
||||
// NB. read(...) may be called from user_init or from a thread
|
||||
// We can check how many characters are available in the RX buffer
|
||||
// with uint32_t uart0_num_char(void);
|
||||
if (read(0, (void*)&ch, 1)) { // 0 is stdin
|
||||
if (i == BUFFER_SIZE-2 || ch == '\n') {
|
||||
buffer[i] = 0;
|
||||
printf("Unknown command: %s\n", (char*) buffer);
|
||||
i = 0;
|
||||
} else {
|
||||
buffer[i++] = ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue