porttimer.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "at32f403a_407.h"
  2. #include "FreeRTOS.h"
  3. #include "task.h"
  4. #include "port.h"
  5. #include "mb.h"
  6. #include "mbport.h"
  7. #include <stdbool.h>
  8. static void prvvTIMERExpiredISR( void );
  9. BOOL xMBPortTimersInit( USHORT usTim1Timerout50us )
  10. {
  11. crm_clocks_freq_type crm_clocks_freq_struct = {0};
  12. crm_clocks_freq_get(&crm_clocks_freq_struct);
  13. nvic_irq_disable(TMR7_GLOBAL_IRQn);
  14. crm_periph_clock_enable(CRM_TMR7_PERIPH_CLOCK, TRUE);
  15. tmr_base_init(TMR7, (usTim1Timerout50us * 50) - 1, (crm_clocks_freq_struct.ahb_freq / 1000000) - 1);
  16. tmr_cnt_dir_set(TMR7, TMR_COUNT_UP);
  17. NVIC_ClearPendingIRQ(TMR7_GLOBAL_IRQn);
  18. nvic_irq_enable(TMR7_GLOBAL_IRQn, 5, 0);
  19. return TRUE;
  20. }
  21. /* Create an ISR which is called whenever the timer has expired. This function
  22. * must then call pxMBPortCBTimerExpired( ) to notify the protocol stack that
  23. * the timer has expired.
  24. */
  25. static void prvvTIMERExpiredISR( void )
  26. {
  27. ( void )pxMBPortCBTimerExpired( );
  28. }
  29. //
  30. void TMR7_GLOBAL_IRQHandler(void)
  31. {
  32. if(tmr_flag_get(TMR7, TMR_OVF_FLAG) != RESET)
  33. {
  34. tmr_flag_clear(TMR7, TMR_OVF_FLAG);
  35. vMBPortSetWithinException(TRUE);
  36. prvvTIMERExpiredISR();
  37. vMBPortSetWithinException(FALSE);
  38. }
  39. }
  40. //
  41. void vMBPortTimerClose( void )
  42. {
  43. tmr_interrupt_enable(TMR7, TMR_OVF_INT, FALSE);
  44. tmr_counter_enable(TMR7, FALSE);
  45. }
  46. //
  47. void vMBPortTimersEnable()
  48. {
  49. tmr_flag_clear(TMR7, TMR_OVF_FLAG);
  50. tmr_interrupt_enable(TMR7, TMR_OVF_INT, TRUE);
  51. tmr_counter_value_set(TMR7, 0);
  52. tmr_counter_enable(TMR7, TRUE);
  53. }
  54. //
  55. void vMBPortTimersDisable()
  56. {
  57. tmr_flag_clear(TMR7, TMR_OVF_FLAG);
  58. tmr_interrupt_enable(TMR7, TMR_OVF_INT, FALSE);
  59. tmr_counter_value_set(TMR7, 0);
  60. tmr_counter_enable(TMR7, FALSE);
  61. }
  62. //
  63. void vMBPortTimersDelay( USHORT usTimeOutMS )
  64. {
  65. vTaskDelay( usTimeOutMS / portTICK_RATE_MS );
  66. }