sensor_driver.c 6.2 KB

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