diff --git a/lib/bsp/entry_user.c b/lib/bsp/entry_user.c index 4902fb3..3fefb2f 100644 --- a/lib/bsp/entry_user.c +++ b/lib/bsp/entry_user.c @@ -73,13 +73,9 @@ void _init_bsp(int core_id, int number_of_cores) /* Initialize bss data to 0 */ init_bss(); /* Init UART */ - uart_init(UART_DEVICE_3); - uart_configure(UART_DEVICE_3, 115200, 8, UART_STOP_1, UART_PARITY_NONE); - uart_set_receive_trigger(UART_DEVICE_3, UART_RECEIVE_FIFO_1); fpioa_set_function(4, FUNC_UART3_RX); fpioa_set_function(5, FUNC_UART3_TX); - sys_register_getchar(uart3_getchar); - sys_register_putchar(uart3_putchar); + uart_debug_init(UART_DEVICE_3); /* Init FPIOA */ fpioa_init(); /* Register finalization function */ diff --git a/lib/bsp/include/bsp.h b/lib/bsp/include/bsp.h index deecc67..2c384eb 100644 --- a/lib/bsp/include/bsp.h +++ b/lib/bsp/include/bsp.h @@ -4,4 +4,6 @@ #include "entry.h" #include "sleep.h" #include "encoding.h" +#include "syscalls.h" +#include "printf.h" #endif \ No newline at end of file diff --git a/lib/bsp/include/syscalls.h b/lib/bsp/include/syscalls.h index 50c4c93..496509e 100644 --- a/lib/bsp/include/syscalls.h +++ b/lib/bsp/include/syscalls.h @@ -76,14 +76,11 @@ void sys_stdin_flush(void); void __attribute__((noreturn)) sys_exit(int code); -void setStats(int enable); - -#undef putchar -int putchar(int ch); -void printstr(const char *s); - -void printhex(uint64_t x); - +/** + * @brief Get free memory + * + * @return The size of free memory + */ size_t get_free_heap_size(void); #ifdef __cplusplus diff --git a/lib/drivers/include/uart.h b/lib/drivers/include/uart.h index 4a13cc0..5c4e21f 100644 --- a/lib/drivers/include/uart.h +++ b/lib/drivers/include/uart.h @@ -470,64 +470,12 @@ void uart_set_tat(uart_device_number_t uart_channel, uart_tat_mode_t tat_mode, s void uart_set_det(uart_device_number_t uart_channel, uart_det_mode_t det_mode, size_t time); /** - * @brief Put a char to UART1 + * @brief Set the default debug serial port * - * @param[in] c The char to put + * @param[in] uart_channel Uart index * - * @return result - * - Byte On success, returns the written character. - * - EOF On failure, returns EOF and sets the error indicator (see ferror()) on stdout. */ -int uart1_putchar(char c); - -/** - * @brief Get a byte from UART1 - * - * @return byte as int type from UART - * - Byte The character read as an unsigned char cast to an int - * - EOF EOF on end of file or error, no enough byte to read - */ -int uart1_getchar(void); - -/** - * @brief Put a char to UART2 - * - * @param[in] c The char to put - * - * @return result - * - Byte On success, returns the written character. - * - EOF On failure, returns EOF and sets the error indicator (see ferror()) on stdout. - */ -int uart2_putchar(char c); - -/** - * @brief Get a byte from UART2 - * - * @return byte as int type from UART - * - Byte The character read as an unsigned char cast to an int - * - EOF EOF on end of file or error, no enough byte to read - */ -int uart2_getchar(void); - -/** - * @brief Put a char to UART3 - * - * @param[in] c The char to put - * - * @return result - * - Byte On success, returns the written character. - * - EOF On failure, returns EOF and sets the error indicator (see ferror()) on stdout. - */ -int uart3_putchar(char c); - -/** - * @brief Get a byte from UART3 - * - * @return byte as int type from UART - * - Byte The character read as an unsigned char cast to an int - * - EOF EOF on end of file or error, no enough byte to read - */ -int uart3_getchar(void); +void uart_debug_init(uart_device_number_t uart_channel); #ifdef __cplusplus } diff --git a/lib/drivers/sysctl.c b/lib/drivers/sysctl.c index 1d719ee..26c5c3b 100644 --- a/lib/drivers/sysctl.c +++ b/lib/drivers/sysctl.c @@ -20,6 +20,7 @@ #include "string.h" #include "encoding.h" #include "bsp.h" +#include "uart.h" #define SYSCTRL_CLOCK_FREQ_IN0 (26000000UL) @@ -1790,8 +1791,10 @@ uint32_t sysctl_pll_set_freq(sysctl_pll_t pll, uint32_t pll_freq) /* 9. Change CPU CLK to PLL */ if(pll == SYSCTL_PLL0) + { sysctl_clock_set_clock_select(SYSCTL_CLOCK_SELECT_ACLK, SYSCTL_SOURCE_PLL0); - + uart_debug_init(-1); + } return result; } diff --git a/lib/drivers/uart.c b/lib/drivers/uart.c index 953b145..ceb21c0 100644 --- a/lib/drivers/uart.c +++ b/lib/drivers/uart.c @@ -19,6 +19,7 @@ #include "uart.h" #include "utils.h" #include "atomic.h" +#include "syscalls.h" #define __UART_BRATE_CONST 16 @@ -95,7 +96,9 @@ static int uart_irq_callback(void *param) return 0; } -int uart_channel_putc(char c, uart_device_number_t channel) +static uart_device_number_t s_uart_debug_channel = UART_DEVICE_3; + +static int uart_channel_putc(char c, uart_device_number_t channel) { while (uart[channel]->LSR & (1u << 5)) continue; @@ -103,7 +106,7 @@ int uart_channel_putc(char c, uart_device_number_t channel) return c & 0xff; } -int uart_channel_getc(uart_device_number_t channel) +static int uart_channel_getc(uart_device_number_t channel) { /* If received empty */ if (!(uart[channel]->LSR & 1)) @@ -112,34 +115,39 @@ int uart_channel_getc(uart_device_number_t channel) return (char)(uart[channel]->RBR & 0xff); } -int uart1_putchar(char c) +static int uart_debug_putchar(char c) { - return uart_channel_putc(c, UART_DEVICE_1); + return uart_channel_putc(c, s_uart_debug_channel); } -int uart1_getchar(void) +static int uart_debug_getchar(void) { - return uart_channel_getc(UART_DEVICE_1); + return uart_channel_getc(s_uart_debug_channel); } -int uart2_putchar(char c) +void uart_debug_init(uart_device_number_t uart_channel) { - return uart_channel_putc(c, UART_DEVICE_2); -} - -int uart2_getchar(void) -{ - return uart_channel_getc(UART_DEVICE_2); -} - -int uart3_putchar(char c) -{ - return uart_channel_putc(c, UART_DEVICE_3); -} - -int uart3_getchar(void) -{ - return uart_channel_getc(UART_DEVICE_3); + volatile bool v_uart_reset_flag = false; + if(uart_channel >= UART_DEVICE_1 && uart_channel <= UART_DEVICE_3) + { + s_uart_debug_channel = uart_channel; + v_uart_reset_flag = true; + } + uart_init(s_uart_debug_channel); + uart_configure(s_uart_debug_channel, 115200, 8, UART_STOP_1, UART_PARITY_NONE); + uart_set_receive_trigger(s_uart_debug_channel, UART_RECEIVE_FIFO_1); + if(v_uart_reset_flag) + { + sys_register_getchar(uart_debug_getchar); + sys_register_putchar(uart_debug_putchar); + } + else + { + if(sys_getchar == NULL) + sys_register_getchar(uart_debug_getchar); + if(sys_putchar == NULL) + sys_register_putchar(uart_debug_putchar); + } } static int uart_dma_callback(void *ctx) diff --git a/src/hello_world/main.c b/src/hello_world/main.c index 8edd386..59655cc 100644 --- a/src/hello_world/main.c +++ b/src/hello_world/main.c @@ -12,9 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include -#include "bsp.h" +#include +#include int core1_function(void *ctx) { @@ -23,9 +22,9 @@ int core1_function(void *ctx) while(1); } - -int main() +int main(void) { + sysctl_pll_set_freq(SYSCTL_PLL0, 800000000); uint64_t core = current_coreid(); int data; printf("Core %ld Hello world\n", core); @@ -35,7 +34,8 @@ int main() sys_stdin_flush(); scanf("%d", &data); - printf("Data is %d\n", data); + printf("\nData is %d\n", data); while(1) continue; + return 0; }