u_global.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include "u_global.h"
  2. //#include "hw_lc_impl.h"
  3. #include "user_driver.h"
  4. Sys_t g_sys;
  5. static AnalogTimer_t m_ag_timer_list[AG_TIMER_ID_MAX] = {0x00};
  6. void clr_format_transition(uint8_t ts_type, uint8_t ts_num, uint8_t *clr_8, uint32_t *clr_32)
  7. {
  8. int i = 0;
  9. if (ts_type == CLR_TS_TYPE_8_32)
  10. {
  11. for (i = 0; i < ts_num; i++)
  12. {
  13. clr_32[i] = clr_8[i * 3 + 2] << 16 | clr_8[i * 3] << 8 | clr_8[i * 3 + 1];
  14. //U_UART_PRINTF("rgb = %02X, %02X, %02X, clr_32 = %06X\n", clr_8[i * 3], clr_8[i * 3 + 1], clr_8[i * 3 + 2], clr_32[i]);
  15. }
  16. }
  17. else
  18. {
  19. for (i = 0; i < ts_num; i++)
  20. {
  21. clr_8[i * 3] = clr_32[i] >> 8 & 0xFF;
  22. clr_8[i * 3 + 1] = clr_32[i] & 0xFF;
  23. clr_8[i * 3 + 2] = clr_32[i] >> 16 & 0xFF;
  24. }
  25. }
  26. }
  27. //uint32_t u_get_sys_time(void)
  28. //{
  29. // return (HW_Get_Native_Clk_Avoid_Race() / 32);
  30. //}
  31. uint32_t u_get_sys_time(void)
  32. {
  33. return (HW_Get_Native_Clk_Avoid_Race());//»ñÈ¡ÔËÐÐmsÊý
  34. }
  35. uint8_t u_ag_timer_start(AgTimerId timer_id, uint16_t timing, void (*callback)(void))
  36. {
  37. if (timer_id >= AG_TIMER_ID_MAX || callback == NULL)
  38. {
  39. return GLO_ERR;
  40. }
  41. //
  42. // p_timer->en = GLO_EN;
  43. if (timing)
  44. {
  45. m_ag_timer_list[timer_id].timing = timing ;
  46. }
  47. m_ag_timer_list[timer_id].timer_id = timer_id;
  48. m_ag_timer_list[timer_id].cb = callback;
  49. m_ag_timer_list[timer_id].record_time = u_get_sys_time() + m_ag_timer_list[timer_id].timing;
  50. return GLO_NO_ERR;
  51. }
  52. uint8_t u_ag_timer_stop(AgTimerId timer_id)
  53. {
  54. if (timer_id >= AG_TIMER_ID_MAX)
  55. {
  56. return GLO_ERR;
  57. }
  58. m_ag_timer_list[timer_id].cb = NULL;
  59. return GLO_NO_ERR;
  60. }
  61. void ag_timer_sched(void)
  62. {
  63. int i = 0;
  64. volatile uint32_t curr_sys_time = u_get_sys_time();
  65. for (i = 0; i < AG_TIMER_ID_MAX; i++)
  66. {
  67. if (m_ag_timer_list[i].cb && curr_sys_time >= m_ag_timer_list[i].record_time)
  68. {
  69. m_ag_timer_list[i].record_time = u_get_sys_time() + m_ag_timer_list[i].timing;
  70. m_ag_timer_list[i].cb();
  71. // U_UART_PRINTF("sys_time = %d\r\n TaskID:%d", u_get_sys_time(),m_ag_timer_list[i]);
  72. }
  73. }
  74. }
  75. static SysEvent m_sys_event = {0x00};
  76. static SysEvenInfo m_sys_event_info[SYS_EVENT_MAX_NUM] = {0x00};
  77. void sys_event_init(void)
  78. {
  79. memset(&m_sys_event, 0, sizeof(SysEvent));
  80. memset(&m_sys_event_info, 0, sizeof(m_sys_event_info));
  81. }
  82. uint8_t sys_event_new(uint16_t dely_time, void (*execute_cb)(void))
  83. {
  84. uint8_t info_save_ind = 0x00, i = 0;
  85. for (i = 0; i < SYS_EVENT_MAX_NUM; i++)
  86. {
  87. if (((m_sys_event.enent_flag >> i) & 0x01) == 0)
  88. {
  89. info_save_ind = i;
  90. m_sys_event.enent_flag |= (0x01 << i);
  91. m_sys_event_info[info_save_ind].enent_flag_bit = (0x01 << i);
  92. m_sys_event_info[info_save_ind].execute_time = u_get_sys_time() + dely_time / SYS_TICK;
  93. m_sys_event_info[info_save_ind].execute_cb = execute_cb;
  94. //U_UART_PRINTF("even_flag = %X\n", m_sys_event.enent_flag);
  95. return 1;
  96. }
  97. }
  98. return 0;
  99. }
  100. //void sys_event_free(uint16_t dely_time, void (*execute_cb)(void))
  101. //{
  102. //}
  103. void sys_event_sched(void)
  104. {
  105. int i = 0;
  106. volatile uint32_t curr_sys_time = 0x00;
  107. if (m_sys_event.enent_flag == 0x00)
  108. {
  109. return;
  110. }
  111. curr_sys_time = u_get_sys_time();
  112. for (i = 0; i < SYS_EVENT_MAX_NUM; i++)
  113. {
  114. if ((m_sys_event.enent_flag >> i) & 0x01)
  115. {
  116. if (curr_sys_time >= m_sys_event_info[i].execute_time)
  117. {
  118. m_sys_event.enent_flag &= ~(0x01 << i);
  119. m_sys_event_info[i].execute_cb();
  120. // U_UART_PRINTF("even_flag = %X\n", m_sys_event.enent_flag);
  121. }
  122. }
  123. }
  124. }
  125. void sys_param_init(void)
  126. {
  127. memset(&g_sys, 0, sizeof(Sys_t));
  128. memset(m_ag_timer_list, 0, sizeof(m_ag_timer_list));
  129. //sys_event_init();
  130. }
  131. signed int u_bprintf_null(const char *fmt, ...)
  132. {
  133. return 1;
  134. }