40 #define verify_info(MSG, ...) printf(MSG " | ", ## __VA_ARGS__)
44 typedef const char * (*verify_fn_t)();
60 static const char * verify_sht21()
64 return "I2C read error";
67 if ((v < 1500) || (v > 5000)) {
68 sprintf(fmt_buf,
"Temperature odd: %d C\n", v / 100);
79 static const char * verify_max123x(uint8_t addr)
82 sprintf(fmt_buf,
"Powerboard ADC failure @%02x", addr);
88 static const char * verify_max123x_ch(uint8_t addr,
int ch,
int conv,
char * unit, uint32_t mn, uint32_t mx)
92 sprintf(fmt_buf,
"Powerboard ADC read @%02x, ch=%u", addr, ch);
96 uint32_t val = ((uint32_t)result * conv) / MAX123X_MAX_VALUE;
97 verify_info(
"%5d %s", val, unit);
99 if (val < mn || val > mx) {
100 sprintf(fmt_buf,
"Out of bounds (%d, %d)", mn, mx);
108 static inline const char * verify_max123x_0() {
return verify_max123x(
POWER_ADC0_I2C_ADDR); }
109 static inline const char * verify_max123x_1() {
return verify_max123x(POWER_ADC1_I2C_ADDR); }
111 static inline const char * verify_max123x_0_c12v() {
return verify_max123x_ch(
POWER_ADC0_I2C_ADDR, 0, 3300,
"mA", 300, 450); }
112 static inline const char * verify_max123x_0_c1v() {
return verify_max123x_ch(
POWER_ADC0_I2C_ADDR, 1, 3300,
"mA", 600, 1000); }
113 static inline const char * verify_max123x_0_c1v8() {
return verify_max123x_ch(
POWER_ADC0_I2C_ADDR, 2, 1320,
"mA", 400, 550); }
114 static inline const char * verify_max123x_0_c2v5() {
return verify_max123x_ch(
POWER_ADC0_I2C_ADDR, 3, 1320,
"mA", 100, 200); }
115 static inline const char * verify_max123x_0_c3v3() {
return verify_max123x_ch(
POWER_ADC0_I2C_ADDR, 4, 3300,
"mA", 300, 450); }
116 static inline const char * verify_max123x_0_c5v() {
return verify_max123x_ch(
POWER_ADC0_I2C_ADDR, 5, 1320,
"mA", 0, 10); }
117 static inline const char * verify_max123x_0_cpmt() {
return verify_max123x_ch(
POWER_ADC0_I2C_ADDR, 6, 1320,
"mA", 0, 1000); }
118 static inline const char * verify_max123x_0_cvled() {
return verify_max123x_ch(
POWER_ADC0_I2C_ADDR, 7, 6600,
"mA", 10, 40); }
119 static inline const char * verify_max123x_0_lvled() {
return verify_max123x_ch(
POWER_ADC0_I2C_ADDR, 8, 33330,
"mV", 400, 700); }
120 static inline const char * verify_max123x_0_l12v() {
return verify_max123x_ch(
POWER_ADC0_I2C_ADDR, 9, 16500,
"mV", 11800, 12200); }
121 static inline const char * verify_max123x_0_temp() {
return verify_max123x_ch(
POWER_ADC0_I2C_ADDR, 10, 330000,
"mC", 20000, 45000); }
122 static inline const char * verify_max123x_1_l1v() {
return verify_max123x_ch(POWER_ADC1_I2C_ADDR, 0, 3300,
"mV", 950, 1050); }
123 static inline const char * verify_max123x_1_l1v8() {
return verify_max123x_ch(POWER_ADC1_I2C_ADDR, 1, 3300,
"mV", 1750, 1850); }
124 static inline const char * verify_max123x_1_l2v5() {
return verify_max123x_ch(POWER_ADC1_I2C_ADDR, 2, 3300,
"mV", 2450, 2550); }
125 static inline const char * verify_max123x_1_l3v3() {
return verify_max123x_ch(POWER_ADC1_I2C_ADDR, 3, 6600,
"mV", 3250, 3350); }
126 static inline const char * verify_max123x_1_l5v() {
return verify_max123x_ch(POWER_ADC1_I2C_ADDR, 4, 6600,
"mV", 4950, 5050); }
127 static inline const char * verify_max123x_1_lpmt() {
return verify_max123x_ch(POWER_ADC1_I2C_ADDR, 5, 6600,
"mV", 3250, 3350); }
128 static inline const char * verify_max123x_1_ldac() {
return verify_max123x_ch(POWER_ADC1_I2C_ADDR, 6, 3300,
"mV", 0, 1000); }
135 static const char * verify_compass()
143 uint8_t ahrs_addr = 0;
144 const char * rv = NULL;
145 bool isLSM303 =
false;
152 rv =
"No compass sensor found!";
156 }
else ahrs_addr = AHRS_I2C_PRIM_ADDR;
161 if (ahrs_addr != 0) {
162 verify_info(
"Compass = AHRS, version=%d", ahrs_addr, ver);
164 verify_info(
"Compass = LSM303", isLSM303);
167 if (ahrs_addr == 0 && !isLSM303)
169 rv =
"LSM303 reports not being LSM303!";
173 if (ahrs_addr != 0) {
174 if (!
ahrsRead(INS_I2C_DEV, ahrs_addr, &cmpDta))
176 rv =
"AHRS could not read compass data";
179 }
else if (isLSM303) {
181 .
magScale = LSM303D_MAGSCALE_2GAUSS,
182 .magRate = LSM303D_MAGRATE_12HZ5,
183 .magMode = LSM303D_MAGMODE_CONTINUOUS,
189 rv =
"LSM303 could not write magnetic cfg";
195 .
accRate = LSM303D_ACCRATE_12HZ5,
196 .accAAF = LSM303D_ACCAAF_773HZ,
197 .accHPF = LSM303D_ACCHPF_NORMAL,
198 .accScale = LSM303D_ACCSCALE_2G,
204 rv =
"LSM303 could not write accelerometer cfg";
216 rv =
"LSM303 could not write temperature cfg";
227 rv =
"LSM303 could not read compass direction";
237 rv =
"LSM303 could not read accelerometer information";
250 if (az < -11 || az > -9) {
251 rv =
"Accelerometer Z value not close to -1";
255 if (ax < -1 || ax > 1) {
256 rv =
"Accelerometer X value not close to 0";
260 if (ay < -1 || ay > 1) {
261 rv =
"Accelerometer Y value not close to 0";
278 static const char * verify_octopus_cpld(
I2C_Device * dev, uint8_t addr)
281 return "Did not wake up";
287 static const char * verify_octopus_cpld_small() {
291 static const char * verify_octopus_cpld_large() {
298 static const char * verify_octopus_mux(
I2C_Device * dev, uint8_t addr)
301 sprintf(fmt_buf,
"I2C mux @ %02xh failed", addr);
307 static inline const char * verify_octopus_mux_small_0() {
311 static inline const char * verify_octopus_mux_small_1() {
315 static inline const char * verify_octopus_mux_large_0() {
319 static inline const char * verify_octopus_mux_large_1() {
323 static inline const char * verify_octopus_mux_large_2() {
333 static const char * verify_pmt(
I2C_Device * dev, uint8_t cpld_addr, uint8_t mux_base_addr, uint8_t ch)
335 const char * rv = NULL;
339 rv =
"Failed to wake up CPLD this time";
344 rv =
"Failed to select CPLD channel";
352 rv =
"Failed to enable CPLD clock";
358 rv =
"Failed to select PCA channel";
364 rv =
"Failed to read promis ID";
366 verify_info(
"ID: %02x%02x%02x", buf[0],buf[1],buf[2]);
371 if (rv == NULL) rv =
"Failed to deselect PCA channel";
424 static const char * verify_nanobeacon_dac()
427 return "Failed to write DAC value";
438 { -1,
"SHT21", verify_sht21, -1, -1,
false },
439 { -1,
"Compass", verify_compass, -1, -1,
false},
440 { 7,
"Powerb ADC 0 exist", verify_max123x_0, -1, -1,
false},
441 { 8,
"Powerb ADC 1 exist", verify_max123x_1, -1, -1,
false},
442 { -1,
"Powerb 12V current", verify_max123x_0_c12v, 7, -1,
false},
443 { -1,
"Powerb 1V current", verify_max123x_0_c1v, 7, -1,
false},
444 { -1,
"Powerb 1.8V current", verify_max123x_0_c1v8, 7, -1,
false},
445 { -1,
"Powerb 2.5V current", verify_max123x_0_c2v5, 7, -1,
false},
446 { -1,
"Powerb 3.3V current", verify_max123x_0_c3v3, 7, -1,
false},
447 { -1,
"Powerb 5V current", verify_max123x_0_c5v, 7, -1,
false},
448 { -1,
"Powerb PMT current", verify_max123x_0_cpmt, 7, -1,
false},
449 { -1,
"Powerb LED current", verify_max123x_0_cvled, 7, -1,
false},
450 { -1,
"Powerb LED level", verify_max123x_0_lvled, 7, -1,
false},
451 { -1,
"Powerb 12V level", verify_max123x_0_l12v, 7, -1,
false},
452 { -1,
"Powerb temperature", verify_max123x_0_temp, 7, -1,
false},
453 { -1,
"Powerb 1V level", verify_max123x_1_l1v, 8, -1,
false},
454 { -1,
"Powerb 1.8V level", verify_max123x_1_l1v8, 8, -1,
false},
455 { -1,
"Powerb 2.5V level", verify_max123x_1_l2v5, 8, -1,
false},
456 { -1,
"Powerb 3.3V level", verify_max123x_1_l3v3, 8, -1,
false},
457 { -1,
"Powerb 5V level", verify_max123x_1_l5v, 8, -1,
false},
458 { -1,
"Powerb PMT level", verify_max123x_1_lpmt, 8, -1,
false},
459 { -1,
"Powerb DAC level", verify_max123x_1_ldac, 8, -1,
false},
460 { -1,
"Nano beacon DAC", verify_nanobeacon_dac, -1, -1,
false},
461 { 0,
"Octopus CPLD small", verify_octopus_cpld_small, -1, -1,
false},
462 { 1,
"Octopus CPLD large", verify_octopus_cpld_large, -1, -1,
false},
463 { 2,
"Octopus MUX 0 small", verify_octopus_mux_small_0, -1, -1,
false},
464 { 3,
"Octopus MUX 1 small", verify_octopus_mux_small_1, -1, -1,
false},
465 { 4,
"Octopus MUX 0 large", verify_octopus_mux_large_0, -1, -1,
false},
466 { 5,
"Octopus MUX 1 large", verify_octopus_mux_large_1, -1, -1,
false},
467 { 6,
"Octopus MUX 2 large", verify_octopus_mux_large_2, -1, -1,
false},
468 { -1,
"1 PMT 0 for small", verify_pmt_4_small_0, 0, 2,
false},
469 { -1,
"2 PMT 1 for small", verify_pmt_4_small_1, 0, 2,
false},
470 { -1,
"3 PMT 2 for small", verify_pmt_4_small_2, 0, 2,
false},
471 { -1,
"4 PMT 3 for small", verify_pmt_4_small_3, 0, 2,
false},
472 { -1,
"5 PMT 4 for small", verify_pmt_4_small_4, 0, 2,
false},
473 { -1,
"6 PMT 5 for small", verify_pmt_4_small_5, 0, 2,
false},
474 { -1,
"7 PMT 6 for small", verify_pmt_4_small_6, 0, 2,
false},
475 { -1,
"8 PMT 7 for small", verify_pmt_4_small_7, 0, 2,
false},
476 { -1,
"9 PMT 8 for small", verify_pmt_4_small_8, 0, 3,
false},
477 { -1,
"10 PMT 9 for small", verify_pmt_4_small_9, 0, 3,
false},
478 { -1,
"11 PMT 10 for small", verify_pmt_4_small_10, 0, 3,
false},
479 { -1,
"12 PMT 11 for small", verify_pmt_4_small_11, 0, 3,
false},
480 { -1,
"13 PMT 0 for large", verify_pmt_4_large_0, 1, 4,
false},
481 { -1,
"14 PMT 1 for large", verify_pmt_4_large_1, 1, 4,
false},
482 { -1,
"15 PMT 2 for large", verify_pmt_4_large_2, 1, 4,
false},
483 { -1,
"16 PMT 3 for large", verify_pmt_4_large_3, 1, 4,
false},
484 { -1,
"17 PMT 4 for large", verify_pmt_4_large_4, 1, 4,
false},
485 { -1,
"18 PMT 5 for large", verify_pmt_4_large_5, 1, 4,
false},
486 { -1,
"19 PMT 6 for large", verify_pmt_4_large_6, 1, 4,
false},
487 { -1,
"20 PMT 7 for large", verify_pmt_4_large_7, 1, 4,
false},
488 { -1,
"21 PMT 8 for large", verify_pmt_4_large_8, 1, 5,
false},
489 { -1,
"22 PMT 9 for large", verify_pmt_4_large_9, 1, 5,
false},
490 { -1,
"23 PMT 10 for large", verify_pmt_4_large_10, 1, 5,
false},
491 { -1,
"24 PMT 11 for large", verify_pmt_4_large_11, 1, 5,
false},
492 { -1,
"25 PMT 12 for large", verify_pmt_4_large_12, 1, 5,
false},
493 { -1,
"26 PMT 13 for large", verify_pmt_4_large_13, 1, 5,
false},
494 { -1,
"27 PMT 14 for large", verify_pmt_4_large_14, 1, 5,
false},
495 { -1,
"28 PMT 15 for large", verify_pmt_4_large_15, 1, 5,
false},
496 { -1,
"29 PMT 16 for large", verify_pmt_4_large_16, 1, 6,
false},
497 { -1,
"30 PMT 17 for large", verify_pmt_4_large_17, 1, 6,
false},
498 { -1,
"31 PMT 18 for large", verify_pmt_4_large_18, 1, 6,
false},
501 const char cmd_verify_help[] =
"Verify hardware";
503 bool cmd_verify_exec(
int argc,
const char *args[])
505 unsigned int executed = 0;
506 unsigned int skipped = 0;
507 unsigned int failed = 0;
511 const int no_of_tests =
sizeof(_tests)/
sizeof(_tests[0]);
513 printf(
"Starting %d CLB tests\n", no_of_tests);
515 for (
int i = 0; i < no_of_tests; i++)
523 if (test->label != -1) {
524 labels[test->label] = i;
528 test->failed =
false;
529 printf(
" %03d %-24s | ", i, test->name);
530 if (test->dep1 >= 0) {
531 if (_tests[labels[test->dep1]].failed) {
533 printf(
"Skipped because %s failed\n", _tests[labels[test->dep1]].name);
537 if (test->dep2 >= 0) {
538 if (_tests[labels[test->dep2]].failed) {
540 printf(
"Skipped because %s failed\n", _tests[labels[test->dep2]].name);
545 const char * result = test->fn();
548 if (result == NULL) {
558 printf(
"%s\n", result);
565 printf(
"Completed, executed=%d, failed=%d, skipped=%d\n", executed, failed, skipped);
Axis structure for 3D information.
This driver is to read and configure the AHRS I2C sensor.
#define POWER_I2C_DEV
Power board I2C device.
#define OCTOS_MUXB_I2C_ADDR
Octopus small I2C MUX base address.
bool ltc2631Write(I2C_Device *dev, uint8_t addr, uint16_t value, bool update)
Sets the DAC value on the input register.
#define OCTOS_CPLD_I2C_ADDR
Octopus small CLPD address.
Driver of the LTC2631 DAC as found on the power board.
#define OCTOL_CPLD_I2C_ADDR
Octopus large CLPD base address.
bool lsm303DMagnetCfg(I2C_Device *dev, uint8_t addr, Lsm303DMagCfg config)
Set the Magnet configuration.
#define POWER_DAC_I2C_ADDR
The address of the Power Board DAC (LTC2631)
bool ahrsGetVersion(I2C_Device *dev, uint8_t addr, uint8_t *version)
Reads the AHRS version.
Generic LSM303D configuration.
uint16_t accRate
Accelerometer rate , one of LSM303D_ACCRATE_*.
void gpioPinConf(int pin, GpioPinDir dir)
Configure PIN directionality.
#define OCTOS_I2C_DEV
Octopus small I2C device.
Accelerator configuration structure.
System start up and management.
bool lsm303DAccelRead(I2C_Device *dev, uint8_t addr, Lsm303Axis *result)
Read the accelerometer information.
f32_t hx
Hx in gauss (Float)
#define POWER_ADC0_I2C_ADDR
The address of the Power Board ADC (LTC2499) - deprecated, no longer used.
Structure defines OpenCores I2C Device.
#define OCTOL_I2C_DEV
Octopus large I2C device.
const char * errGetDescr()
Returns the last error description, if any, else null.
bool max123xConvert(I2C_Device *dev, i2cAddr addr, int ch, uint16_t *result)
Performs a single conversion of a specific channel.
bool prmsID(I2C_Device *dev, uint8_t addr, uint8_t *id)
Returns the burned ID of the PROMiS device.
bool sht21Temp(I2C_Device *dev, uint8_t addr, int *answer)
Starts and reads the temperatures from SHT21 at I2C address 'addr' (hold master mode); puts the resul...
void timeDelay(uint32_t msec)
Simple busy-wait delay.
f32_t hz
Hz in gauss (Float)
#define OCTOL_MUXB_I2C_ADDR
Octopus large I2C MUX base address.
bool max123xSetup(I2C_Device *dev, i2cAddr addr, int ref, bool extclk, bool bipolar)
Writes the setup register of the MAX123x.
void gpioPinSet(int pin, bool high)
Sets the pin state.
Structure defines data from a compass/tilt/gyro sensor.
#define LSM303D_I2C_ADDR
LSM303D Address.
Manages the global system error.
MAX123x multichannel ADC driver.
bool lsm303DValid(I2C_Device *dev, uint8_t addr, bool *isLSM303)
Checks whether or not the LSM303D is valid.
bool ahrsRead(I2C_Device *dev, uint8_t addr, CompassData *data)
Reads all data from the AHRS.
bool ocWrite(I2C_Device *dev, uint8_t addr, OCReg reg, uint32_t value)
Writes one of the CPLD registers.
void errClear()
Clears the current error.
#define GPIO_AHRS_ENABLE
Defines GPIO pins.
void sysClearCrashDetect()
Clear crash detect.
f32_t fltFromI16(int16_t val, int fBits)
Takes an integer value and converts it to a float.
uint32_t errGet()
Returns the last error code, or null.
This module is responsible for distributing error codes.
#define SHT21_I2C_ADDR
SHT21 I2C Address.
bool lsm303DMagnetRead(I2C_Device *dev, uint8_t addr, Lsm303Axis *result)
Read the magnet information.
This driver is to read the SHT21 I2C temperature and humidity sensor.
#define AHRS_I2C_SEC_ADDR
AHRS I2C Address.
#define OCTO_PROMIS_I2C_ADDR
Generic PROMiS I2C address.
bool lsm303DAccelCfg(I2C_Device *dev, uint8_t addr, Lsm303DAccCfg config)
Set the accelerometer configuration.
bool lsm303DCfg(I2C_Device *dev, uint8_t addr, Lsm303DCfg config)
Sets the generic device configuration parameters.
static bool pca9548_select(I2C_Device *dev, int addr, int ch)
Select a specific channel on the PCA9548.
This driver interfaces with the PROMiS PMT ASIC.
This driver encapsulates the functionality of the CPLD on the octopus board.
Driver for the ST LSM303Dx Compass sensor.
f32_t hy
Hy in gauss (Float)
static void wdogFeed()
Feed the watchdog.
static bool ocWakeUp(I2C_Device *dev, uint8_t addr)
Wakes up the octopus board, apparently it needs it.
This module implements parsing and formating of strings and integers.
Configures the board-specific peripherals, like I2C, SPI etc...
uint8_t magScale
Magnet scale, use one of LSM303D_MAGSCALEE_*.
int32_t fltToI32(f32_t value, uint32_t multiplier)
This takes a f32_t IEEE 754 single precision floating point, and converts it to a multiplied integer...