aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--firmware/atmel_softpack_libraries/libchip_sam3s/source/exceptions.c2
-rw-r--r--firmware/libboard/common/include/uart_console.h5
-rw-r--r--firmware/libboard/common/source/uart_console.c30
-rw-r--r--firmware/libcommon/include/stdio.h7
-rw-r--r--firmware/libcommon/source/fputs.c15
-rw-r--r--firmware/libcommon/source/stdio.c58
6 files changed, 108 insertions, 9 deletions
diff --git a/firmware/atmel_softpack_libraries/libchip_sam3s/source/exceptions.c b/firmware/atmel_softpack_libraries/libchip_sam3s/source/exceptions.c
index 74e0fbd..6d2a135 100644
--- a/firmware/atmel_softpack_libraries/libchip_sam3s/source/exceptions.c
+++ b/firmware/atmel_softpack_libraries/libchip_sam3s/source/exceptions.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.
*
@@ -41,6 +42,7 @@
* Headers
*----------------------------------------------------------------------------*/
+#define printf printf_sync
#include "chip.h"
/*----------------------------------------------------------------------------
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
diff --git a/firmware/libcommon/include/stdio.h b/firmware/libcommon/include/stdio.h
index 7695d20..258c7ab 100644
--- a/firmware/libcommon/include/stdio.h
+++ b/firmware/libcommon/include/stdio.h
@@ -52,9 +52,14 @@ signed int printf(const char *pFormat, ...);
signed int sprintf(char *pStr, const char *pFormat, ...);
signed int puts(const char *pStr);
-
int fputc(int c, FILE *stream);
int fputs(const char *s, FILE *stream);
#define putc(c, stream) fputc(c, stream)
#define putchar(c) fputc(c, stdout)
+
+signed int vfprintf_sync(FILE *pStream, const char *pFormat, va_list ap);
+signed int vprintf_sync(const char *pFormat, va_list ap);
+signed int printf_sync(const char *pFormat, ...);
+int fputc_sync(int c, FILE *stream);
+int fputs_sync(const char *s, FILE *stream);
diff --git a/firmware/libcommon/source/fputs.c b/firmware/libcommon/source/fputs.c
index ca6f851..110f68e 100644
--- a/firmware/libcommon/source/fputs.c
+++ b/firmware/libcommon/source/fputs.c
@@ -26,6 +26,19 @@ int fputc(int c, FILE *stream)
int fputs(const char *s, FILE *stream)
{
while (*s != '\0')
- UART_PutChar(*s++);
+ fputc(*s++, stream);
+ return 0;
+}
+
+int fputc_sync(int c, FILE *stream)
+{
+ UART_PutChar_Sync(c);
+ return c;
+}
+
+int fputs_sync(const char *s, FILE *stream)
+{
+ while (*s != '\0')
+ fputc_sync(*s++, stream);
return 0;
}
diff --git a/firmware/libcommon/source/stdio.c b/firmware/libcommon/source/stdio.c
index 505c895..06ad611 100644
--- a/firmware/libcommon/source/stdio.c
+++ b/firmware/libcommon/source/stdio.c
@@ -2,6 +2,7 @@
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
+ * Copyright (c) 2018, sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de>
*
* All rights reserved.
*
@@ -436,6 +437,32 @@ signed int vfprintf(FILE *pStream, const char *pFormat, va_list ap)
}
//------------------------------------------------------------------------------
+/// Outputs a formatted string on the given stream. Format arguments are given
+/// in a va_list instance.
+/// \note This function is synchronous (i.e. blocks until the print completes)
+/// \param pStream Output stream.
+/// \param pFormat Format string
+/// \param ap Argument list.
+//------------------------------------------------------------------------------
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
+signed int vfprintf_sync(FILE *pStream, const char *pFormat, va_list ap)
+{
+ char pStr[MAX_STRING_SIZE];
+ char pError[] = "stdio.c: increase MAX_STRING_SIZE\n\r";
+
+ // Write formatted string in buffer
+ if (vsprintf(pStr, pFormat, ap) >= MAX_STRING_SIZE) {
+
+ fputs_sync(pError, stderr);
+ }
+
+ // Display string
+ return fputs_sync(pStr, pStream);
+}
+#pragma GCC diagnostic pop
+
+//------------------------------------------------------------------------------
/// Outputs a formatted string on the DBGU stream. Format arguments are given
/// in a va_list instance.
/// \param pFormat Format string
@@ -447,6 +474,18 @@ signed int vprintf(const char *pFormat, va_list ap)
}
//------------------------------------------------------------------------------
+/// Outputs a formatted string on the DBGU stream. Format arguments are given
+/// in a va_list instance.
+/// \note This function is synchronous (i.e. blocks until the print completes)
+/// \param pFormat Format string
+/// \param ap Argument list.
+//------------------------------------------------------------------------------
+signed int vprintf_sync(const char *pFormat, va_list ap)
+{
+ return vfprintf_sync(stdout, pFormat, ap);
+}
+
+//------------------------------------------------------------------------------
/// Outputs a formatted string on the given stream, using a variable number of
/// arguments.
/// \param pStream Output stream.
@@ -484,6 +523,25 @@ signed int printf(const char *pFormat, ...)
}
//------------------------------------------------------------------------------
+/// Outputs a formatted string on the DBGU stream, using a variable number of
+/// arguments.
+/// \note This function is synchronous (i.e. blocks until the print completes)
+/// \param pFormat Format string.
+//------------------------------------------------------------------------------
+signed int printf_sync(const char *pFormat, ...)
+{
+ va_list ap;
+ signed int result;
+
+ // Forward call to vprintf
+ va_start(ap, pFormat);
+ result = vprintf_sync(pFormat, ap);
+ va_end(ap);
+
+ return result;
+}
+
+//------------------------------------------------------------------------------
/// Writes a formatted string inside another string.
/// \param pStr Storage string.
/// \param pFormat Format string.