int main(void) { static const evhandler_t evhndl_main[] = { extdetail_WKUP_button_handler }; struct EventListener el0; /* * 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(); extdetail_init(); palSetPad(GPIOC, GPIOC_LED); /*! * GPIO Pins for generating pulses at data input detect and data output send. * Used for measuring latency timing of data * * \sa board.h */ palClearPad( TIMEOUTPUT_PORT, TIMEOUTPUT_PIN); palSetPadMode(TIMEOUTPUT_PORT, TIMEOUTPUT_PIN, PAL_MODE_OUTPUT_PUSHPULL); palSetPad( TIMEINPUT_PORT, TIMEINPUT_PIN); palSetPadMode(TIMEINPUT_PORT, TIMEINPUT_PIN, PAL_MODE_OUTPUT_PUSHPULL ); /* * I2C2 I/O pins setup */ palSetPadMode(si_i2c_connections.i2c_sda_port , si_i2c_connections.i2c_sda_pad, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_OSPEED_HIGHEST |PAL_STM32_PUDR_FLOATING ); palSetPadMode(si_i2c_connections.i2c_scl_port, si_i2c_connections.i2c_scl_pad, PAL_MODE_ALTERNATE(4) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_FLOATING); palSetPad(si_i2c_connections.i2c_scl_port, si_i2c_connections.i2c_scl_pad ); static const ShellCommand commands[] = { {"mem", cmd_mem}, {"threads", cmd_threads}, {NULL, NULL} }; usbSerialShellStart(commands); mpu9150_start(&I2CD2); i2cStart(mpu9150_driver.i2c_instance, &si_i2c_config); mpu9150_init(mpu9150_driver.i2c_instance); /* Administrative threads */ chThdCreateStatic(waThread_blinker, sizeof(waThread_blinker), NORMALPRIO, Thread_blinker, NULL); chThdCreateStatic(waThread_indwatchdog, sizeof(waThread_indwatchdog), NORMALPRIO, Thread_indwatchdog, NULL); /* MAC */ /*! * Use a locally administered MAC address second LSbit of MSB of MAC should be 1 * Use unicast address LSbit of MSB of MAC should be 0 */ data_udp_init(); chThdCreateStatic(wa_lwip_thread , sizeof(wa_lwip_thread) , NORMALPRIO + 2, lwip_thread , SENSOR_LWIP); chThdCreateStatic(wa_data_udp_send_thread , sizeof(wa_data_udp_send_thread) , NORMALPRIO , data_udp_send_thread , NULL); /* i2c MPU9150 */ chThdCreateStatic(waThread_mpu9150_int, sizeof(waThread_mpu9150_int) , NORMALPRIO , Thread_mpu9150_int, NULL); /* SPI ADIS */ //chThdCreateStatic(waThread_adis_dio1, sizeof(waThread_adis_dio1), NORMALPRIO, Thread_adis_dio1, NULL); //chThdCreateStatic(waThread_adis_newdata, sizeof(waThread_adis_newdata), NORMALPRIO, Thread_adis_newdata, NULL); /*! Activates the EXT driver 1. */ extStart(&EXTD1, &extcfg); chEvtRegister(&extdetail_wkup_event, &el0, 0); while (TRUE) { chEvtDispatch(evhndl_main, chEvtWaitOneTimeout((eventmask_t)1, MS2ST(500))); } }
/* * Application entry point. */ int main(void) { static const evhandler_t evhndl[] = { WKUP_button_handler }; struct EventListener el0; /* * 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(); /* * Initialize event structures BEFORE using them */ chEvtInit(&wkup_event); /* * Shell manager initialization. */ usbSerialShellStart(commands); // Enable Continuous GPT for 1ms Interval gptStart(&GPTD1, &gpt1cfg); gptStartContinuous(&GPTD1,10000); // Configure pins for Feedback ADC's palSetPadMode(GPIOA, GPIOA_PIN4, PAL_MODE_INPUT_ANALOG); palSetPadMode(GPIOA, GPIOA_PIN5, PAL_MODE_INPUT_ANALOG); // Configure pins for Input ADC's palSetPadMode(GPIOF, GPIOF_PIN6, PAL_MODE_INPUT_ANALOG); palSetPadMode(GPIOF, GPIOF_PIN7, PAL_MODE_INPUT_ANALOG); // Configure pins for LED's // PD3: Vertical Axis LED palSetPadMode(GPIOD, GPIOD_PIN3, PAL_MODE_OUTPUT_PUSHPULL); // PD4: Lateral Axis LED palSetPadMode(GPIOD, GPIOD_PIN4, PAL_MODE_OUTPUT_PUSHPULL); // Configure pins for switches // PD8: Drive Enable Switch palSetPadMode(GPIOD, GPIOD_PIN8, PAL_MODE_INPUT); // PD9: Mode Select Switch palSetPadMode(GPIOD, GPIOD_PIN9, PAL_MODE_INPUT); // Configure pins for long lead GMD Enable/Watchdog // PD5: Enable out to GMD palSetPadMode(GPIOD, GPIOD_PIN5, PAL_MODE_OUTPUT_PUSHPULL); // PD6: Watchdog out to GMD palSetPadMode(GPIOD, GPIOD_PIN6, PAL_MODE_OUTPUT_PUSHPULL); // Configure pins for short lead GMD Enable/Watchdog // PD10: Enable out to GMD palSetPadMode(GPIOD, GPIOD_PIN10, PAL_MODE_OUTPUT_PUSHPULL); // PD11: Watchdog out to GMD palSetPadMode(GPIOD, GPIOD_PIN11, PAL_MODE_OUTPUT_PUSHPULL); // Configure pins for PWM output (D12-D15: TIM4, channel 1-4) palSetPadMode(GPIOD, GPIOD_PIN12, PAL_MODE_ALTERNATE(2)); //U-pole, short lead palSetPadMode(GPIOD, GPIOD_PIN13, PAL_MODE_ALTERNATE(2)); //V-pole, short lead palSetPadMode(GPIOD, GPIOD_PIN14, PAL_MODE_ALTERNATE(2)); //U-pole, long lead palSetPadMode(GPIOD, GPIOD_PIN15, PAL_MODE_ALTERNATE(2)); //V-pole, long lead adcStart(&ADCD1, NULL); adcStart(&ADCD2, NULL); adcStart(&ADCD3, NULL); pwmStart(&PWMD4, &pwmcfg); // Enable TIM4 PWM channel 1-4 with initial DC=0% /* @param[in] pwmp pointer to a @p PWMDriver object * @param[in] channel PWM channel identifier (0...PWM_CHANNELS-1) * @param[in] width PWM pulse width as clock pulses number */ pwmEnableChannel(&PWMD4, 0, 0); pwmEnableChannel(&PWMD4, 1, 0); pwmEnableChannel(&PWMD4, 2, 0); pwmEnableChannel(&PWMD4, 3, 0); // Set axis control gain and limit values // Set Vertical Axis Gains vertAxisStruct.U16PositionPGain = 4; vertAxisStruct.U16PositionIGain = 1; vertAxisStruct.U16PositionDGain = 0; // Set vertical axis limits vertAxisStruct.U16CommandLimit = VERTICAL_COMMAND_LIMIT; vertAxisStruct.U16HighPosnLimit = 5100; vertAxisStruct.U16LowPosnLimit = 2480; // Set Lateral Axis Gains latAxisStruct.U16PositionPGain = 2; latAxisStruct.U16PositionIGain = 0; latAxisStruct.U16PositionDGain = 0; // Set lateral axis limits latAxisStruct.U16CommandLimit = LATERAL_COMMAND_LIMIT; latAxisStruct.U16HighPosnLimit = 5300; latAxisStruct.U16LowPosnLimit = 3100; /* * Activates the serial driver 6 and SDC driver 1 using default * configuration. */ sdStart(&SD6, NULL); /* * Activates the EXT driver 1. * This is for the external interrupt */ extStart(&EXTD1, &extcfg); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and listen for events. */ chEvtRegister(&wkup_event, &el0, 0); while (TRUE) { //Cycle motordrive if timer fails if(U32DelayCount++ > 2500){ motordrive(&GPTD1); } chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500))); } }