text: #include "profile.h"
  #include "ingsoc.h"
  #include "platform_api.h"
  #include <stdio.h>
  
  #define PRINT_PORT    APB_UART0
  
  uint32_t cb_putc(char *c, void *dummy)
  {
      while (apUART_Check_TXFIFO_FULL(PRINT_PORT) == 1);
      UART_SendData(PRINT_PORT, (uint8_t)*c);
      return 0;
  }
  
  int __putchar(int ch, struct __printf_tag * ptr)
  {
      cb_putc((char *)&ch, NULL);
      return ch;
  }
  
  void config_uart(uint32_t freq, uint32_t baud)
  {
      UART_sStateStruct config;
  
      config.word_length       = UART_WLEN_8_BITS;
      config.parity            = UART_PARITY_NOT_CHECK;
      config.fifo_enable       = 1;
      config.two_stop_bits     = 0;
      config.receive_en        = 1;
      config.transmit_en       = 1;
      config.UART_en           = 1;
      config.cts_en            = 0;
      config.rts_en            = 0;
      config.rxfifo_waterlevel = 1;
      config.txfifo_waterlevel = 1;
      config.ClockFrequency    = freq;
      config.BaudRate          = baud;
  
      apUART_Initialize(PRINT_PORT, &config, 0);
  }
  
  void setup_peripherals(void)
  {
      config_uart(OSC_CLK_FREQ, 115200);
  }
  
  int app_main()
  {
      // If there are *three* crystals on board, *uncomment* below line.
      // Otherwise, below line should be kept commented out.
      // platform_set_rf_clk_source(0);
  
      setup_peripherals();
  
      // setup putc handle
      platform_set_evt_callback(PLATFORM_CB_EVT_PUTC, (f_platform_evt_cb)cb_putc, NULL);
  
      platform_set_evt_callback(PLATFORM_CB_EVT_PROFILE_INIT, setup_profile, NULL);
      return 0;
  }
  
  
  
  