8 #include PLATFORM_HEADER
15 #define _LLIO_STDIN ((int) stdin)
16 #define _LLIO_STDOUT ((int) stdout)
17 #define _LLIO_STDERR ((int) stderr)
18 #define _LLIO_ERROR (-1)
19 #define __write _write
22 void __io_putchar(
char c );
25 __io_putchar((
char) c);
29 #define RECEIVE_QUEUE_SIZE (128)
31 uint8_t rxQ[RECEIVE_QUEUE_SIZE];
44 assert( (baudrate >= 300) && (baudrate <=921600) );
46 tmp = (2*12000000L + baudrate/2) / baudrate;
47 SC1_UARTFRAC = tmp & 1;
48 SC1_UARTPER = tmp / 2;
53 tempcfg = SC_UART8BIT;
56 if (parity == PARITY_ODD) {
57 tempcfg |= SC_UARTPAR | SC_UARTODD;
58 }
else if( parity == PARITY_EVEN ) {
59 tempcfg |= SC_UARTPAR;
62 if ((stopbits & 0x0F) >= 2) {
63 tempcfg |= SC_UART2STP;
65 SC1_UARTCFG = tempcfg;
67 SC1_MODE = SC1_MODE_UART;
77 SC1_INTMODE = SC_RXVALLEVEL;
79 INT_SC1CFG |= (INT_SCRXVAL |
91 size_t __write(
int handle,
const unsigned char * buffer,
size_t size)
97 if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR) {
104 while ((SC1_UARTSTAT&SC_UARTTXIDLE)!=SC_UARTTXIDLE) {}
109 if(SC1_MODE != SC1_MODE_UART) {
115 while ((SC1_UARTSTAT&SC_UARTTXFREE)!=SC_UARTTXFREE) {}
128 size_t fflush(
int handle)
131 return __write(_LLIO_STDOUT,
NULL, 0);
134 static void halInternalUart1TxIsr(
void)
144 size_t __read(
int handle,
unsigned char * buffer,
size_t size)
150 if (handle != _LLIO_STDIN)
155 for(nChars = 0; (rxUsed>0) && (nChars < size); nChars++) {
157 *buffer++ = rxQ[rxTail];
158 rxTail = (rxTail+1) % RECEIVE_QUEUE_SIZE;
166 static void halInternalUart1RxIsr(
void)
173 while ( SC1_UARTSTAT & SC_UARTRXVAL ) {
174 uint8_t errors = SC1_UARTSTAT & (SC_UARTFRMERR |
177 uint8_t incoming = (uint8_t) SC1_DATA;
179 if ( (errors == 0) && (rxUsed < (RECEIVE_QUEUE_SIZE-1)) ) {
180 rxQ[rxHead] = incoming;
181 rxHead = (rxHead+1) % RECEIVE_QUEUE_SIZE;
201 interrupt = INT_SC1FLAG;
202 interrupt &= INT_SC1CFG;
204 while (interrupt != 0) {
206 INT_SC1FLAG = interrupt;
209 if ( interrupt & (INT_SCRXVAL |
214 halInternalUart1RxIsr();
218 if ( interrupt & (INT_SCTXFREE |
221 halInternalUart1TxIsr();
224 interrupt = INT_SC1FLAG;
225 interrupt &= INT_SC1CFG;
238 if (__read(_LLIO_STDIN,data,1))
244 void __io_putchar(
char c )
246 __write(_LLIO_STDOUT, (
unsigned char *)&c, 1);
252 __read(_LLIO_STDIN, &c, 1);
256 void __io_flush(
void )
258 __write(_LLIO_STDOUT,
NULL, 0);
void uartInit(uint32_t baudrate, uint8_t databits, SerialParity parity, uint8_t stopbits)
Initialize the UART.
Utility and convenience functions for STM32W108 microcontroller, common to both the full and minimal ...
#define NULL
The null pointer.
#define TRUE
An alias for one, used for clarity.
SerialParity
A list of the possible values for the parity parameter to uartInit()
Minimal Hal functions common across all microcontroller-specific files.
boolean __io_getcharNonBlocking(uint8_t *data)
Read the input byte if any.
Header for STM32W uart drivers, supporting IAR's standard library IO routines.
#define FALSE
An alias for zero, used for clarity.
#define ATOMIC(blah)
A block of code may be made atomic by wrapping it with this macro.
#define PORTB_PIN(y)
Some registers and variables require indentifying GPIO by a single number instead of the port and pin...
void halGpioConfig(uint32_t io, uint32_t config)
Configure an IO pin's operating mode.