123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- /*
- * Implement sensor driver function in here.
- * Every sensor include init,write,read function.
- * Author:Jimbo
- */
- #include <stdint.h>
- #include <stdio.h>
- #include "sensor_tbl.h"
- #include "hal_interface_api.h"
- #include "linux/fcntl.h"
- /*
- * sensor number: 1
- * sensor name: +12V
- * brief: ltc4280
- */
- int sensor_1_init(void)
- {
- return 0;
- }
- int sensor_1_write(void)
- {
- return 0;
- }
- int sensor_1_read(uint8_t *reading)
- {
- uint8_t buf = 5;
- int fd = open("/dev/i2c3", O_RDWR);
- stm32_i2c_master_write(fd, 0xAA, &buf, 1);
- stm32_i2c_master_read(fd, 0xAA, &buf, 1);
- close(fd);
- //printf("read sensor 1: %#x!\n", buf);
- *reading = buf;
- return 0;
- }
- /*
- * sensor number: 2
- * sensor name: +12V_Current
- * brief: ltc4280
- */
- int sensor_2_init(void)
- {
- // log("init sensor 2!\r\n");
- return 0;
- }
- int sensor_2_write(void)
- {
- // log("write sensor 2!\r\n");
- return 0;
- }
- int sensor_2_read(uint8_t *reading)
- {
- uint8_t buf = 4;
- int fd = open("/dev/i2c3", O_RDWR);
- stm32_i2c_master_write(fd, 0xAA, &buf, 1);
- stm32_i2c_master_read(fd, 0xAA, &buf, 1);
- close(fd);
- *reading = buf;
- return 0;
- }
- /*
- * sensor number: 3
- * sensor name: Temp_Board
- * brief: G780 local
- */
- int sensor_3_init(void)
- {
- // log("init sensor 2!\r\n");
- return 0;
- }
- int sensor_3_write(void)
- {
- // log("write sensor 2!\r\n");
- return 0;
- }
- int sensor_3_read(uint8_t *reading)
- {
- uint8_t buf = 0;
- int fd = open("/dev/i2c3", O_RDWR);
- stm32_i2c_master_write(fd, 0x98, &buf, 1);
- stm32_i2c_master_read(fd, 0x98, &buf, 1);
- close(fd);
- *reading = buf;
- return 0;
- }
- /*
- * sensor number: 4
- * sensor name: Temp_FPGA
- * brief: G780 remote
- */
- int sensor_4_init(void)
- {
- // log("init sensor 2!\r\n");
- return 0;
- }
- int sensor_4_write(void)
- {
- // log("write sensor 2!\r\n");
- return 0;
- }
- int sensor_4_read(uint8_t *reading)
- {
- uint8_t buf = 1;
- int fd = open("/dev/i2c3", O_RDWR);
- stm32_i2c_master_write(fd, 0x98, &buf, 1);
- stm32_i2c_master_read(fd, 0x98, &buf, 1);
- close(fd);
- *reading = buf;
- return 0;
- }
- /*
- * sensor number: 5
- * sensor name: +1.5V
- * brief: adc_ch1
- */
- int sensor_5_init(void)
- {
- return 0;
- }
- int sensor_5_write(void)
- {
- return 0;
- }
- int sensor_5_read(uint8_t *reading)
- {
- uint16_t buf;
- stm32_adc_get_value(1, &buf);
- *reading = buf>>4;
- return 0;
- }
- /*
- * sensor number: 6
- * sensor name: +0.75V
- * brief: adc_ch2
- */
- int sensor_6_init(void)
- {
- return 0;
- }
- int sensor_6_write(void)
- {
- return 0;
- }
- int sensor_6_read(uint8_t *reading)
- {
- uint16_t buf;
- stm32_adc_get_value(2, &buf);
- *reading = buf>>4;
- return 0;
- }
- /*
- * sensor number: 7
- * sensor name: +1.8V
- * brief: adc_ch3
- */
- int sensor_7_init(void)
- {
- return 0;
- }
- int sensor_7_write(void)
- {
- return 0;
- }
- int sensor_7_read(uint8_t *reading)
- {
- uint16_t buf;
- stm32_adc_get_value(3, &buf);
- *reading = buf>>4;
- return 0;
- }
- /*
- * sensor number: 8
- * sensor name: +1.2V
- * brief: adc_ch4
- */
- int sensor_8_init(void)
- {
- return 0;
- }
- int sensor_8_write(void)
- {
- return 0;
- }
- int sensor_8_read(uint8_t *reading)
- {
- uint16_t buf;
- stm32_adc_get_value(4, &buf);
- *reading = buf>>4;
- return 0;
- }
- /*
- * sensor number: 9
- * sensor name: +1.0V
- * brief: adc_ch5
- */
- int sensor_9_init(void)
- {
- return 0;
- }
- int sensor_9_write(void)
- {
- return 0;
- }
- int sensor_9_read(uint8_t *reading)
- {
- uint16_t buf;
- stm32_adc_get_value(5, &buf);
- *reading = buf>>4;
- return 0;
- }
- /*
- * sensor number: 10
- * sensor name: +2.5V
- * brief: adc_ch6
- */
- int sensor_10_init(void)
- {
- return 0;
- }
- int sensor_10_write(void)
- {
- return 0;
- }
- int sensor_10_read(uint8_t *reading)
- {
- uint16_t buf;
- stm32_adc_get_value(6, &buf);
- *reading = buf>>4;
- return 0;
- }
- /*
- * sensor number: 11
- * sensor name: +3.3V
- * brief: adc_ch7
- */
- int sensor_11_init(void)
- {
- return 0;
- }
- int sensor_11_write(void)
- {
- return 0;
- }
- int sensor_11_read(uint8_t *reading)
- {
- uint16_t buf;
- stm32_adc_get_value(7, &buf);
- *reading = buf>>4;
- return 0;
- }
- sensor_tbl_t sensor_tbl[]=
- {
- {
- 1, //sensor number
- 0, //power on delay
- 0, //reset delay
- 3, //Monitor interval
- MonitorOnStandby, //monitor states
- sensor_1_read, //read function
- sensor_1_write, //write functon
- sensor_1_init, //init function
- },
-
- {
- 2, //sensor number
- 0, //power on delay
- 0, //reset delay
- 3, //Monitor interval
- MonitorOnStandby, //monitor states
- sensor_2_read,
- sensor_2_write,
- sensor_2_init,
- },
-
- {
- 3, //sensor number
- 0, //power on delay
- 0, //reset delay
- 3, //Monitor interval
- MonitorOnStandby, //monitor states
- sensor_3_read,
- sensor_3_write,
- sensor_3_init,
- },
-
- {
- 4, //sensor number
- 0, //power on delay
- 0, //reset delay
- 3, //Monitor interval
- MonitorOnStandby, //monitor states
- sensor_4_read,
- sensor_4_write,
- sensor_4_init,
- },
-
- {
- 5, //sensor number
- 0, //power on delay
- 0, //reset delay
- 3, //Monitor interval
- MonitorOnStandby, //monitor states
- sensor_5_read,
- sensor_5_write,
- sensor_5_init,
- },
-
- {
- 6, //sensor number
- 0, //power on delay
- 0, //reset delay
- 3, //Monitor interval
- MonitorOnStandby, //monitor states
- sensor_6_read,
- sensor_6_write,
- sensor_6_init,
- },
-
- {
- 7, //sensor number
- 0, //power on delay
- 0, //reset delay
- 3, //Monitor interval
- MonitorOnStandby, //monitor states
- sensor_7_read,
- sensor_7_write,
- sensor_7_init,
- },
-
- {
- 8, //sensor number
- 0, //power on delay
- 0, //reset delay
- 3, //Monitor interval
- MonitorOnStandby, //monitor states
- sensor_8_read,
- sensor_8_write,
- sensor_8_init,
- },
-
- {
- 9, //sensor number
- 0, //power on delay
- 0, //reset delay
- 3, //Monitor interval
- MonitorOnStandby, //monitor states
- sensor_9_read,
- sensor_9_write,
- sensor_9_init,
- },
-
- {
- 10, //sensor number
- 0, //power on delay
- 0, //reset delay
- 3, //Monitor interval
- MonitorOnStandby, //monitor states
- sensor_10_read,
- sensor_10_write,
- sensor_10_init,
- },
-
- {
- 11, //sensor number
- 0, //power on delay
- 0, //reset delay
- 3, //Monitor interval
- MonitorOnStandby, //monitor states
- sensor_11_read,
- sensor_11_write,
- sensor_11_init,
- }
-
- };
- sensor_tbl_t *getSensorDev(uint8_t sensorNum)
- {
- uint16_t i = 0;
- uint16_t sensorCnt=0;
- sensorCnt = sizeof(sensor_tbl)/sizeof(sensor_tbl_t);
-
- for(i=0; i<sensorCnt; i++)
- {
- if(sensor_tbl[i].sensor_number == sensorNum)
- return &sensor_tbl[i];
- }
-
- printf("Error: Can't find sensor, sensorNum = %#x\r\n", sensorNum);
- return NULL;
- }
|