/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Initializes a serial-over-USB CDC driver. */ sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); /* * Activates the USB driver and then the USB bus pull-up on D+. * Note, a delay is inserted in order to not have to disconnect the cable * after a reset. */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1, NULL); /* * LSM303DLHC Object Initialization */ lsm303dlhcObjectInit(&LSM303DLHCD1); /* * Activates the LSM303DLHC driver. */ lsm303dlhcStart(&LSM303DLHCD1, &lsm303dlhccfg); /* * Shell manager initialization. */ shellInit(); while(TRUE) { if (SDU1.config->usbp->state == USB_ACTIVE) { thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, "shell", NORMALPRIO + 1, shellThread, (void *)&shell_cfg1); chThdWait(shelltp); /* Waiting termination. */ } chThdSleepMilliseconds(1000); } lsm303dlhcStop(&LSM303DLHCD1); return 0; }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* Initializes a serial-over-USB CDC driver.*/ sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); /* * Activates the USB driver and then the USB bus pull-up on D+. * Note, a delay is inserted in order to not have to disconnect the cable * after a reset. */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* Creates the blinker thread.*/ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1, NULL); /* LSM303DLHC Object Initialization.*/ lsm303dlhcObjectInit(&LSM303DLHCD1); /* Activates the LSM303DLHC driver.*/ lsm303dlhcStart(&LSM303DLHCD1, &lsm303dlhccfg); /* Normal main() thread activity, printing MEMS data on the SDU1.*/ while (true) { lsm303dlhcAccelerometerReadRaw(&LSM303DLHCD1, accraw); chprintf(chp, "LSM303DLHC Accelerometer raw data...\r\n"); for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++) { chprintf(chp, "%c-axis: %d\r\n", axisID[i], accraw[i]); } lsm303dlhcCompassReadRaw(&LSM303DLHCD1, compraw); chprintf(chp, "LSM303DLHC Compass raw data...\r\n"); for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) { chprintf(chp, "%c-axis: %d\r\n", axisID[i], compraw[i]); } lsm303dlhcAccelerometerReadCooked(&LSM303DLHCD1, acccooked); chprintf(chp, "LSM303DLHC Accelerometer cooked data...\r\n"); for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++) { chprintf(chp, "%c-axis: %.3f\r\n", axisID[i], acccooked[i]); } lsm303dlhcCompassReadCooked(&LSM303DLHCD1, compcooked); chprintf(chp, "LSM303DLHC Compass cooked data...\r\n"); for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) { chprintf(chp, "%c-axis: %.3f\r\n", axisID[i], compcooked[i]); } chThdSleepMilliseconds(100); cls(chp); } lsm303dlhcStop(&LSM303DLHCD1); }