You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.6 KiB

2 years ago
  1. #include "zport.h"
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include "zboard.h"
  5. uint32_t sys_haspassedms(uint32_t ticket)
  6. {
  7. uint32_t nowticket = HAL_GetTick();
  8. if (nowticket >= ticket)
  9. {
  10. return nowticket - ticket;
  11. }
  12. return UINT32_MAX - ticket + nowticket;
  13. }
  14. ///**********************************************************************************************************************
  15. // * ===================================================printf重定向=================================================== *
  16. // **********************************************************************************************************************/
  17. int fputc(int ch, FILE *stream)
  18. {
  19. uint8_t c = ch;
  20. HAL_UART_Transmit(&DEBUG_UART, &c, 1, 100);
  21. return ch;
  22. }
  23. ///***********************************************************************************************************************
  24. // * ====================================================调试指示灯===================================================== *
  25. // ***********************************************************************************************************************/
  26. void port_do_debug_light_state(void)
  27. {
  28. static uint32_t lastprocess = 0;
  29. if (sys_haspassedms(lastprocess) > 300)
  30. {
  31. lastprocess = HAL_GetTick();
  32. HAL_GPIO_TogglePin(DEBUG_LIGHT_PORT, DEBUG_LIGHT_PIN);
  33. }
  34. }
  35. /***********************************************************************************************************************
  36. * *************************************************************************************************************** *
  37. ***********************************************************************************************************************/
  38. static uart_t m_uarts[] = {
  39. {&DEBUG_UART, 0}
  40. // {&ENV_SENSOR_UART485, 0},
  41. };
  42. __weak void port_mock_on_uart_rx(uart_t *uart) {}
  43. static void uarts_start_receive(uart_t *uart) { HAL_UART_Receive_IT(uart->uarthandler, &uart->rxbuf, 1); }
  44. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
  45. {
  46. for (size_t i = 0; i < (sizeof(m_uarts) / sizeof(uart_t)); i++)
  47. {
  48. if (m_uarts[i].uarthandler == huart)
  49. {
  50. port_mock_on_uart_rx(&m_uarts[i]);
  51. uarts_start_receive(&m_uarts[i]);
  52. return;
  53. }
  54. }
  55. }
  56. void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
  57. {
  58. for (size_t i = 0; i < (sizeof(m_uarts) / sizeof(uart_t)); i++)
  59. {
  60. if (m_uarts[i].uarthandler == huart)
  61. {
  62. uarts_start_receive(&m_uarts[i]);
  63. return;
  64. }
  65. }
  66. }
  67. // export
  68. void port_uart_start_all_uart_receive(void)
  69. {
  70. for (size_t i = 0; i < (sizeof(m_uarts) / sizeof(uart_t)); i++)
  71. {
  72. uarts_start_receive(&m_uarts[i]);
  73. }
  74. }