examples: Remove all '#undef __KERNEL__' from source code
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
e8b5c47eb8
commit
7da4a34aac
@ -48,7 +48,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <nuttx/spi/spi.h>
|
#include <nuttx/spi/spi.h>
|
||||||
#undef __KERNEL__
|
|
||||||
#include <arch/board/board.h>
|
#include <arch/board/board.h>
|
||||||
#include <nuttx/fs/fs.h>
|
#include <nuttx/fs/fs.h>
|
||||||
#include <nuttx/sensors/adxl372.h>
|
#include <nuttx/sensors/adxl372.h>
|
||||||
@ -136,14 +135,14 @@ static char subtest_prompt(FAR char *prompt)
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/******************************************************************************
|
/****************************************************************************
|
||||||
* Name: adxl372_test
|
* Name: adxl372_test
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* This function is public so that it can be called by board diagnostic
|
* This function is public so that it can be called by board diagnostic
|
||||||
* programs that contain the ADXL372.
|
* programs that contain the ADXL372.
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static int adxl372_test(int is_interactive, FAR char *path)
|
static int adxl372_test(int is_interactive, FAR char *path)
|
||||||
{
|
{
|
||||||
@ -156,10 +155,12 @@ static int adxl372_test(int is_interactive, FAR char *path)
|
|||||||
{
|
{
|
||||||
int16_t d[3];
|
int16_t d[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char tstchars[] =
|
unsigned char tstchars[] =
|
||||||
{
|
{
|
||||||
0x5e, 0xc5, 0x00
|
0x5e, 0xc5, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
char bfr[32] __attribute__((aligned(2))); /* REVISIT: GCC dependent attribute */
|
char bfr[32] __attribute__((aligned(2))); /* REVISIT: GCC dependent attribute */
|
||||||
FAR struct XYZ *pxyz = (FAR struct XYZ *) bfr;
|
FAR struct XYZ *pxyz = (FAR struct XYZ *) bfr;
|
||||||
int rc = PASSED;
|
int rc = PASSED;
|
||||||
@ -175,7 +176,8 @@ static int adxl372_test(int is_interactive, FAR char *path)
|
|||||||
}
|
}
|
||||||
else if (errno == EROFS)
|
else if (errno == EROFS)
|
||||||
{
|
{
|
||||||
printf(CRED "ERROR: Accelerometer mounted as Read Only." CRESET "\n", path, errno);
|
printf(CRED "ERROR: Accelerometer mounted as Read Only." CRESET "\n",
|
||||||
|
path, errno);
|
||||||
rc = RC_OPENRONLY;
|
rc = RC_OPENRONLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,19 +192,19 @@ static int adxl372_test(int is_interactive, FAR char *path)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d"
|
||||||
ADXL372_DEVID_AD, path, errcode);
|
CRESET "\n", ADXL372_DEVID_AD, path, errcode);
|
||||||
rc = RC_SEEKFAIL;
|
rc = RC_SEEKFAIL;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(bfr, 0xAA, sizeof(bfr));
|
memset(bfr, 0xaa, sizeof(bfr));
|
||||||
ret = read(fd, bfr, 4); /* read the sensor id regs */
|
ret = read(fd, bfr, 4); /* read the sensor id regs */
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Failed to read sensor ID from %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Failed to read sensor ID from %s: %d"
|
||||||
path, errcode);
|
CRESET "\n", path, errcode);
|
||||||
rc = RC_READFAIL;
|
rc = RC_READFAIL;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
@ -211,7 +213,8 @@ static int adxl372_test(int is_interactive, FAR char *path)
|
|||||||
bfr[1] != ADXL372_DEVID_MST_VALUE &&
|
bfr[1] != ADXL372_DEVID_MST_VALUE &&
|
||||||
bfr[2] != ADXL372_PARTID_VALUE)
|
bfr[2] != ADXL372_PARTID_VALUE)
|
||||||
{
|
{
|
||||||
printf(CRED "ERROR: Sensor ID is 0x%02X%02X%02X%02X, expected 0x%02X%02X%02Xxx." CRESET "\n",
|
printf(CRED "ERROR: Sensor ID is 0x%02X%02X%02X%02X, "
|
||||||
|
"expected 0x%02X%02X%02Xxx." CRESET "\n",
|
||||||
bfr[0], bfr[1], bfr[2], bfr[3],
|
bfr[0], bfr[1], bfr[2], bfr[3],
|
||||||
ADXL372_DEVID_AD_VALUE, ADXL372_DEVID_MST_VALUE,
|
ADXL372_DEVID_AD_VALUE, ADXL372_DEVID_MST_VALUE,
|
||||||
ADXL372_PARTID_VALUE);
|
ADXL372_PARTID_VALUE);
|
||||||
@ -254,8 +257,8 @@ static int adxl372_test(int is_interactive, FAR char *path)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d"
|
||||||
ADXL372_SCRATCH, path, errcode);
|
CRESET "\n", ADXL372_SCRATCH, path, errcode);
|
||||||
rc = RC_SEEK2FAIL;
|
rc = RC_SEEK2FAIL;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
@ -263,33 +266,33 @@ static int adxl372_test(int is_interactive, FAR char *path)
|
|||||||
rc_step = PASSED;
|
rc_step = PASSED;
|
||||||
for (i = 0; i < sizeof(tstchars); i++)
|
for (i = 0; i < sizeof(tstchars); i++)
|
||||||
{
|
{
|
||||||
memset(bfr, 0xAA, sizeof(bfr));
|
memset(bfr, 0xaa, sizeof(bfr));
|
||||||
bfr[0] = (char)tstchars[i];
|
bfr[0] = (char)tstchars[i];
|
||||||
ret = write(fd, bfr, 1); /* write the scratch register */
|
ret = write(fd, bfr, 1); /* write the scratch register */
|
||||||
if (ret < 0 && rc != RC_OPENRONLY)
|
if (ret < 0 && rc != RC_OPENRONLY)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Write operation failed to %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Write operation failed to %s: %d"
|
||||||
path, errcode);
|
CRESET "\n", path, errcode);
|
||||||
rc = RC_WRITEFAIL;
|
rc = RC_WRITEFAIL;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(bfr, 0xAA, sizeof(bfr));
|
memset(bfr, 0xaa, sizeof(bfr));
|
||||||
ret = read(fd, bfr, 1); /* read the scratch register */
|
ret = read(fd, bfr, 1); /* read the scratch register */
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Read operation failed from %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Read operation failed from %s: %d"
|
||||||
path, errcode);
|
CRESET "\n", path, errcode);
|
||||||
rc = RC_READ2FAIL;
|
rc = RC_READ2FAIL;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bfr[0] != (char)tstchars[i])
|
if (bfr[0] != (char)tstchars[i])
|
||||||
{
|
{
|
||||||
printf(CRED "ERROR: Wrote 0x%02X, read back 0x%02X." CRESET "\n",
|
printf(CRED "ERROR: Wrote 0x%02X, read back 0x%02X."
|
||||||
tstchars[i], bfr[0]);
|
CRESET "\n", tstchars[i], bfr[0]);
|
||||||
rc_step = RC_WRMFAIL;
|
rc_step = RC_WRMFAIL;
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
{
|
{
|
||||||
@ -330,13 +333,13 @@ static int adxl372_test(int is_interactive, FAR char *path)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d"
|
||||||
ADXL372_XDATA_H, path, errcode);
|
CRESET "\n", ADXL372_XDATA_H, path, errcode);
|
||||||
rc = RC_SEEK3FAIL;
|
rc = RC_SEEK3FAIL;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(bfr, 0xAA, sizeof(bfr));
|
memset(bfr, 0xaa, sizeof(bfr));
|
||||||
ret = read(fd, bfr, 6); /* read live accelerometer data */
|
ret = read(fd, bfr, 6); /* read live accelerometer data */
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
@ -372,7 +375,9 @@ quick_exit:
|
|||||||
close(fd);
|
close(fd);
|
||||||
if (rc == PASSED)
|
if (rc == PASSED)
|
||||||
{
|
{
|
||||||
printf(CGREEN "ADXL372 accelerometer diagnostic completed successfully." CRESET "\n");
|
printf(CGREEN
|
||||||
|
"ADXL372 accelerometer diagnostic completed successfully."
|
||||||
|
CRESET "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@ -404,23 +409,23 @@ int main(int argc, FAR char *argv[])
|
|||||||
adxl372_test, /* ADXL372 accelerometer tests */
|
adxl372_test, /* ADXL372 accelerometer tests */
|
||||||
};
|
};
|
||||||
|
|
||||||
FAR char *test_path[sizeof(test_ptr_array) / sizeof(test_ptr_array[0])];
|
FAR char *test_path[ARRAYSIZE(test_ptr_array)];
|
||||||
|
|
||||||
if (argc < 1 || *argv[1] == 0 || *(argv[1] + 1) == 0)
|
if (argc < 1 || *argv[1] == 0 || *(argv[1] + 1) == 0)
|
||||||
{
|
{
|
||||||
goto print_help;
|
goto print_help;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We have at least 1 parameters, and the first parameter has at least two characters. */
|
/* We have at least 1 parameter which has at least two characters. */
|
||||||
|
|
||||||
if (*argv[1] == '-')
|
if (*argv[1] == '-')
|
||||||
{
|
{
|
||||||
flag_present = 1;
|
flag_present = 1;
|
||||||
if (*(argv[1]+1) == 'b')
|
if (*(argv[1] + 1) == 'b')
|
||||||
{
|
{
|
||||||
is_interactive = 0;
|
is_interactive = 0;
|
||||||
}
|
}
|
||||||
else if (*(argv[1]+1) == 'i')
|
else if (*(argv[1] + 1) == 'i')
|
||||||
{
|
{
|
||||||
is_interactive = 1;
|
is_interactive = 1;
|
||||||
}
|
}
|
||||||
@ -500,7 +505,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
printf("Set to batch mode.\n");
|
printf("Set to batch mode.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ui >= (sizeof(test_ptr_array) / sizeof(test_ptr_array[0])))
|
else if (ui >= ARRAYSIZE(test_ptr_array))
|
||||||
{
|
{
|
||||||
printf("Huh?\n");
|
printf("Huh?\n");
|
||||||
}
|
}
|
||||||
@ -521,7 +526,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
{
|
{
|
||||||
printf("ADXL372 sensor diagnostic started in batch mode...\n");
|
printf("ADXL372 sensor diagnostic started in batch mode...\n");
|
||||||
|
|
||||||
for (ui = 0; ui < (sizeof(test_ptr_array) / sizeof(test_ptr_array[0])); ui++)
|
for (ui = 0; ui < ARRAYSIZE(test_ptr_array); ui++)
|
||||||
{
|
{
|
||||||
step_rc = 0;
|
step_rc = 0;
|
||||||
if (test_ptr_array[ui] != 0)
|
if (test_ptr_array[ui] != 0)
|
||||||
@ -548,7 +553,7 @@ print_help:
|
|||||||
printf("adxl372_test [-b | -i] <dev_path>\n");
|
printf("adxl372_test [-b | -i] <dev_path>\n");
|
||||||
printf(" -b = batch mode execution\n");
|
printf(" -b = batch mode execution\n");
|
||||||
printf(" -i = interactive mode execution (default)\n");
|
printf(" -i = interactive mode execution (default)\n");
|
||||||
printf(" <dev_path> = Device path and name for the ADXL372 accelerometer\n");
|
printf(" <dev_path> = Device path for the ADXL372 accelerometer\n");
|
||||||
printf(" Example:\n");
|
printf(" Example:\n");
|
||||||
printf(" adxl372_test -b /dev/adxl372_0\n");
|
printf(" adxl372_test -b /dev/adxl372_0\n");
|
||||||
return RC_INVALPARM;
|
return RC_INVALPARM;
|
||||||
|
@ -48,7 +48,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <nuttx/spi/spi.h>
|
#include <nuttx/spi/spi.h>
|
||||||
#undef __KERNEL__
|
|
||||||
#include <arch/board/board.h>
|
#include <arch/board/board.h>
|
||||||
#include <nuttx/fs/fs.h>
|
#include <nuttx/fs/fs.h>
|
||||||
#include <nuttx/sensors/lsm330.h>
|
#include <nuttx/sensors/lsm330.h>
|
||||||
@ -167,10 +166,12 @@ int lsm330acl_test(int is_interactive, char *path)
|
|||||||
{
|
{
|
||||||
int16_t d[3];
|
int16_t d[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char tstchars[] =
|
unsigned char tstchars[] =
|
||||||
{
|
{
|
||||||
0x5e, 0xc5, 0x00
|
0x5e, 0xc5, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
char bfr[32] __attribute__((aligned(2)));
|
char bfr[32] __attribute__((aligned(2)));
|
||||||
FAR struct XYZ *pxyz = (struct XYZ *)(&bfr[2]); /* Padding and Status byte 1st */
|
FAR struct XYZ *pxyz = (struct XYZ *)(&bfr[2]); /* Padding and Status byte 1st */
|
||||||
int rc = PASSED;
|
int rc = PASSED;
|
||||||
@ -187,7 +188,8 @@ int lsm330acl_test(int is_interactive, char *path)
|
|||||||
}
|
}
|
||||||
else if (errno == EROFS)
|
else if (errno == EROFS)
|
||||||
{
|
{
|
||||||
printf(CRED "ERROR: Accelerometer mounted as Read Only." CRESET "\n", path, errno);
|
printf(CRED "ERROR: Accelerometer mounted as Read Only."
|
||||||
|
CRESET "\n", path, errno);
|
||||||
rc = RC_OPENRONLYA;
|
rc = RC_OPENRONLYA;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,27 +204,27 @@ int lsm330acl_test(int is_interactive, char *path)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d"
|
||||||
LSM330_GYRO_IDREG, path, errcode);
|
CRESET "\n", LSM330_GYRO_IDREG, path, errcode);
|
||||||
rc = RC_SEEKFAILA;
|
rc = RC_SEEKFAILA;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(bfr, 0xAA, sizeof(bfr));
|
memset(bfr, 0xaa, sizeof(bfr));
|
||||||
ret = read(fd, bfr, 1); /* read the sensor id */
|
ret = read(fd, bfr, 1); /* read the sensor id */
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Failed to read sensor ID from %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Failed to read sensor ID from %s: %d"
|
||||||
path, errcode);
|
CRESET "\n", path, errcode);
|
||||||
rc = RC_READFAILA;
|
rc = RC_READFAILA;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bfr[0] != LSM330_ACL_IDREG_VALUE)
|
if (bfr[0] != LSM330_ACL_IDREG_VALUE)
|
||||||
{
|
{
|
||||||
printf(CRED "ERROR: Sensor ID is 0x%02X, expected 0x%02X." CRESET "\n",
|
printf(CRED "ERROR: Sensor ID is 0x%02X, expected 0x%02X."
|
||||||
bfr[0], LSM330_ACL_IDREG_VALUE);
|
CRESET "\n", bfr[0], LSM330_ACL_IDREG_VALUE);
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
{
|
{
|
||||||
rc = RC_IDFAILA;
|
rc = RC_IDFAILA;
|
||||||
@ -253,7 +255,6 @@ int lsm330acl_test(int is_interactive, char *path)
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
||||||
/* write and read a scratch register */
|
/* write and read a scratch register */
|
||||||
|
|
||||||
printf("Writing and reading a scratch register...\n");
|
printf("Writing and reading a scratch register...\n");
|
||||||
@ -261,8 +262,8 @@ int lsm330acl_test(int is_interactive, char *path)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d"
|
||||||
LSM330_ACL_SCRATCH, path, errcode);
|
CRESET "\n", LSM330_ACL_SCRATCH, path, errcode);
|
||||||
rc = RC_SEEK2FAILA;
|
rc = RC_SEEK2FAILA;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
@ -270,33 +271,33 @@ int lsm330acl_test(int is_interactive, char *path)
|
|||||||
rc_step = PASSED;
|
rc_step = PASSED;
|
||||||
for (i = 0; i < sizeof(tstchars); i++)
|
for (i = 0; i < sizeof(tstchars); i++)
|
||||||
{
|
{
|
||||||
memset(bfr, 0xAA, sizeof(bfr));
|
memset(bfr, 0xaa, sizeof(bfr));
|
||||||
bfr[0] = (char)tstchars[i];
|
bfr[0] = (char)tstchars[i];
|
||||||
ret = write(fd, bfr, 1); /* write the scratch register */
|
ret = write(fd, bfr, 1); /* write the scratch register */
|
||||||
if (ret < 0 && rc != RC_OPENRONLYA)
|
if (ret < 0 && rc != RC_OPENRONLYA)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Write operation failed to %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Write operation failed to %s: %d"
|
||||||
path, errcode);
|
CRESET "\n", path, errcode);
|
||||||
rc = RC_WRITEFAILA;
|
rc = RC_WRITEFAILA;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(bfr, 0xAA, sizeof(bfr));
|
memset(bfr, 0xaa, sizeof(bfr));
|
||||||
ret = read(fd, bfr, 1); /* read the scratch register */
|
ret = read(fd, bfr, 1); /* read the scratch register */
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Read operation failed from %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Read operation failed from %s: %d"
|
||||||
path, errcode);
|
CRESET "\n", path, errcode);
|
||||||
rc = RC_READ2FAILA;
|
rc = RC_READ2FAILA;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bfr[0] != (char)tstchars[i])
|
if (bfr[0] != (char)tstchars[i])
|
||||||
{
|
{
|
||||||
printf(CRED "ERROR: Wrote 0x%02X, read back 0x%02X." CRESET "\n",
|
printf(CRED "ERROR: Wrote 0x%02X, read back 0x%02X."
|
||||||
tstchars[i], bfr[0]);
|
CRESET "\n", tstchars[i], bfr[0]);
|
||||||
rc_step = RC_WRMFAILA;
|
rc_step = RC_WRMFAILA;
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
{
|
{
|
||||||
@ -337,13 +338,13 @@ int lsm330acl_test(int is_interactive, char *path)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d"
|
||||||
LSM330_ACL_STATUS, path, errcode);
|
CRESET "\n", LSM330_ACL_STATUS, path, errcode);
|
||||||
rc = RC_SEEK3FAILA;
|
rc = RC_SEEK3FAILA;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(bfr, 0xAA, sizeof(bfr));
|
memset(bfr, 0xaa, sizeof(bfr));
|
||||||
ret = read(fd, &bfr[1], 7); /* read live accelerometer data */
|
ret = read(fd, &bfr[1], 7); /* read live accelerometer data */
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
@ -374,7 +375,8 @@ quick_exit:
|
|||||||
close(fd);
|
close(fd);
|
||||||
if (rc == PASSED)
|
if (rc == PASSED)
|
||||||
{
|
{
|
||||||
printf(CGREEN "LSM330 accelerometer diagnostic completed successfully." CRESET "\n");
|
printf(CGREEN "LSM330 accelerometer diagnostic completed successfully."
|
||||||
|
CRESET "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@ -400,10 +402,12 @@ int lsm330gyro_test(int is_interactive, FAR char *path)
|
|||||||
{
|
{
|
||||||
int16_t d[3];
|
int16_t d[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char tstchars[] =
|
unsigned char tstchars[] =
|
||||||
{
|
{
|
||||||
0x5e, 0xc5, 0x00
|
0x5e, 0xc5, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
char bfr[32] __attribute__((aligned(2)));
|
char bfr[32] __attribute__((aligned(2)));
|
||||||
FAR struct XYZ *pxyz = (struct XYZ *)(&bfr[2]); /* Temp and Status byte 1st */
|
FAR struct XYZ *pxyz = (struct XYZ *)(&bfr[2]); /* Temp and Status byte 1st */
|
||||||
int rc = PASSED;
|
int rc = PASSED;
|
||||||
@ -436,27 +440,27 @@ int lsm330gyro_test(int is_interactive, FAR char *path)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d"
|
||||||
LSM330_GYRO_IDREG, path, errcode);
|
CRESET "\n", LSM330_GYRO_IDREG, path, errcode);
|
||||||
rc = RC_SEEKFAILG;
|
rc = RC_SEEKFAILG;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(bfr, 0xAA, sizeof(bfr));
|
memset(bfr, 0xaa, sizeof(bfr));
|
||||||
ret = read(fd, bfr, 1); /* read the sensor id */
|
ret = read(fd, bfr, 1); /* read the sensor id */
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Failed to read sensor ID from %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Failed to read sensor ID from %s: %d"
|
||||||
path, errcode);
|
CRESET "\n", path, errcode);
|
||||||
rc = RC_READFAILG;
|
rc = RC_READFAILG;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bfr[0] != LSM330_GYRO_IDREG_VALUE)
|
if (bfr[0] != LSM330_GYRO_IDREG_VALUE)
|
||||||
{
|
{
|
||||||
printf(CRED "ERROR: Sensor ID is 0x%02X, expected 0x%02X." CRESET "\n",
|
printf(CRED "ERROR: Sensor ID is 0x%02X, expected 0x%02X."
|
||||||
bfr[0], LSM330_GYRO_IDREG_VALUE);
|
CRESET "\n", bfr[0], LSM330_GYRO_IDREG_VALUE);
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
{
|
{
|
||||||
rc = RC_IDFAILG;
|
rc = RC_IDFAILG;
|
||||||
@ -472,16 +476,16 @@ int lsm330gyro_test(int is_interactive, FAR char *path)
|
|||||||
printf("Sensor ID 0x%02X is correct!\n", bfr[0]);
|
printf("Sensor ID 0x%02X is correct!\n", bfr[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_interactive)
|
if (is_interactive)
|
||||||
{
|
{
|
||||||
ch1 = subtest_prompt("Press 'l' to repeat or enter to continue.\n"
|
ch1 = subtest_prompt("Press 'l' to repeat or enter to continue.\n"
|
||||||
SUB_PROMPT);
|
SUB_PROMPT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ch1 == 'x')
|
if (ch1 == 'x')
|
||||||
{
|
{
|
||||||
goto quick_exit;
|
goto quick_exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (ch1 == 'l');
|
while (ch1 == 'l');
|
||||||
|
|
||||||
@ -494,8 +498,8 @@ int lsm330gyro_test(int is_interactive, FAR char *path)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d"
|
||||||
LSM330_GYRO_SCRATCH, path, errcode);
|
CRESET "\n", LSM330_GYRO_SCRATCH, path, errcode);
|
||||||
rc = RC_SEEK2FAILG;
|
rc = RC_SEEK2FAILG;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
@ -509,8 +513,8 @@ int lsm330gyro_test(int is_interactive, FAR char *path)
|
|||||||
if (ret < 0 && rc != RC_OPENRONLYG)
|
if (ret < 0 && rc != RC_OPENRONLYG)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Write operation failed to %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Write operation failed to %s: %d"
|
||||||
path, errcode);
|
CRESET "\n", path, errcode);
|
||||||
rc = RC_WRITEFAILG;
|
rc = RC_WRITEFAILG;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
@ -520,16 +524,16 @@ int lsm330gyro_test(int is_interactive, FAR char *path)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Read operation failed from %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Read operation failed from %s: %d"
|
||||||
path, errcode);
|
CRESET "\n", path, errcode);
|
||||||
rc = RC_READ2FAILG;
|
rc = RC_READ2FAILG;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bfr[0] != (char)tstchars[i])
|
if (bfr[0] != (char)tstchars[i])
|
||||||
{
|
{
|
||||||
printf(CRED "ERROR: Wrote 0x%02X, read back 0x%02X." CRESET "\n",
|
printf(CRED "ERROR: Wrote 0x%02X, read back 0x%02X."
|
||||||
tstchars[i], bfr[0]);
|
CRESET "\n", tstchars[i], bfr[0]);
|
||||||
rc_step = RC_WRMFAILG;
|
rc_step = RC_WRMFAILG;
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
{
|
{
|
||||||
@ -570,8 +574,8 @@ int lsm330gyro_test(int is_interactive, FAR char *path)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = errno;
|
errcode = errno;
|
||||||
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d" CRESET "\n",
|
printf(CRED "ERROR: Failed to seek to reg 0x%02X in %s: %d"
|
||||||
LSM330_GYRO_OUT_TEMP, path, errcode);
|
CRESET "\n", LSM330_GYRO_OUT_TEMP, path, errcode);
|
||||||
rc = RC_SEEK3FAILG;
|
rc = RC_SEEK3FAILG;
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
@ -588,7 +592,7 @@ int lsm330gyro_test(int is_interactive, FAR char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("LSM330 GYRO = (%6d, %6d, %6d), Temp=%d, Stat=0x%02X\n",
|
printf("LSM330 GYRO = (%6d, %6d, %6d), Temp=%d, Stat=0x%02X\n",
|
||||||
pxyz->d[0], pxyz->d[1], pxyz->d[2], bfr[0]&0x0FF, bfr[1]);
|
pxyz->d[0], pxyz->d[1], pxyz->d[2], bfr[0] & 0xff, bfr[1]);
|
||||||
|
|
||||||
if (is_interactive)
|
if (is_interactive)
|
||||||
{
|
{
|
||||||
@ -608,7 +612,8 @@ quick_exit:
|
|||||||
close(fd);
|
close(fd);
|
||||||
if (rc == PASSED)
|
if (rc == PASSED)
|
||||||
{
|
{
|
||||||
printf(CGREEN "LSM330 gyroscope diagnostic completed successfully." CRESET "\n");
|
printf(CGREEN "LSM330 gyroscope diagnostic completed successfully."
|
||||||
|
CRESET "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@ -635,29 +640,29 @@ int main(int argc, FAR char *argv[])
|
|||||||
|
|
||||||
/* The two arrays below must be synchronized */
|
/* The two arrays below must be synchronized */
|
||||||
|
|
||||||
test_ptr_t test_ptr_array[] = /* Array of test programs */
|
test_ptr_t test_ptr_array[] =
|
||||||
{
|
{
|
||||||
lsm330acl_test, /* LSM330 accelerometer tests */
|
lsm330acl_test, /* LSM330 accelerometer tests */
|
||||||
lsm330gyro_test, /* LSM330 gyroscope tests */
|
lsm330gyro_test, /* LSM330 gyroscope tests */
|
||||||
};
|
};
|
||||||
|
|
||||||
FAR char *test_path[sizeof(test_ptr_array) / sizeof(test_ptr_array[0])];
|
FAR char *test_path[ARRAYSIZE(test_ptr_array)];
|
||||||
|
|
||||||
if (argc < 2 || *argv[1] == 0 || *(argv[1]+1) == 0)
|
if (argc < 2 || *argv[1] == 0 || *(argv[1] + 1) == 0)
|
||||||
{
|
{
|
||||||
goto print_help;
|
goto print_help;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We have at least 2 parameters, and the first parameter has at least two characters. */
|
/* We have at least 2 parameters, the first has at least two characters. */
|
||||||
|
|
||||||
if (*argv[1] == '-')
|
if (*argv[1] == '-')
|
||||||
{
|
{
|
||||||
flag_present = 1;
|
flag_present = 1;
|
||||||
if (*(argv[1]+1) == 'b')
|
if (*(argv[1] + 1) == 'b')
|
||||||
{
|
{
|
||||||
is_interactive = 0;
|
is_interactive = 0;
|
||||||
}
|
}
|
||||||
else if (*(argv[1]+1) == 'i')
|
else if (*(argv[1] + 1) == 'i')
|
||||||
{
|
{
|
||||||
is_interactive = 1;
|
is_interactive = 1;
|
||||||
}
|
}
|
||||||
@ -680,13 +685,15 @@ int main(int argc, FAR char *argv[])
|
|||||||
|
|
||||||
if (stat(test_path[0], &sbuf))
|
if (stat(test_path[0], &sbuf))
|
||||||
{
|
{
|
||||||
printf(CRED "Error: Accelerometer path not found. Path=%s" CRESET "\n", test_path[0]);
|
printf(CRED "Error: Accelerometer path not found. Path=%s" CRESET "\n",
|
||||||
|
test_path[0]);
|
||||||
rc = RC_INVALPATH;
|
rc = RC_INVALPATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(test_path[1], &sbuf))
|
if (stat(test_path[1], &sbuf))
|
||||||
{
|
{
|
||||||
printf(CRED "Error: Gyroscope path not found. Path=%s" CRESET "\n", test_path[1]);
|
printf(CRED "Error: Gyroscope path not found. Path=%s" CRESET "\n",
|
||||||
|
test_path[1]);
|
||||||
rc = RC_INVALPATH;
|
rc = RC_INVALPATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -745,7 +752,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
printf("Set to batch mode.\n");
|
printf("Set to batch mode.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ui >= (sizeof(test_ptr_array) / sizeof(test_ptr_array[0])))
|
else if (ui >= ARRAYSIZE(test_ptr_array))
|
||||||
{
|
{
|
||||||
printf("Huh?\n");
|
printf("Huh?\n");
|
||||||
}
|
}
|
||||||
@ -765,7 +772,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
else /* not interactive mode */
|
else /* not interactive mode */
|
||||||
{
|
{
|
||||||
printf("LSM330 sensor diagnostic started in batch mode...\n");
|
printf("LSM330 sensor diagnostic started in batch mode...\n");
|
||||||
for (ui = 0; ui < (sizeof(test_ptr_array) / sizeof(test_ptr_array[0])); ui++)
|
for (ui = 0; ui < ARRAYSIZE(test_ptr_array); ui++)
|
||||||
{
|
{
|
||||||
step_rc = 0;
|
step_rc = 0;
|
||||||
if (test_ptr_array[ui] != 0)
|
if (test_ptr_array[ui] != 0)
|
||||||
@ -792,8 +799,8 @@ print_help:
|
|||||||
printf("lsm330spi_test [-b | -i] <dev_path_acl> <dev_path_gyro>\n");
|
printf("lsm330spi_test [-b | -i] <dev_path_acl> <dev_path_gyro>\n");
|
||||||
printf(" -b = batch mode execution\n");
|
printf(" -b = batch mode execution\n");
|
||||||
printf(" -i = interactive mode execution (default)\n");
|
printf(" -i = interactive mode execution (default)\n");
|
||||||
printf(" <dev_path_acl> = Device path and name for the LSM330 accelerometer\n");
|
printf(" <dev_path_acl> = Device path for the LSM330 accelerometer\n");
|
||||||
printf(" <dev_path_gyro> = Device path and name for the LSM330 gyroscope\n");
|
printf(" <dev_path_gyro> = Device path for the LSM330 gyroscope\n");
|
||||||
printf(" Example:\n");
|
printf(" Example:\n");
|
||||||
printf(" lsm330spi_test -b /dev/lsm330acl0 /dev/lsm330gyro0\n");
|
printf(" lsm330spi_test -b /dev/lsm330acl0 /dev/lsm330gyro0\n");
|
||||||
return RC_INVALPARM;
|
return RC_INVALPARM;
|
||||||
|
Loading…
Reference in New Issue
Block a user