sensor_driver.c 6.5 KB

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