uart_table.c 4.1 KB

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