2016-09-16 10:10:18 +02:00
|
|
|
#include "platform.h"
|
2016-09-20 05:35:56 +02:00
|
|
|
#include "driver/console.h"
|
|
|
|
#include <stdio.h>
|
2016-09-16 10:10:18 +02:00
|
|
|
|
|
|
|
int platform_init (void)
|
|
|
|
{
|
|
|
|
return PLATFORM_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ****************************************************************************
|
|
|
|
// UART
|
|
|
|
|
|
|
|
uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int parity, int stopbits )
|
|
|
|
{
|
2016-09-20 05:35:56 +02:00
|
|
|
if (id == CONSOLE_UART)
|
2016-09-16 10:10:18 +02:00
|
|
|
{
|
2016-09-20 05:35:56 +02:00
|
|
|
ConsoleSetup_t cfg;
|
|
|
|
cfg.bit_rate = baud;
|
|
|
|
switch (databits)
|
|
|
|
{
|
|
|
|
case 5: cfg.data_bits = CONSOLE_NUM_BITS_5; break;
|
|
|
|
case 6: cfg.data_bits = CONSOLE_NUM_BITS_6; break;
|
|
|
|
case 7: cfg.data_bits = CONSOLE_NUM_BITS_7; break;
|
|
|
|
case 8: // fall-through
|
|
|
|
default: cfg.data_bits = CONSOLE_NUM_BITS_8; break;
|
|
|
|
}
|
|
|
|
switch (parity)
|
|
|
|
{
|
|
|
|
case PLATFORM_UART_PARITY_EVEN: cfg.parity = CONSOLE_PARITY_EVEN; break;
|
|
|
|
case PLATFORM_UART_PARITY_ODD: cfg.parity = CONSOLE_PARITY_ODD; break;
|
|
|
|
default: // fall-through
|
|
|
|
case PLATFORM_UART_PARITY_NONE: cfg.parity = CONSOLE_PARITY_NONE; break;
|
|
|
|
}
|
|
|
|
switch (stopbits)
|
|
|
|
{
|
|
|
|
default: // fall-through
|
|
|
|
case PLATFORM_UART_STOPBITS_1:
|
|
|
|
cfg.stop_bits = CONSOLE_STOP_BITS_1; break;
|
|
|
|
case PLATFORM_UART_STOPBITS_1_5:
|
|
|
|
cfg.stop_bits = CONSOLE_STOP_BITS_1_5; break;
|
|
|
|
case PLATFORM_UART_STOPBITS_2:
|
|
|
|
cfg.stop_bits = CONSOLE_STOP_BITS_2; break;
|
|
|
|
}
|
|
|
|
cfg.auto_baud = false;
|
|
|
|
console_setup (&cfg);
|
|
|
|
return baud;
|
2016-09-16 10:10:18 +02:00
|
|
|
}
|
2016-09-20 05:35:56 +02:00
|
|
|
else
|
2016-09-16 10:10:18 +02:00
|
|
|
{
|
2016-09-20 05:35:56 +02:00
|
|
|
printf("UART1/UART2 not yet supported\n");
|
|
|
|
return 0;
|
2016-09-16 10:10:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void platform_uart_send( unsigned id, uint8_t data )
|
|
|
|
{
|
2016-09-20 05:35:56 +02:00
|
|
|
if (id == CONSOLE_UART)
|
|
|
|
putchar (data);
|
2016-09-16 10:10:18 +02:00
|
|
|
}
|