aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/libboard
diff options
context:
space:
mode:
authorKévin Redon <kredon@sysmocom.de>2018-08-02 15:02:05 +0200
committerKévin Redon <kredon@sysmocom.de>2018-08-04 11:16:13 +0200
commit1836ac076167f6975b5e46a48de9d00e929e4fef (patch)
treeffc5becf8828bd6173c2ce141eceff0a0ce08f98 /firmware/libboard
parentdd36d9b0100053c7d42fe950d5033ad01ba8d196 (diff)
add synchronous UART transmission and use it in exceptions
The default ISR (particularly the HardFault handler) print information, but this information was not displayed on the console because the UART IRQ is lower than some default blocking IRQ. Allowing to set synchronous transfer corrects this. The underlying Atmel exception library had to be modified to use the synchronous output. Making UART_PutChar always synchronous when called from an ISR is not desired because we use TRACE_ macros is some ISR. The synchronous output must be set explicitly. Change-Id: I1b4ace5185cf2dc32684934ed12bf6a8682e9bad
Diffstat (limited to 'firmware/libboard')
-rw-r--r--firmware/libboard/common/include/uart_console.h5
-rw-r--r--firmware/libboard/common/source/uart_console.c30
2 files changed, 28 insertions, 7 deletions
diff --git a/firmware/libboard/common/include/uart_console.h b/firmware/libboard/common/include/uart_console.h
index c0ee3a7..70425bc 100644
--- a/firmware/libboard/common/include/uart_console.h
+++ b/firmware/libboard/common/include/uart_console.h
@@ -29,16 +29,15 @@
*/
#ifndef _UART_CONSOLE_
#define _UART_CONSOLE_
-
#include <stdint.h>
extern void UART_Configure( uint32_t dwBaudrate, uint32_t dwMasterClock ) ;
-extern void UART_Exit(void) ;
+extern void UART_Exit( void ) ;
extern void UART_PutChar( uint8_t uc ) ;
+extern void UART_PutChar_Sync( uint8_t uc ) ;
extern uint32_t UART_GetChar( void ) ;
extern uint32_t UART_IsRxReady( void ) ;
-
extern void UART_DumpFrame( uint8_t* pucFrame, uint32_t dwSize ) ;
extern void UART_DumpMemory( uint8_t* pucBuffer, uint32_t dwSize, uint32_t dwAddress ) ;
extern uint32_t UART_GetInteger( uint32_t* pdwValue ) ;
diff --git a/firmware/libboard/common/source/uart_console.c b/firmware/libboard/common/source/uart_console.c
index 3ce7331..3a00e49 100644
--- a/firmware/libboard/common/source/uart_console.c
+++ b/firmware/libboard/common/source/uart_console.c
@@ -2,6 +2,7 @@
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2009, Atmel Corporation
+ * Copyright (c) 2018, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
*
* All rights reserved.
*
@@ -135,10 +136,10 @@ void CONSOLE_ISR(void)
/**
* \brief Outputs a character on the UART line.
*
- * \note This function is synchronous (i.e. uses polling).
+ * \note This function is asynchronous (i.e. uses a buffer and interrupt to complete the transfer).
* \param c Character to send.
*/
-extern void UART_PutChar( uint8_t c )
+void UART_PutChar( uint8_t uc )
{
Uart *pUart = CONSOLE_UART ;
@@ -148,9 +149,8 @@ extern void UART_PutChar( uint8_t c )
UART_Configure(CONSOLE_BAUDRATE, BOARD_MCK);
}
- /* Only store input if buffer is not full, else drop it */
if (!rbuf_is_full(&uart_tx_buffer)) {
- rbuf_write(&uart_tx_buffer, c);
+ rbuf_write(&uart_tx_buffer, uc);
if (!(pUart->UART_IMR & UART_IMR_TXRDY)) {
pUart->UART_IER = UART_IER_TXRDY;
CONSOLE_ISR();
@@ -159,6 +159,28 @@ extern void UART_PutChar( uint8_t c )
}
/**
+ * \brief Outputs a character on the UART line.
+ *
+ * \note This function is synchronous (i.e. uses polling and blocks until the transfer is complete).
+ * \param c Character to send.
+ */
+void UART_PutChar_Sync( uint8_t uc )
+{
+ Uart *pUart = CONSOLE_UART ;
+
+ /* Initialize console is not already done */
+ if ( !_ucIsConsoleInitialized )
+ {
+ UART_Configure(CONSOLE_BAUDRATE, BOARD_MCK);
+ }
+
+ while (!(pUart->UART_SR & UART_SR_TXRDY)); /* Wait for transfer buffer to be empty */
+ pUart->UART_THR = uc; /* Send data to UART peripheral */
+ while (!(pUart->UART_SR & UART_SR_TXRDY)); /* Wait for transfer buffer to transferred to shift register */
+ while (!(pUart->UART_SR & UART_SR_TXEMPTY)); /* Wait for transfer shift register to be empty (i.e. transfer is complete) */
+}
+
+/**
* \brief Input a character from the UART line.
*
* \note This function is synchronous