dev_uart_table.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #include "dev_uart_table.h"
  2. #include "dev_can.h"
  3. #include "hal_uart4.h"
  4. #include <stdint.h>
  5. static void read_1000(uint8_t memoft, uint8_t *data, uint8_t *read_bytes)
  6. {
  7. uint8_t size = 0;
  8. switch (memoft)
  9. {
  10. case 0:
  11. data[0] = 0x12;
  12. data[1] = 0x13;
  13. size = 2;
  14. break;
  15. case 1:
  16. data[0] = 0x14;
  17. size = 1;
  18. break;
  19. case 2:
  20. data[0] = 0x14;
  21. size = 1;
  22. break;
  23. case 3:
  24. data[0] = 0x14;
  25. size = 1;
  26. break;
  27. case 4:
  28. data[0] = 0x14;
  29. size = 1;
  30. break;
  31. case 5:
  32. data[0] = 0x14;
  33. size = 1;
  34. break;
  35. case 6:
  36. data[0] = 0x14;
  37. size = 1;
  38. break;
  39. case 7:
  40. data[0] = 0x14;
  41. size = 1;
  42. break;
  43. }
  44. *read_bytes += size;
  45. }
  46. static void read_1100(uint8_t memoft, uint8_t *data, uint8_t *read_bytes)
  47. {
  48. uint8_t size = 0;
  49. switch (memoft)
  50. {
  51. case 0:
  52. data[0] = 0x12;
  53. data[1] = 0x13;
  54. size = 2;
  55. break;
  56. case 1:
  57. data[0] = 0x14;
  58. size = 1;
  59. break;
  60. case 2:
  61. data[0] = 0x14;
  62. size = 1;
  63. break;
  64. case 3:
  65. data[0] = 0x14;
  66. size = 1;
  67. break;
  68. case 4:
  69. data[0] = 0x14;
  70. size = 1;
  71. break;
  72. case 5:
  73. data[0] = 0x14;
  74. size = 1;
  75. break;
  76. case 6:
  77. data[0] = 0x14;
  78. size = 1;
  79. break;
  80. case 7:
  81. data[0] = 0x14;
  82. size = 1;
  83. break;
  84. }
  85. *read_bytes += size;
  86. }
  87. const regist_read_type mem_read_table[] = {
  88. {0x1000, read_1000},
  89. {0x1100, read_1100},
  90. };
  91. uint8_t aa = 0;
  92. uint8_t bb = 0;
  93. uint8_t cc = 0;
  94. static void write_1000(uint8_t memoft, uint8_t *data, uint8_t *read_bytes)
  95. {
  96. uint8_t size = 0;
  97. switch (memoft)
  98. {
  99. case 0:
  100. aa = data[0];
  101. bb = data[1];
  102. size = 2;
  103. break;
  104. case 1:
  105. cc = data[0];
  106. size = 1;
  107. break;
  108. }
  109. *read_bytes += size;
  110. }
  111. const regist_read_type mem_write_table[] = {
  112. {0x1000, write_1000},
  113. };
  114. uint8_t get_regist_value(uart_type *p_data, uint8_t mem_start_addr, uint8_t read_len)
  115. {
  116. uint8_t len, i;
  117. uint8_t cur_len = 0;
  118. uint8_t mem_addr_oft = 0;
  119. uint16_t mem_addr = 0;
  120. uint8_t *ptr = 0;
  121. mem_addr_oft = (uint8_t)(mem_start_addr & 0x000F);
  122. mem_addr = mem_start_addr & 0xFFF0;
  123. len = read_len;
  124. ptr = &p_data->tx[4];
  125. for (i = 0; i < ARR_SIZE(mem_read_table); i++)
  126. {
  127. if ((mem_addr = mem_read_table[i].addr) && mem_read_table[i].p_func != 0)
  128. {
  129. do
  130. {
  131. mem_read_table[i].p_func(mem_addr_oft++, &ptr[cur_len], &cur_len);
  132. } while ((cur_len < len) && (mem_addr_oft < 16));
  133. if (cur_len > len)
  134. {
  135. return 0;
  136. }
  137. else if (cur_len < len)
  138. {
  139. mem_addr = mem_addr + mem_addr_oft & 0xFFF0;
  140. mem_addr_oft = 0;
  141. }
  142. else
  143. {
  144. return 1;
  145. }
  146. }
  147. }
  148. return 0;
  149. }
  150. uint8_t set_regist_value(uart_type *p_data, uint8_t mem_start_addr, uint8_t read_len)
  151. {
  152. uint8_t len, i;
  153. uint8_t cur_len = 0;
  154. uint8_t mem_addr_oft = 0;
  155. uint16_t mem_addr = 0;
  156. uint8_t *ptr = 0;
  157. mem_addr_oft = (uint8_t)(mem_start_addr & 0x000F);
  158. mem_addr = mem_start_addr & 0xFFF0;
  159. len = read_len;
  160. ptr = &p_data->rx[5];
  161. for (i = 0; i < ARR_SIZE(mem_write_table); i++)
  162. {
  163. if ((mem_addr = mem_write_table[i].addr) && mem_write_table[i].p_func != 0)
  164. {
  165. do
  166. {
  167. mem_write_table[i].p_func(mem_addr_oft++, &ptr[cur_len], &cur_len);
  168. } while ((cur_len < len) && mem_addr_oft < 17);
  169. if ((mem_addr_oft >= 17) || (cur_len != len))
  170. {
  171. return 0;
  172. }
  173. else
  174. {
  175. return 1;
  176. }
  177. }
  178. }
  179. return 0;
  180. }