main.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*!
  2. \file main.c
  3. \brief UASRT receiver timeout
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-06-06, V1.0.0, firmware for GD32F3x0
  8. */
  9. #include "gd32f3x0.h"
  10. #include <stdio.h>
  11. #include "gd32f3x0_eval.h"
  12. uint8_t rxbuffer[64];
  13. uint8_t txbuffer[64];
  14. extern __IO uint8_t txcount;
  15. extern __IO uint16_t rxcount;
  16. void nvic_config(void);
  17. /*!
  18. \brief main function
  19. \param[in] none
  20. \param[out] none
  21. \retval none
  22. */
  23. int main(void)
  24. {
  25. uint32_t i=0, j=0;
  26. nvic_config();
  27. gd_eval_com_init(EVAL_COM1);
  28. printf("a usart receive timeout test example!");
  29. while (1){
  30. if(0 == rxcount){
  31. /* enable the USART receive interrupt */
  32. usart_interrupt_enable(EVAL_COM1, USART_INT_RBNE);
  33. }else{
  34. /* enable the USART receive timeout and configure the time of timeout */
  35. usart_receiver_timeout_enable(EVAL_COM1);
  36. usart_receiver_timeout_config(EVAL_COM1, 115200*3);
  37. while(RESET == usart_flag_get(EVAL_COM1, USART_FLAG_RT));
  38. for(i=0; i<rxcount; i++){
  39. txbuffer[i]=rxbuffer[j++];
  40. }
  41. /* disable the USART receive interrupt and enable the USART transmit interrupt */
  42. usart_interrupt_disable(EVAL_COM1, USART_INT_RBNE);
  43. usart_interrupt_enable(EVAL_COM1, USART_INT_TBE);
  44. while(txcount < rxcount);
  45. usart_flag_clear(EVAL_COM1, USART_FLAG_RT);
  46. txcount=0;
  47. rxcount=0;
  48. i=0;
  49. j=0;
  50. }
  51. }
  52. }
  53. /* retarget the C library printf function to the USART */
  54. int fputc(int ch, FILE *f)
  55. {
  56. usart_data_transmit(EVAL_COM1, (uint8_t)ch);
  57. while(RESET == usart_flag_get(EVAL_COM1, USART_FLAG_TBE));
  58. return ch;
  59. }
  60. /*!
  61. \brief configure the nested vectored interrupt controller
  62. \param[in] none
  63. \param[out] none
  64. \retval none
  65. */
  66. void nvic_config(void)
  67. {
  68. nvic_irq_enable(USART0_IRQn, 0, 1);
  69. }