sensor_driver.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /*
  2. * Implement sensor driver function in here.
  3. * Every sensor include init,write,read function.
  4. * Author:Jimbo
  5. */
  6. #include <stdint.h>
  7. #include <stdio.h>
  8. #include "sensor_tbl.h"
  9. #include "hal_interface_api.h"
  10. #include "linux/fcntl.h"
  11. /*
  12. * sensor number: 1
  13. * sensor name: +12V
  14. * brief: ltc4280
  15. */
  16. int sensor_1_init(void)
  17. {
  18. return 0;
  19. }
  20. int sensor_1_write(void)
  21. {
  22. return 0;
  23. }
  24. int sensor_1_read(uint8_t *reading)
  25. {
  26. uint8_t buf = 5;
  27. // int fd = open("/dev/i2c3", O_RDWR);
  28. // stm32_i2c_master_write(fd, 0xAA, &buf, 1);
  29. // stm32_i2c_master_read(fd, 0xAA, &buf, 1);
  30. // close(fd);
  31. //printf("read sensor 1: %#x!\n", buf);
  32. //*reading = buf;
  33. *reading = 0xff;
  34. return 0;
  35. }
  36. /*
  37. * sensor number: 2
  38. * sensor name: +12V_Current
  39. * brief: ltc4280
  40. */
  41. int sensor_2_init(void)
  42. {
  43. // log("init sensor 2!\r\n");
  44. return 0;
  45. }
  46. int sensor_2_write(void)
  47. {
  48. // log("write sensor 2!\r\n");
  49. return 0;
  50. }
  51. int sensor_2_read(uint8_t *reading)
  52. {
  53. uint8_t buf = 4;
  54. // int fd = open("/dev/i2c3", O_RDWR);
  55. // stm32_i2c_master_write(fd, 0xAA, &buf, 1);
  56. // stm32_i2c_master_read(fd, 0xAA, &buf, 1);
  57. // close(fd);
  58. //*reading = buf;
  59. *reading = 0xe0;
  60. return 0;
  61. }
  62. /*
  63. * sensor number: 3
  64. * sensor name: Temp_Board
  65. * brief: G780 local
  66. */
  67. int sensor_3_init(void)
  68. {
  69. // log("init sensor 2!\r\n");
  70. return 0;
  71. }
  72. int sensor_3_write(void)
  73. {
  74. // log("write sensor 2!\r\n");
  75. return 0;
  76. }
  77. int sensor_3_read(uint8_t *reading)
  78. {
  79. uint8_t buf = 0;
  80. // int fd = open("/dev/i2c3", O_RDWR);
  81. // stm32_i2c_master_write(fd, 0x98, &buf, 1);
  82. // stm32_i2c_master_read(fd, 0x98, &buf, 1);
  83. // close(fd);
  84. //*reading = buf;
  85. *reading = 0x80;
  86. return 0;
  87. }
  88. /*
  89. * sensor number: 4
  90. * sensor name: Temp_FPGA
  91. * brief: G780 remote
  92. */
  93. int sensor_4_init(void)
  94. {
  95. // log("init sensor 2!\r\n");
  96. return 0;
  97. }
  98. int sensor_4_write(void)
  99. {
  100. // log("write sensor 2!\r\n");
  101. return 0;
  102. }
  103. int sensor_4_read(uint8_t *reading)
  104. {
  105. uint8_t buf = 1;
  106. // int fd = open("/dev/i2c3", O_RDWR);
  107. // stm32_i2c_master_write(fd, 0x98, &buf, 1);
  108. // stm32_i2c_master_read(fd, 0x98, &buf, 1);
  109. // close(fd);
  110. //*reading = buf;
  111. *reading = 0x8a;
  112. return 0;
  113. }
  114. /*
  115. * sensor number: 5
  116. * sensor name: +1.5V
  117. * brief: adc_ch1
  118. */
  119. int sensor_5_init(void)
  120. {
  121. return 0;
  122. }
  123. int sensor_5_write(void)
  124. {
  125. return 0;
  126. }
  127. int sensor_5_read(uint8_t *reading)
  128. {
  129. uint16_t buf;
  130. // stm32_adc_get_value(1, &buf);
  131. //*reading = buf>>4;
  132. *reading = 0x50;
  133. return 0;
  134. }
  135. /*
  136. * sensor number: 6
  137. * sensor name: +0.75V
  138. * brief: adc_ch2
  139. */
  140. int sensor_6_init(void)
  141. {
  142. return 0;
  143. }
  144. int sensor_6_write(void)
  145. {
  146. return 0;
  147. }
  148. int sensor_6_read(uint8_t *reading)
  149. {
  150. uint16_t buf;
  151. // stm32_adc_get_value(2, &buf);
  152. //*reading = buf>>4;
  153. *reading = 0x60;
  154. return 0;
  155. }
  156. /*
  157. * sensor number: 7
  158. * sensor name: +1.8V
  159. * brief: adc_ch3
  160. */
  161. int sensor_7_init(void)
  162. {
  163. return 0;
  164. }
  165. int sensor_7_write(void)
  166. {
  167. return 0;
  168. }
  169. int sensor_7_read(uint8_t *reading)
  170. {
  171. uint16_t buf;
  172. // stm32_adc_get_value(3, &buf);
  173. //*reading = buf>>4;
  174. *reading = 0x70;
  175. return 0;
  176. }
  177. /*
  178. * sensor number: 8
  179. * sensor name: +1.2V
  180. * brief: adc_ch4
  181. */
  182. int sensor_8_init(void)
  183. {
  184. return 0;
  185. }
  186. int sensor_8_write(void)
  187. {
  188. return 0;
  189. }
  190. int sensor_8_read(uint8_t *reading)
  191. {
  192. uint16_t buf;
  193. // stm32_adc_get_value(4, &buf);
  194. //*reading = buf>>4;
  195. *reading = 0x80;
  196. return 0;
  197. }
  198. /*
  199. * sensor number: 9
  200. * sensor name: +1.0V
  201. * brief: adc_ch5
  202. */
  203. int sensor_9_init(void)
  204. {
  205. return 0;
  206. }
  207. int sensor_9_write(void)
  208. {
  209. return 0;
  210. }
  211. int sensor_9_read(uint8_t *reading)
  212. {
  213. uint16_t buf;
  214. // stm32_adc_get_value(5, &buf);
  215. //*reading = buf>>4;
  216. *reading = 0x90;
  217. return 0;
  218. }
  219. /*
  220. * sensor number: 10
  221. * sensor name: +2.5V
  222. * brief: adc_ch6
  223. */
  224. int sensor_10_init(void)
  225. {
  226. return 0;
  227. }
  228. int sensor_10_write(void)
  229. {
  230. return 0;
  231. }
  232. int sensor_10_read(uint8_t *reading)
  233. {
  234. uint16_t buf;
  235. // stm32_adc_get_value(6, &buf);
  236. //*reading = buf>>4;
  237. *reading = 0xA0;
  238. return 0;
  239. }
  240. /*
  241. * sensor number: 11
  242. * sensor name: +3.3V
  243. * brief: adc_ch7
  244. */
  245. int sensor_11_init(void)
  246. {
  247. return 0;
  248. }
  249. int sensor_11_write(void)
  250. {
  251. return 0;
  252. }
  253. int sensor_11_read(uint8_t *reading)
  254. {
  255. uint16_t buf;
  256. // stm32_adc_get_value(7, &buf);
  257. //*reading = buf>>4;
  258. *reading = 0xB0;
  259. return 0;
  260. }
  261. sensor_tbl_t sensor_tbl[]=
  262. {
  263. {
  264. 1, //sensor number
  265. 0, //power on delay
  266. 0, //reset delay
  267. 3, //Monitor interval
  268. MonitorOnStandby, //monitor states
  269. sensor_1_read, //read function
  270. sensor_1_write, //write functon
  271. sensor_1_init, //init function
  272. },
  273. {
  274. 2, //sensor number
  275. 0, //power on delay
  276. 0, //reset delay
  277. 3, //Monitor interval
  278. MonitorOnStandby, //monitor states
  279. sensor_2_read,
  280. sensor_2_write,
  281. sensor_2_init,
  282. },
  283. {
  284. 3, //sensor number
  285. 0, //power on delay
  286. 0, //reset delay
  287. 3, //Monitor interval
  288. MonitorOnStandby, //monitor states
  289. sensor_3_read,
  290. sensor_3_write,
  291. sensor_3_init,
  292. },
  293. {
  294. 4, //sensor number
  295. 0, //power on delay
  296. 0, //reset delay
  297. 3, //Monitor interval
  298. MonitorOnStandby, //monitor states
  299. sensor_4_read,
  300. sensor_4_write,
  301. sensor_4_init,
  302. },
  303. {
  304. 5, //sensor number
  305. 0, //power on delay
  306. 0, //reset delay
  307. 3, //Monitor interval
  308. MonitorOnStandby, //monitor states
  309. sensor_5_read,
  310. sensor_5_write,
  311. sensor_5_init,
  312. },
  313. {
  314. 6, //sensor number
  315. 0, //power on delay
  316. 0, //reset delay
  317. 3, //Monitor interval
  318. MonitorOnStandby, //monitor states
  319. sensor_6_read,
  320. sensor_6_write,
  321. sensor_6_init,
  322. },
  323. {
  324. 7, //sensor number
  325. 0, //power on delay
  326. 0, //reset delay
  327. 3, //Monitor interval
  328. MonitorOnStandby, //monitor states
  329. sensor_7_read,
  330. sensor_7_write,
  331. sensor_7_init,
  332. },
  333. {
  334. 8, //sensor number
  335. 0, //power on delay
  336. 0, //reset delay
  337. 3, //Monitor interval
  338. MonitorOnStandby, //monitor states
  339. sensor_8_read,
  340. sensor_8_write,
  341. sensor_8_init,
  342. },
  343. {
  344. 9, //sensor number
  345. 0, //power on delay
  346. 0, //reset delay
  347. 3, //Monitor interval
  348. MonitorOnStandby, //monitor states
  349. sensor_9_read,
  350. sensor_9_write,
  351. sensor_9_init,
  352. },
  353. {
  354. 10, //sensor number
  355. 0, //power on delay
  356. 0, //reset delay
  357. 3, //Monitor interval
  358. MonitorOnStandby, //monitor states
  359. sensor_10_read,
  360. sensor_10_write,
  361. sensor_10_init,
  362. },
  363. {
  364. 11, //sensor number
  365. 0, //power on delay
  366. 0, //reset delay
  367. 3, //Monitor interval
  368. MonitorOnStandby, //monitor states
  369. sensor_11_read,
  370. sensor_11_write,
  371. sensor_11_init,
  372. }
  373. };
  374. sensor_tbl_t *getSensorDev(uint8_t sensorNum)
  375. {
  376. uint16_t i = 0;
  377. uint16_t sensorCnt=0;
  378. sensorCnt = sizeof(sensor_tbl)/sizeof(sensor_tbl_t);
  379. for(i=0; i<sensorCnt; i++)
  380. {
  381. if(sensor_tbl[i].sensor_number == sensorNum)
  382. return &sensor_tbl[i];
  383. }
  384. printf("Error: Can't find sensor, sensorNum = %#x\r\n", sensorNum);
  385. return NULL;
  386. }