From a10ed370febb7168246acebc6cc8492a173170ce Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 1 Nov 2020 16:10:30 +0100 Subject: Complete Write Functions in USART Lib --- usart_irq/main.c | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) (limited to 'usart_irq/main.c') diff --git a/usart_irq/main.c b/usart_irq/main.c index 8c79471..48ce18b 100644 --- a/usart_irq/main.c +++ b/usart_irq/main.c @@ -11,14 +11,13 @@ #define DELAY 1000000 -#define RX_BUFFER_SIZE 50 -#define TX_BUFFER_SIZE 50 +#define RX_BUFFER_SIZE 1000 +#define TX_BUFFER_SIZE 1000 void clock_init(void); void gpio_init(void); void delay(void); -int _write(int file, char *ptr, int len); USART usart3; @@ -26,20 +25,18 @@ USART usart3; int main(void) { - uint8_t rx_buffer[RX_BUFFER_SIZE]; - uint8_t tx_buffer[TX_BUFFER_SIZE]; - + // setup clock_init(); gpio_init(); + uint8_t rx_buffer[RX_BUFFER_SIZE]; + uint8_t tx_buffer[TX_BUFFER_SIZE]; usart_init(&usart3, rx_buffer, RX_BUFFER_SIZE, tx_buffer, TX_BUFFER_SIZE); - gpio_set(GPIOC, GPIO13); - - char welcome[] = "Hello world!\r"; - usart_write(&usart3, welcome); + // welcome message + usart_writeln(&usart3, "This is a demo of USART via IRQ. Just type something!"); + // return any input uint8_t buff; - while(1){ if (usart_read_bytes(&usart3, &buff, 1)){ usart_write_bytes(&usart3, &buff, 1); @@ -60,6 +57,7 @@ void gpio_init(void) { gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13); gpio_clear(GPIOC, GPIO13); + gpio_set(GPIOC, GPIO13); } @@ -69,22 +67,3 @@ void delay(void) __asm__("nop"); } } - - -int _write(int file, char *ptr, int len) -{ - int i; - - if (file == STDOUT_FILENO || file == STDERR_FILENO) { - for (i = 0; i < len; i++) { - if (ptr[i] == '\n') { - uint8_t cr = (uint8_t)'\r'; - usart_write_bytes(&usart3, &cr, 1); - } - usart_write_bytes(&usart3, (uint8_t *)&ptr[i], 1); - } - return i; - } - errno = EIO; - return -1; -} -- cgit v1.2.3-70-g09d2