soft_test.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include "at32f403a_407.h"
  2. #include "soft_test.h"
  3. #include "FreeRTOS.h"
  4. #include "task.h"
  5. #include "digital_input.h"
  6. #include "mux.h"
  7. #include <stdio.h>
  8. #include <math.h>
  9. float sin_signal;
  10. int sin_input = 0;
  11. //
  12. void test_tim_init(void)
  13. {
  14. crm_clocks_freq_type crm_clocks_freq_struct = {0};
  15. crm_periph_clock_enable(CRM_TMR3_PERIPH_CLOCK, TRUE);
  16. crm_clocks_freq_get(&crm_clocks_freq_struct);
  17. tmr_base_init(TMR3, 999, (crm_clocks_freq_struct.ahb_freq / 10000) - 1);
  18. tmr_cnt_dir_set(TMR3, TMR_COUNT_UP);
  19. tmr_flag_clear(TMR3, TMR_OVF_FLAG);
  20. nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
  21. nvic_irq_enable(TMR3_GLOBAL_IRQn, 5, 0);
  22. tmr_counter_enable(TMR3, TRUE);
  23. tmr_interrupt_enable(TMR3, TMR_OVF_INT, TRUE);
  24. }
  25. //
  26. void test_sin_input(void)
  27. {
  28. sin_input++;
  29. if (sin_input == 361)
  30. sin_input = 0;
  31. }
  32. void TMR3_GLOBAL_IRQHandler(void)
  33. {
  34. if (tmr_flag_get(TMR3, TMR_OVF_FLAG) != RESET)
  35. {
  36. tmr_flag_clear(TMR3, TMR_OVF_FLAG);
  37. test_sin_input();
  38. sin_signal = 10*(sin(0.0174533*sin_input) + 1);
  39. //printf("%i, %f\r\n", sin_input, sin_signal);
  40. }
  41. }
  42. //
  43. float test_get_signal(void)
  44. {
  45. return sin_signal;
  46. }
  47. // Генерация тестовых сигналов
  48. void test_signal_task(void *argument)
  49. {
  50. for (;;)
  51. {
  52. vTaskDelay(1000);
  53. printf("Test signal task\r\n");
  54. }
  55. }
  56. //
  57. void test_hw_task(void *argument)
  58. {
  59. for (;;)
  60. {
  61. #if 0
  62. vTaskDelay(1000);
  63. printf("\r\n");
  64. for (uint8_t i = 0; i < 8; i++)
  65. {
  66. printf("Channel: %u, state = %u\r\n", i + 1, di_get(i));
  67. }
  68. #endif
  69. #if 1
  70. vTaskDelay(100);
  71. mux_led_blink();
  72. #endif
  73. //adc_test();
  74. }
  75. }
  76. //
  77. void test_gpio(void *params)
  78. {
  79. (void)params;
  80. for (;;)
  81. {
  82. vTaskDelay(100);
  83. //printf("%" PRId64 " \r\n", rtc_get_ms());
  84. //en_crnt_alrm_in(0x02);
  85. //io_test();
  86. //out_test();
  87. //load_test();
  88. //printf("HW rev: %u\r\n", cm_gpio_get_rev());
  89. //printf("Save mode: %u\r\n", save_mode_get());
  90. }
  91. }