config.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "config.h"
  2. mss_uart_instance_t * const gp_my_uart0 = &g_mss_uart0;
  3. /* gpio and uart0 initialization */
  4. void boardInit(void)
  5. {
  6. /* mss gpio init */
  7. MSS_GPIO_init();
  8. MSS_GPIO_config(MSS_GPIO_0, MSS_GPIO_OUTPUT_MODE);
  9. MSS_GPIO_config(MSS_GPIO_1, MSS_GPIO_OUTPUT_MODE);
  10. /* mss uart0 init: 115200, 8, no, 1 */
  11. MSS_UART_init(gp_my_uart0, MSS_UART_115200_BAUD,
  12. MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT);
  13. }
  14. INIT_BOARD_EXPORT(boardInit);
  15. /* mss uart0 transmit one byte data */
  16. void MSS_UART_polled_tx_byte(mss_uart_instance_t *this_uart, const uint8_t byte)
  17. {
  18. uint32_t tx_ready;
  19. do {
  20. tx_ready = gp_my_uart0->hw_reg->LSR & 0x20u;
  21. } while(!tx_ready);
  22. gp_my_uart0->hw_reg->THR = byte;
  23. }
  24. /* docking finish component */
  25. void rt_hw_console_output(const char *str)
  26. {
  27. while(*str != '\0')
  28. {
  29. if(*str == '\n')
  30. MSS_UART_polled_tx_byte(gp_my_uart0, '\r');
  31. MSS_UART_polled_tx_byte(gp_my_uart0, *str++);
  32. while(!MSS_UART_tx_complete(&g_mss_uart0));
  33. }
  34. }
  35. /* docking finish component */
  36. char rt_hw_console_getchar(void)
  37. {
  38. char dat;
  39. uint8_t rx_size;
  40. do {
  41. rx_size = MSS_UART_get_rx(gp_my_uart0, (uint8_t *)&dat, 1);
  42. } while(0u == rx_size);
  43. return dat;
  44. }
  45. /* custom finish command */
  46. extern uint32_t SystemCoreClock;
  47. void sayHello(void)
  48. {
  49. rt_kprintf("Hello RT-Thread! By SmartFusion2 M2S010\r\n");
  50. rt_kprintf("MSS System Core Clock: %d\r\n", SystemCoreClock);
  51. }
  52. MSH_CMD_EXPORT(sayHello, "say hello to console");