sensor_epsonCommon.c
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // sensor_epsonImu.c - Epson IMU sensor protocol specific code common
4 // for all IMU models
5 //
6 //
7 // THE SOFTWARE IS RELEASED INTO THE PUBLIC DOMAIN.
8 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
9 // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT,
10 // SECURITY, SATISFACTORY QUALITY, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
11 // SHALL EPSON BE LIABLE FOR ANY LOSS, DAMAGE OR CLAIM, ARISING FROM OR IN CONNECTION
12 // WITH THE SOFTWARE OR THE USE OF THE SOFTWARE.
13 //
14 //==============================================================================
15 #include "sensor_epsonCommon.h"
16 #include "hcl.h"
17 #include "hcl_gpio.h"
18 
19 
20 /*****************************************************************************
21 ** Function name: sensorHWReset
22 ** Description: Toggle the RESET pin, delay, wait for NOT_READY bit=0
23 ** This is only applicable on embedded platforms with
24 ** GPIO pin connected to IMU RESET#
25 ** Parameters: None
26 ** Return value: 1=success, 0=fail
27 *****************************************************************************/
28 int sensorHWReset( void )
29 {
30  unsigned int debug = FALSE;
31  unsigned short rxData;
32  unsigned short retryCount = 3000;
33 
34  gpioSet(EPSON_RESET); // RESET pin HIGH
36  gpioClr(EPSON_RESET); // Assert RESET (LOW)
38  gpioSet(EPSON_RESET); // Deassert RESET (HIGH)
40 
41  // Poll NOT_READY bit every 1msec until returns 0
42  // Exit after specified retries
43  do
44  {
46  seDelayMicroSecs(1000);
47  retryCount--;
48  } while((rxData & 0x0400) == 0x0400 && (retryCount != 0));
49 
50  if (retryCount == 0)
51  {
52  printf("\r\n...Error: NOT_READY stuck HIGH.");
53  return FALSE;
54  }
55  return TRUE;
56 }
57 
58 
59 /*****************************************************************************
60 ** Function name: sensorPowerOn
61 ** Description: Initial startup, Goto Config Mode (sanity),
62 ** Trigger HW Reset, check for Hardware Error Flags
63 ** Parameters: None
64 ** Return value: 1=success, 0=fail
65 *****************************************************************************/
66 int sensorPowerOn(void)
67 {
68  unsigned short rxData = 0xFFFF;
69  unsigned int debug = FALSE;
70  unsigned short retryCount = 3000;
71 
72  // Safety Measure, Force Exit of Sampling Mode
73  do
74  {
77  seDelayMicroSecs(1000);
78  retryCount--;
79  } while((rxData & 0x0400) == 0x0000 && (retryCount != 0));
80 
81  if (retryCount == 0)
82  {
83  printf("\r\n...Error: Stuck in Sampling Mode.");
84  return FALSE;
85  }
86 
87  // Hardware Reset if connected, and check for NOT_READY flag
88  if (!sensorHWReset())
89  return FALSE;
90 
91  // Check for error flags
92  rxData = registerRead16(CMD_WINDOW0, ADDR_DIAG_STAT, debug);
93  if (rxData == 0x0000)
94  return TRUE; /* success */
95  else
96  return FALSE; /* fail */
97 }
98 
99 
100 
101 /*****************************************************************************
102 ** Function name: sensorStart
103 ** Description: Start sensor sampling (goto Sampling Mode)
104 ** Parameters: None
105 ** Return value: None
106 *****************************************************************************/
107 void sensorStart(void)
108 {
109  unsigned int debug = FALSE;
110 
112  printf("\r\n...Sensor start.");
113 }
114 
115 
116 /*****************************************************************************
117 ** Function name: sensorStop
118 ** Description: Stop sensor sampling (goto Config Mode)
119 ** Parameters: None
120 ** Return value: None
121 *****************************************************************************/
122 void sensorStop(void)
123 {
124  unsigned int debug = FALSE;
125 
127  seDelayMicroSecs(200000); // Provide 200msec for sensor to finish sending sample
128  printf("\r\n...Sensor stop.");
129 }
130 
131 
132 /*****************************************************************************
133 ** Function name: sensorReset
134 ** Description: Send Software Reset to Sensor + Delay 800 msec
135 ** Parameters: None
136 ** Return value: None
137 *****************************************************************************/
138 void sensorReset(void)
139 {
140  unsigned int debug = FALSE;
141 
142  printf("\r\n...Software Reset begin.");
145  printf("\r\n...Software Reset complete.");
146 }
147 
148 
149 /*****************************************************************************
150 ** Function name: sensorFlashTest
151 ** Description: Send Flashtest command to Sensor and check status
152 ** NOTE: Not supported for V340
153 ** Parameters: None
154 ** Return value: 1=success, 0=fail
155 *****************************************************************************/
157 {
158  unsigned int debug = FALSE;
159  unsigned short rxData;
160  unsigned short retryCount = 3000;
161 
162  printf("\r\n...Flash test begin.");
165  do
166  {
167  rxData = registerRead16(CMD_WINDOW1, ADDR_MSC_CTRL_LO, debug);
168  retryCount--;
169  } while((rxData & 0x0800) == 0x0800 && (retryCount != 0));
170  if (retryCount == 0)
171  {
172  printf("\r\n...Error: Flashtest bit did not retrun to 0b.");
173  return FALSE;
174  }
175 
176  rxData = registerRead16(CMD_WINDOW0, ADDR_DIAG_STAT, debug);
177  printf("\r\n...Flash test complete.");
178 
179  if ((rxData & 0x0004) == 0x0000)
180  return TRUE;
181  else
182  return FALSE;
183 
184 }
185 
186 
187 /*****************************************************************************
188 ** Function name: sensorSelfTest
189 ** Description: Send SelfTest command to Sensor and check status
190 ** Parameters: None
191 ** Return value: 1=success, 0=fail
192 *****************************************************************************/
193 int sensorSelfTest(void)
194 {
195  unsigned int debug = FALSE;
196  unsigned short rxData;
197  unsigned short retryCount = 3000;
198 
199  printf("\r\n...Self test begin.");
202  do
203  {
204  rxData = registerRead16(CMD_WINDOW1, ADDR_MSC_CTRL_LO, debug);
205  retryCount--;
206  } while((rxData & 0x0400) == 0x0400 && (retryCount != 0));
207  if (retryCount == 0)
208  {
209  printf("\r\n...Error: Self test bit did not return to 0b.");
210  return FALSE;
211  }
212 
213  rxData = registerRead16(CMD_WINDOW0, ADDR_DIAG_STAT, debug);
214  printf("\r\n...Self test complete.");
215 
216  if ((rxData & 0x0002) == 0x0000)
217  return TRUE;
218  else
219  return FALSE;
220 
221 }
222 
223 
224 /*****************************************************************************
225 ** Function name: ppSensorDataRead32N
226 ** Description: 32-bit post process for sensor data array returned
227 ** by either sensorDataReadN() or sensorDataReadBurstN()
228 ** NOTE: Not supported for G350 or V340
229 ** Parameters: Pointer to output double float array,
230 ** pointer to input signed short array, start index
231 ** Return value: none
232 ** Notes:
233 ** 1. The input array order is assumed to be: GX GY GZ , AX AY AZ
234 ** The sensor output bit mode is assumed to be 32-bit.
235 ** Each input array element contains 16-bit data.
236 *****************************************************************************/
237 void ppSensorDataRead32N(double ppSensorReadData[], signed short sensorReadData[], unsigned char startIndex)
238 {
239  ppSensorReadData[0] = ((sensorReadData[startIndex] << 16) + sensorReadData[startIndex + 1]) * EPSON_GYRO_SF/65536;
240  ppSensorReadData[1] = ((sensorReadData[startIndex + 2] << 16) + sensorReadData[startIndex + 3]) * EPSON_GYRO_SF/65536;
241  ppSensorReadData[2] = ((sensorReadData[startIndex + 4] << 16) + sensorReadData[startIndex + 5]) * EPSON_GYRO_SF/65536;
242 
243  ppSensorReadData[3] = ((sensorReadData[startIndex + 6] << 16) + sensorReadData[startIndex + 7]) * EPSON_ACCL_SF/65536;
244  ppSensorReadData[4] = ((sensorReadData[startIndex + 8] << 16) + sensorReadData[startIndex + 9]) * EPSON_ACCL_SF/65536;
245  ppSensorReadData[5] = ((sensorReadData[startIndex + 10] << 16) + sensorReadData[startIndex + 11]) * EPSON_ACCL_SF/65536;
246 }
247 
248 
249 /*****************************************************************************
250 ** Function name: ppSensorDataRead16N
251 ** Description: 16-bit post process for sensor data array returned
252 ** by either sensorDataReadN() or sensorDataReadBurstN()
253 ** NOTE: Must be used for V340 or G350
254 ** Parameters: Pointer to output double float array,
255 ** pointer to input signed short array, start index
256 ** Return value: none
257 ** Notes:
258 ** 1. The input array order is assumed to be: GX GY GZ , AX AY AZ
259 ** The sensor output bit mode is assumed to be 16-bit.
260 ** Each input array element contains 16-bit data.
261 *****************************************************************************/
262 void ppSensorDataRead16N(double ppSensorReadData[], signed short sensorReadData[], unsigned char startIndex)
263 {
264  ppSensorReadData[0] = (sensorReadData[startIndex]) * EPSON_GYRO_SF;
265  ppSensorReadData[1] = (sensorReadData[startIndex + 1]) * EPSON_GYRO_SF;
266  ppSensorReadData[2] = (sensorReadData[startIndex + 2]) * EPSON_GYRO_SF;
267 
268  ppSensorReadData[3] = (sensorReadData[startIndex + 3]) * EPSON_ACCL_SF;
269  ppSensorReadData[4] = (sensorReadData[startIndex + 4]) * EPSON_ACCL_SF;
270  ppSensorReadData[5] = (sensorReadData[startIndex + 5]) * EPSON_ACCL_SF;
271 }
272 
273 /*****************************************************************************
274 ** Function name: calChksum16
275 ** Description: Calculate checksum16 from array of 16-bit words retrieved
276 ** from IMU burst read (does not contain header (0x80) or
277 ** delimiter (0x0D) byte
278 ** Parameters: pointer to unsigned short array, end index to calculate to
279 ** Return value: 16-bit checksum value
280 ** Notes:
281 ** 1. The burst packet consists of 16-bit data units.
282 ** Usually the last index in the array contains the IMU generated checksum16
283 ** to compare to
284 **
285 *****************************************************************************/
286 unsigned short calChecksum16(unsigned short sensorReadData[], unsigned int endOffset)
287 {
288  int i;
289  unsigned short chksum16_calc = 0;
290 
291  for (i = 0; i < endOffset; i++)
292  chksum16_calc += sensorReadData[i];
293 
294  return chksum16_calc;
295 }
#define DELAY_EPSON_RESET
#define EPSON_POWER_ON_DELAY
#define ADDR_MSC_CTRL_LO
int sensorFlashTest(void)
#define CMD_WINDOW1
#define CMD_SOFTRESET
#define FALSE
Definition: hcl_uart.c:32
#define TRUE
Definition: hcl_uart.c:31
#define CMD_SELFTEST
#define CMD_WINDOW0
#define EPSON_GYRO_SF
void gpioSet(uint8_t pin)
Definition: hcl_gpio.c:53
void sensorStop(void)
#define EPSON_SELF_TEST_DELAY
#define ADDR_MODE_CTRL_HI
#define EPSON_FLASH_TEST_DELAY
#define ADDR_MODE_CTRL_LO
void seDelayMicroSecs(uint32_t micros)
Definition: hcl_linux.c:67
#define EPSON_RESET
Definition: hcl_gpio.h:27
unsigned short registerRead16(unsigned char, unsigned char, unsigned int)
void registerWriteByte(unsigned char, unsigned char, unsigned char, unsigned int)
#define ADDR_GLOB_CMD_LO
void gpioClr(uint8_t pin)
Definition: hcl_gpio.c:65
unsigned short calChecksum16(unsigned short sensorReadData[], unsigned int endOffset)
int sensorHWReset(void)
#define CMD_END_SAMPLING
void ppSensorDataRead32N(double ppSensorReadData[], signed short sensorReadData[], unsigned char startIndex)
void sensorStart(void)
#define ADDR_DIAG_STAT
#define CMD_FLASHTEST
#define EPSON_ACCL_SF
void seDelayMS(uint32_t millis)
Definition: hcl_linux.c:54
int sensorSelfTest(void)
int sensorPowerOn(void)
#define ADDR_MSC_CTRL_HI
void ppSensorDataRead16N(double ppSensorReadData[], signed short sensorReadData[], unsigned char startIndex)
void sensorReset(void)
#define CMD_BEGIN_SAMPLING


epson_g364_imu_driver
Author(s):
autogenerated on Mon Jun 10 2019 13:12:32