Beispiel #1
0
void ExtiInitLocal(void){
  chSysLock();
  starttacho_vt();
  chSysUnlock();

#if !GYRO_UPDATE_PERIOD_HARDCODED
  tmObjectInit(&itg3200_tmup);
#endif /* !GYRO_UPDATE_PERIOD_HARDCODED */

  tmObjectInit(&tacho_tmup);

  extStart(&EXTD1, &extcfg);
}
Beispiel #2
0
//-----------------------------------------------------------------------------
int
kuroBoxInit(void)
{
    kbg_setLED1(1);
    kbg_setLED2(1);
    kbg_setLED3(1);

    // Serial
    sdStart(&SD1, &serial1_cfg);
    sdStart(&SD2, &serial2_cfg);

    // start the SPI bus, just use the LCD's SPI config since
    // it's shared with the eeprom
    spiStart(&SPID1, &lcd_cfg.spicfg);
    memset(lcd_buffer, 0, sizeof(lcd_buffer));
    st7565Start(&ST7565D1, &lcd_cfg, &SPID1, lcd_buffer);

    // EEPROM
    spiEepromStart(&spiEepromD1, &eeprom_cfg, &SPID1);

    // this turns on Layer 1 power, this turns on the mosfets controlling the
    // VCC rail. After this, we can start GPS, VectorNav and altimeter
    kbg_setL1PowerOn();

    // wait for it to stabilise, poweron devices, and let them start before continuing
    chThdSleepMilliseconds(500);

    // set initial button state.
    kuroBoxButtonsInit();

    gptStart(&GPTD2, &one_sec_cfg);

    // indicate we're ready
    chThdSleepMilliseconds(100);
    kbg_setLED1(0);
    kbg_setLED2(0);
    kbg_setLED3(0);

    // all external interrupts, all the system should now be ready for it
    extStart(&EXTD1, &extcfg);

    return KB_OK;
}
Beispiel #3
0
void sc_extint_set_isr_cb(ioportid_t port,
                          uint8_t pin,
                          SC_EXTINT_EDGE mode,
                          extcallback_t cb)

{
  uint8_t need_start = 1;
  uint8_t i;
  uint32_t ext_mode;
  EXTChannelConfig cfg;

  chDbgAssert(pin < EXT_MAX_CHANNELS , "EXT pin number outside range");
  chDbgAssert(mode == EXT_CH_MODE_RISING_EDGE ||
              mode == EXT_CH_MODE_FALLING_EDGE ||
              mode == EXT_CH_MODE_BOTH_EDGES, "Invalid edge mode");

  chMtxLock(&cfg_mtx);

  chDbgAssert(extcfg.channels[pin].cb == NULL,
              "EXT pin already registered");

  for (i = 0; i < EXT_MAX_CHANNELS; ++i) {
    if (extcfg.channels[pin].cb != NULL) {
      need_start = 0;
      break;
    }
  }

  ext_mode = (mode | EXT_CH_MODE_AUTOSTART | _get_ext_from_port(port));

  cfg.cb = cb;
  cfg.mode = ext_mode;

  if (need_start) {
    extStart(&EXTD1, &extcfg);
  }

  extSetChannelMode(&EXTD1, pin, &cfg);

  chMtxUnlock(&cfg_mtx);
}
Beispiel #4
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();

  /*
   * Activates the EXT driver 1.
   */
  extStart(&EXTD1, &extcfg);

  while (TRUE) {
    chThdSleepMilliseconds(500);
  }
}
Beispiel #5
0
msg_t madgwick_node(void *arg) {
	r2p::Node node("madgwick");
	r2p::Publisher<r2p::TiltMsg> tilt_pub;
	attitude_t attitude_data;
	systime_t time;

	(void) arg;
	chRegSetThreadName("madgwick");

	i2cStart(&I2C_DRIVER, &i2c1cfg);
	spiStart(&SPI_DRIVER, &spi1cfg);
	extStart(&EXTD1, &extcfg);

	gyroRun(&SPI_DRIVER, NORMALPRIO);
	accRun(&I2C_DRIVER, NORMALPRIO);
//	magRun(&I2C_DRIVER, NORMALPRIO);

	node.advertise(tilt_pub, "tilt");

	time = chTimeNow();

	for (;;) {
		MadgwickAHRSupdateIMU((gyro_data.x / 57.143) * 3.141592 / 180.0, (gyro_data.y / 57.143) * 3.141592 / 180.0,
				(gyro_data.z / 57.143) * 3.141592 / 180.0, acc_data.x / 1000.0, acc_data.y / 1000.0,
				acc_data.z / 980.0);
		getMadAttitude(&attitude_data);

		r2p::TiltMsg *msgp;
		if (tilt_pub.alloc(msgp)) {
			msgp->angle = (-attitude_data.roll * 57.29578) - 2.35; // basketbot offset
			tilt_pub.publish(*msgp);
		}

		time += MS2ST(20);
		chThdSleepUntil(time);
	}
	return CH_SUCCESS;
}
Beispiel #6
0
/*
 * 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)));
	}
}
/*
 * 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();

	/*
	 * Activates the serial driver 1 using the driver default configuration.
	 */
	sdStart(&SERIAL_DRIVER, NULL);

	/*
	 * Activates the EXT driver.
	 */
	extStart(&EXTD1, &extcfg);

	/*
	 * Activates the I2C driver.
	 */
	i2cStart(&I2C_DRIVER, &i2c1cfg);

	/*
	 * Activates the SPI driver.
	 */
	spiStart(&SPI_DRIVER, &spi1cfg);

	/*
	 * Activates the RTCAN driver.
	 */
	rtcanInit();
	rtcanStart(&RTCAND1, &rtcan_config);

	/*
	 * Creates the blinker thread.
	 */
	chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

	chThdSleepMilliseconds(100);

	/*
	 * Creates the sensor threads.
	 */
	gyrotp = gyroRun(&SPI_DRIVER, NORMALPRIO);
	acctp = accRun(&I2C_DRIVER, NORMALPRIO);
	magtp = magRun(&I2C_DRIVER, NORMALPRIO);

	/*
	 * Creates the publisher threads.
	 */
	chThdCreateFromHeap(NULL, WA_SIZE_2K, NORMALPRIO + 1, PublisherRawThread,
			NULL);

	chThdSleepMilliseconds(100);

	remote_sub("IMURaw");

	/*
	 * Normal main() thread activity, in this demo it does nothing except
	 * sleeping in a loop and check the button state.
	 */
	while (TRUE) {
		chThdSleepMilliseconds(200);
	}
}
void WorkerThreadPool::start()
{
    extStart(threadInit.connHandlerFactory,threadInit.reqHandlerfactory,threadInit.cleanup);
}
Beispiel #9
0
void StartEXT(){
extStart(&EXTD1, &extcfg);
}
Beispiel #10
0
//-----------------------------------------------------------------------------
int
kuroBoxInit(void)
{
	halInit();
	chSysInit();

	PWR->CSR &= ~PWR_CSR_EWUP;

	kbg_setLED1(1);
	kbg_setLED2(1);
	kbg_setLED3(1);

	// Serial
	kuroBoxSerialInit(NULL, NULL);

	// start the SPI bus, just use the LCD's SPI config since
	// it's shared with the eeprom
	spiStart(&SPID1, &lcd_cfg.spicfg);
	memset(lcd_buffer, 0, sizeof(lcd_buffer));
	st7565Start(&ST7565D1, &lcd_cfg, &SPID1, lcd_buffer);
	
	// EEPROM
	spiEepromStart(&spiEepromD1, &eeprom_cfg, &SPID1);
	
	// SDIO 
	sdcStart(&SDCD1, &sdio_cfg);
	
	// just blink to indicate we haven't crashed
#ifdef HAVE_BLINK_THREAD
	blinkerThread = chThdCreateStatic(waBlinker, sizeof(waBlinker), NORMALPRIO, thBlinker, NULL);
#endif // HAVE_BLINK_THREAD

	// read config goes here
	// @TODO: add config reading from eeprom
	
	// ADC to monitor voltage levels.
	// start all the ADC stuff!
	kuroBoxADCInit();
	
	// init the screen, this will spawn a thread to keep it updated
	kuroBoxScreenInit();

	// LTC's, interrupt driven, very quick now
	// Note, this module must be init'd after the screen
	kuroBoxTimeInit();

	// the actual logging thread
	kuroBoxWriterInit();

	// this turns on Layer 1 power, this turns on the mosfets controlling the
	// VCC rail. After this, we can start GPS, VectorNav and altimeter
	kbg_setL1PowerOn();

	// wait for it to stabilise, poweron devices, and let them start before continuing
	chThdSleepMilliseconds(500);

	// gps uart
	kuroBoxGPSInit(&SD6);

	VND1.spip = &SPID2;
	VND1.gpdp = &GPTD14;
	kuroBoxVectorNavInit(&VND1, NULL); // use the defaults

	// start I2C here, since it's a shared bus
	i2cStart(&I2CD2, &i2cfg2);

	// and the altimeter, also spawns a thread.
	kuroBoxAltimeterInit();

	// init the menu structure, and thread, if needed
	kuroBoxMenuInit();

	// set initial button state, AFTER menus!
	kuroBoxButtonsInit();

	// read all configs from bksram and load them up thoughout the system
	kuroBoxConfigInit();

	// Feature "A" - just a test feature that sends updates over serial
	kuroBoxExternalDisplayInit();

	// indicate we're ready
	chprintf(DEBG, "%s\n\r\n\r", BOARD_NAME);
	chThdSleepMilliseconds(50);
	kbg_setLED1(0);
	kbg_setLED2(0);
	kbg_setLED3(0);

	// all external interrupts, all the system should now be ready for it
	extStart(&EXTD1, &extcfg);

	return KB_OK; 
}
Beispiel #11
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();

  //Start external interrupt subsystem
  extStart(&EXTD1, &extcfg);

  //Disable 5V_ENABLE for startup sequence
  palClearPad(GPIOA, GPIO_5V_ENABLE);

  //Configure pin for 5V Enable
  palSetPadMode(GPIOA, GPIO_5V_ENABLE, PAL_MODE_OUTPUT_PUSHPULL);       //Red Team LED

  //Configure Default Team Input Pins
  palSetPadMode(GPIOA, GPIO_TEAMID0, PAL_MODE_INPUT_PULLDOWN);
  palSetPadMode(GPIOA, GPIO_TEAMID1, PAL_MODE_INPUT_PULLDOWN);

  //Configure pins for TeamID LED's
  palSetPadMode(GPIOA, GPIO_RED_LED, PAL_MODE_OUTPUT_PUSHPULL);         //Red Team LED
  palSetPadMode(GPIOA, GPIO_GREEN_LED, PAL_MODE_OUTPUT_PUSHPULL);	//Green Team LED
  palSetPadMode(GPIOA, GPIO_BLUE_LED, PAL_MODE_OUTPUT_PUSHPULL);	//Blue Team LED

  //Configure pins for PLL's
  palSetPadMode(GPIOB, GPIO_RED_PLL, PAL_MODE_INPUT);         //Red Team PLL
  palSetPadMode(GPIOB, GPIO_GREEN_PLL, PAL_MODE_INPUT);       //Green Team PLL
  palSetPadMode(GPIOB, GPIO_BLUE_PLL, PAL_MODE_INPUT);        //Blue Team PLL

  // Configure pin for PWM output (A1: TIM2, channel 4)
  palSetPadMode(GPIOA, GPIO_MOD_FREQ, PAL_MODE_ALTERNATE(2));	//Modulation Freq Out
  //Configure pin for RX Enable
  palSetPadMode(GPIOA, GPIO_RX, PAL_MODE_OUTPUT_PUSHPULL);

  //Read Default Team Pins, set DefaultTeam
  DefaultTeam = (palReadPad(GPIOA, GPIO_TEAMID0) + palReadPad(GPIOA, GPIO_TEAMID1));
  CurrentTeam = DefaultTeam;

  //Set Initial Team
  if(CurrentTeam == REDTEAM) {
    pwmStart(&PWMD2, &pwmcfgRed);
    Red_Team();
  }
  else if(CurrentTeam == GREENTEAM) {
    pwmStart(&PWMD2, &pwmcfgGreen);
    Green_Team();
  }
  else {        //Blue Team
    pwmStart(&PWMD2, &pwmcfgBlue);
    Blue_Team();
  }

  //Enable 5V_ENABLE
  palSetPad(GPIOA, GPIO_5V_ENABLE);

  //Enable GPT's
  gptStart(&GPTD1, &gpt1cfg);
  gptStart(&GPTD3, &gpt3cfg);

  //Idle loop. Wait for interrupts.
  while (TRUE)
    chThdSleepMilliseconds(500);
}
Beispiel #12
0
/*
 * Application entry point.
 */
int main(void) {
  Thread *shelltp = NULL;

  /*
   * 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();

  /*
   * Activates the serial driver 1 using the driver default configuration.
   */
  sdStart(&SERIAL_DRIVER, NULL);

  /*
   * Shell manager initialization.
   */
  shellInit();

  /*
   * Activates the EXT driver.
   */
  extStart(&EXTD1, &extcfg);

  /*
   * Activates the I2C driver.
   */
  i2cStart(&I2C_DRIVER, &i2c1cfg);

  /*
   * Activates the SPI driver.
   */
  spiStart(&SPI_DRIVER, &spi1cfg);

  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  chThdSleepMilliseconds(200);

  if (gyrotp == NULL)
    gyrotp = gyroRun(&SPI_DRIVER, NORMALPRIO);
  if (acctp == NULL)
    acctp = accRun(&I2C_DRIVER, NORMALPRIO);
  if (magtp == NULL)
    magtp = magRun(&I2C_DRIVER, NORMALPRIO);

  /*
   * Normal main() thread activity, in this demo it does nothing except
   * sleeping in a loop and check the button state.
   */
  while (TRUE) {
    if (!shelltp)
      shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO - 1);
    else if (chThdTerminated(shelltp)) {
      chThdRelease(shelltp);
      shelltp = NULL;
    }
    chThdSleepMilliseconds(200);
  }
}
Beispiel #13
0
/*All the pin assignments and the initialization of the Input
 *Capture is done in this function.
 */
void initInput(void) {
  extStart(&EXTD1, &extcfg) ;
}
Beispiel #14
0
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();

    // enable usb
    usbstartup();

    //enable debug print thread
    vInitDebugPrint((BaseSequentialStream *) &SDU1);

    palClearPad(GPIOA, GPIOA_PIN0);
    chThdSleepMilliseconds(20000);
    palSetPad(GPIOA, GPIOA_PIN0);
    //enable interrupt
    extStart(&EXTD1, &extcfg);

    // start thread to be activated by interrupt.
    start_thd();

    bool sender = false;
    if(palReadPad(GPIOC, GPIOC_PIN5) == PAL_HIGH){
        sender = true;
    }

    uint8_t rxbuf[4];
    dw1000_conf_t config;
    if(sender){
        config.shortaddr.u16 = 0xFA77;
    }
    else{
        config.shortaddr.u16 = 0xBEEF;
        //config.shortaddr.u16 = 0xBEFF;
    }


    dw.state = UNINITIALIZED;
    dw1000_euid_t euid;
    euid.u64 = 1;

    dw1000_generate_recommended_conf(
            &default_dw1000_hal,
            DW1000_DATARATE_850,
            DW1000_CHANNEL_2,
            euid,
            &config);

    dw.config = &config;

    dw1000_init(&dw);

    uint32_t zero = \
                    DW1000_EVENT_TXFRS | \
                    DW1000_EVENT_RXDFR | \
                    DW1000_EVENT_AFFREJ | \
                    DW1000_EVENT_RXFCE | \
                    DW1000_EVENT_RXPHE | \
                    DW1000_EVENT_LDEERR | \
                    DW1000_EVENT_RXRFSL | \
                    DW1000_EVENT_RXSFDTO | \
                    DW1000_EVENT_HPDWARN | \
                    DW1000_EVENT_TXBERR \
                    ;
    dw1000_set_interrupts(&default_dw1000_hal,zero);

    dw1000_receive(&dw);

    if(sender){
        set_ranging_callback(calibration_cb);
        palSetPad(GPIOC, GPIOC_PIN8);
    }
    else{
        palClearPad(GPIOC, GPIOC_PIN8);
    }

    int per_loop =0;
    uint8_t sleep =20;
    while(1)
    {
        //palTogglePad(GPIOC, GPIOC_PIN8);
        chThdSleepMilliseconds(sleep);
        dw1000_shortaddr_t dst;

        if(sender){
            dst.u16 = 0xBEEF;
            request_ranging(&dw, dst);
            chThdSleepMilliseconds(sleep);
            dst.u16 =0xBEFF;
            request_ranging(&dw, dst);
        }

        dw1000_get_event_counters(&default_dw1000_hal, counter);
        if (per_loop == 100){
            per_loop = 0;
           // printf("    PHR_ERRORS:    %u \n\r", counter[PHR_ERRORS]);
           // printf("    RSD_ERRORS:    %u \n\r", counter[RSD_ERRORS]);
           // printf("    FCS_GOOD:      %u \n\r", counter[FCS_GOOD]);
           // printf("    FCS_ERRORS:    %u \n\r", counter[FCS_ERRORS]);
           // printf("    FILTER_REJ:    %u \n\r", counter[FILTER_REJECTIONS]);
           // printf("    RX_OVERRUNS:   %u \n\r", counter[RX_OVERRUNS]);
           // printf("    SFD_TO:        %u \n\r", counter[SFD_TIMEOUTS]);
           // printf("    PREAMBLE_TO:   %u \n\r", counter[PREAMBLE_TIMEOUTS]);
           // printf("    RX_TIMEOUTS:   %u \n\r", counter[RX_TIMEOUTS]);
           // printf("    TX_SENT:       %u \n\r", counter[TX_SENT]);
           // printf("    HPWARN:        %u \n\r", counter[HALF_PERIOD_WARNINGS]);
           // printf("    TX_PWRUP_WARN: %u \n\r", counter[TX_PWRUP_WARNINGS]);
        }
        per_loop++;


    }

}
Beispiel #15
0
int main(void) {
	static Thread            *shelltp       = NULL;
	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);
	palSetPad(GPIOA, GPIOA_SPI1_SCK);
	palSetPad(GPIOA, GPIOA_SPI1_NSS);

	/*
	 * SPI1 I/O pins setup.
	 */
	palSetPadMode(adis_connections.spi_sck_port, adis_connections.spi_sck_pad,
			PAL_MODE_ALTERNATE(5) |
			PAL_STM32_OSPEED_HIGHEST);
	palSetPadMode(adis_connections.spi_miso_port, adis_connections.spi_miso_pad,
			PAL_MODE_ALTERNATE(5) |
			PAL_STM32_OSPEED_HIGHEST| PAL_STM32_PUDR_FLOATING);
	palSetPadMode(adis_connections.spi_mosi_port, adis_connections.spi_mosi_pad,
			PAL_MODE_ALTERNATE(5) |
			PAL_STM32_OSPEED_HIGHEST );
	palSetPadMode(adis_connections.spi_cs_port, adis_connections.spi_cs_pad,
			PAL_MODE_OUTPUT_PUSHPULL |
			PAL_STM32_OSPEED_HIGHEST);

	palSetPad(GPIOA, GPIOA_SPI1_SCK);
	palSetPad(GPIOA, GPIOA_SPI1_NSS);

	/*!
	 * Initializes a serial-over-USB CDC driver.
	 */
	sduObjectInit(&SDU_PSAS);
	sduStart(&SDU_PSAS, &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(1000);
	usbStart(serusbcfg.usbp, &usbcfg);
	usbConnectBus(serusbcfg.usbp);

	shellInit();

	iwdg_begin();

	/*!
	 * Activates the serial driver 6 and SDC driver 1 using default
	 * configuration.
	 */
	sdStart(&SD6, NULL);

	spiStart(&SPID1, &adis_spicfg);       /* Set transfer parameters.  */

	chThdSleepMilliseconds(300);

	adis_init();
	adis_reset();

	/*! Activates the EXT driver 1. */
	extStart(&EXTD1, &extcfg);

	chThdCreateStatic(waThread_blinker,      sizeof(waThread_blinker),      NORMALPRIO, Thread_blinker,      NULL);
	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);
	chThdCreateStatic(waThread_indwatchdog,  sizeof(waThread_indwatchdog),  NORMALPRIO, Thread_indwatchdog,  NULL);

	chEvtRegister(&extdetail_wkup_event, &el0, 0);
	while (TRUE) {
		if (!shelltp && (SDU_PSAS.config->usbp->state == USB_ACTIVE))
			shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
		else if (chThdTerminated(shelltp)) {
			chThdRelease(shelltp);    /* Recovers memory of the previous shell.   */
			shelltp = NULL;           /* Triggers spawning of a new shell.        */
		}
		chEvtDispatch(evhndl_main, chEvtWaitOneTimeout((eventmask_t)1, MS2ST(500)));
	}
}
Beispiel #16
0
/*
 * Application entry point.
 */
int main(void) {

  size_t start = 1100;
  size_t end = 1150;
  volatile int32_t adc_its = 0;
  volatile int32_t spi_its = 0;
  volatile int32_t uart_its = 0;
  volatile int32_t adc_its_idle = 0;
  volatile int32_t spi_its_idle = 0;
  volatile int32_t uart_its_idle = 0;
  volatile uint32_t idle_thread_cnt = 0;

  #if EMCNAND_USE_KILL_TEST
  size_t kill = 8000;
  #endif

  /*
   * 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();

  emcStart(&EMCD1, &emccfg);
#if !STM32_EMC_EMCNAND_USE_FSMC_INT
  extStart(&EXTD1, &extcfg);
#endif
  emcnandStart(&EMCNANDD1, &nandcfg);

  chThdSleepMilliseconds(4000);

  chThdCreateStatic(fsmcIdleThreadWA,
        sizeof(fsmcIdleThreadWA),
        NORMALPRIO - 20,
        fsmcIdleThread,
        NULL);

  nand_wp_release();

  dma_storm_adc_start();
  dma_storm_uart_start();
  dma_storm_spi_start();
  T = chVTGetSystemTimeX();
  general_test(&EMCNANDD1, start, end, 1);
  T = chVTGetSystemTimeX() - T;
  adc_its = dma_storm_adc_stop();
  uart_its = dma_storm_uart_stop();
  spi_its = dma_storm_spi_stop();
  chSysLock();
  idle_thread_cnt = IdleCnt;
  IdleCnt = 0;
  chSysUnlock();

  dma_storm_adc_start();
  dma_storm_uart_start();
  dma_storm_spi_start();
  chThdSleep(T);
  adc_its_idle = dma_storm_adc_stop();
  uart_its_idle = dma_storm_uart_stop();
  spi_its_idle = dma_storm_spi_stop();

  osalDbgCheck(idle_thread_cnt > (IdleCnt / 4));
  osalDbgCheck(abs(adc_its - adc_its_idle)   < (adc_its_idle  / 20));
  osalDbgCheck(abs(uart_its - uart_its_idle) < (uart_its_idle / 20));
  osalDbgCheck(abs(spi_its - spi_its_idle)   < (spi_its_idle  / 10));

  ecc_test(&EMCNANDD1, end);

#if EMCNAND_USE_KILL_TEST
  kill_block(&EMCNANDD1, kill);
#endif

  nand_wp_assert();

  /*
   * Normal main() thread activity, in this demo it does nothing.
   */
  while (TRUE) {
    chThdSleepMilliseconds(500);
  }
}
Beispiel #17
0
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+.
     * 
     */
    usbDisconnectBus(serusbcfg.usbp);
    chThdSleepMilliseconds(500);
    usbStart(serusbcfg.usbp, &usbcfg);
    usbConnectBus(serusbcfg.usbp);

    /*
     *
     * Start I2C and set up sensors
     * 
     */
    i2cStart(&I2CD2, &i2cfg2);

    /* Initialize Accelerometer and Gyroscope */
    if (MPU6050Init(&mpu6050cfg) != MSG_OK)
        panic("MPU6050 init failed"); /* Initialization failed */

    /* Initialize Magnetometer */
    if (HMC5983Init(&hmc5983cfg) != MSG_OK)
        panic("HMC5983 init failed"); /* Initialization failed */

    /* Initialize Barometer */
    /* TODO: Add barometer code */

    /* Initialize sensor readout */
    if (SensorReadInit(&mpu6050cfg, &hmc5983cfg,
                       &mpu6050cal, &hmc5983cal) != MSG_OK)
        panic("Sensor Read init failed"); /* Initialization failed */

    /*
     *
     * Start the external interrupts
     *
     */
    extStart(&EXTD1, &extcfg);

    /*
     *
     * Initialize the RC Outputs
     *
     */
    if (RCOutputInit(&rcoutputcfg) != MSG_OK)
        panic("RC output init failed"); /* Initialization failed */

    /*
     *
     * Start RC Inputs
     *
     */
    eicuInit();
    eicuStart(&EICUD9, &rcinputcfg);
    eicuEnable(&EICUD9);

    /*
     *
     * Start test thread
     * 
     */
    chThdCreateStatic(  waThreadTestEvents,
                        sizeof(waThreadTestEvents),
                        HIGHPRIO,
                        ThreadTestEvents,
                        NULL);

    while(1)
    {
        chThdSleepMilliseconds(100);
        if (isUSBActive() == true)
            chprintf((BaseSequentialStream *)&SDU1, "Input width: %u\r\n", ic_test);
    }
}
Beispiel #18
0
void buttonInit(){

    extStart(&EXTD1, &extcfg);
    chThdCreateStatic(waThreadButton, sizeof(waThreadButton),
                    NORMALPRIO + 10, ThreadButton, NULL);
}
void setup_ExternalInterrupt()
{
	extStart(&EXTD1, &extcfg); 
}
Beispiel #20
0
void ExtiPnc::start(void){
  extStart(&EXTD1, &extcfg);
  ready = true;
}
Beispiel #21
0
/*===========================================================================*/
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();


	/*
	 * kruciální řádek protože pokud se to zapne bez debugru tak je tam
	 * jenom bordel a když se to pak srovnává s NULL tak se to cely
	 * vymrdá a skoči do unhandled exception
	 */
	uint8_t i;
	for (i = 0 ; i< 60 ; i++)
		logic_pointery[i] = NULL;

	//test_logic_fill();

	chThdSleepMilliseconds(100);

	/*
	 * Activates the USB driver and then the USB bus pull-up on D+.
	 */
	usb_user_init();

	/*
	 * Shell manager initialization.
	 */
	shellInit();

	/*
	 * Init tft display ssd1289 and gui
	 */
	gui_init();


	/**
	 * @brief start the whole bad thing
	 */
	logic_init();

	/*
	 * start external interrupt system
	 */
	extStart(&EXTD1, &extcfg);

	/*
	 * start wah thread
	 */
	wah_init();

	/*
	 * Normal main() thread activity, in this demo it does nothing except
	 * sleeping in a loop and check the button state.
	 */

	EventListener el;
	chEvtRegister(&event_touch, &el, TOUCH_PUSH);

#ifdef I2C_TEST
	i2c_test();
#endif

	gui_thread();

	while(TRUE);
}
Beispiel #22
0
//fixme: This is kind of a cheesey way of doing this, but doing it better
//       will probably only happen when extAddCallback's todo is fixed.
void extUtilsStart(void){
    extStart(&EXTD1, &extconfig);
}
Beispiel #23
0
static bool init_gpio(t_hydra_console *con)
{
	/* PA7 as Input connected to TRF7970A MOD Pin */
	// palSetPadMode(GPIOA, 7, PAL_MODE_INPUT);

	/* Configure NFC/TRF7970A in SPI mode with Chip Select */
	/* TRF7970A IO0 (To set to "0" for SPI) */
	palClearPad(GPIOA, 3);
	palSetPadMode(GPIOA, 3, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_MID1);

	/* TRF7970A IO1 (To set to "1" for SPI) */
	palSetPad(GPIOA, 2);
	palSetPadMode(GPIOA, 2, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_MID1);

	/* TRF7970A IO2 (To set to "1" for SPI) */
	palSetPad(GPIOC, 0);
	palSetPadMode(GPIOC, 0, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_MID1);

	/*
	 * Initializes the SPI driver 1. The SPI1 signals are routed as follows:
	 * Shall be configured as SPI Slave for TRF7970A NFC data sampling on MOD pin.
	 * NSS. (Not used use Software).
	 * PA5 - SCK.(AF5)  => Connected to TRF7970A SYS_CLK pin
	 * PA6 - MISO.(AF5) (Not Used)
	 * PA7 - MOSI.(AF5) => Connected to TRF7970A MOD pin
	 */
	/* spiStart() is done in sniffer see sniffer.c */
	/* SCK.     */
	palSetPadMode(GPIOA, 5, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_MID1);
	/* MISO. Not used/Not connected */
	palSetPadMode(GPIOA, 6, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_MID1);
	/* MOSI. connected to TRF7970A MOD Pin */
	palSetPadMode(GPIOA, 7, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_MID1);

	/*
	 * Initializes the SPI driver 2. The SPI2 signals are routed as follow:
	 * PC1 - NSS.
	 * PB10 - SCK.
	 * PC2 - MISO.
	 * PC3 - MOSI.
	 * Used for communication with TRF7970A in SPI mode with NSS.
	 */
	mode_con1.proto.dev_gpio_pull = MODE_CONFIG_DEV_GPIO_NOPULL;
	mode_con1.proto.dev_speed = 5; /* 5 250 000 Hz */
	mode_con1.proto.dev_phase = 1;
	mode_con1.proto.dev_polarity = 0;
	mode_con1.proto.dev_bit_lsb_msb = DEV_SPI_FIRSTBIT_MSB;
	mode_con1.proto.dev_mode = DEV_SPI_MASTER;
	bsp_spi_init(BSP_DEV_SPI2, &mode_con1.proto);

	/* NSS - ChipSelect. */
	palSetPad(GPIOC, 1);
	palSetPadMode(GPIOC, 1, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_MID1);
	/* SCK.     */
	palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_MID1);
	/* MISO.    */
	palSetPadMode(GPIOC, 2, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_MID1);
	/* MOSI.    */
	palSetPadMode(GPIOC, 3, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_MID1);

	/* Enable TRF7970A EN=1 (EN2 is already equal to GND) */
	palClearPad(GPIOB, 11);
	palSetPadMode(GPIOB, 11, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_MID1);
	McuDelayMillisecond(2);

	palSetPad(GPIOB, 11);
	/* After setting EN=1 wait at least 21ms */
	McuDelayMillisecond(21);

	if (!hydranfc_test_shield()) {
		if(con != NULL)
			cprintf(con, "HydraNFC not found.\r\n");
		return FALSE;
	}

	/* Configure K1/2/3/4 Buttons as Input */
	palSetPadMode(GPIOB, 7, PAL_MODE_INPUT);
	palSetPadMode(GPIOB, 6, PAL_MODE_INPUT);
	palSetPadMode(GPIOB, 8, PAL_MODE_INPUT);
	palSetPadMode(GPIOB, 9, PAL_MODE_INPUT);

	/* Configure D2/3/4/5 LEDs as Output */
	D2_OFF;
	D3_OFF;
	D4_OFF;
	D5_OFF;
	palSetPadMode(GPIOB, 0, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_MID1);
	palSetPadMode(GPIOB, 3, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_MID1);
	palSetPadMode(GPIOB, 4, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_MID1);
	palSetPadMode(GPIOB, 5, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_MID1);

	/* Activates the EXT driver 1. */
	if(con != NULL)
		extStart(&EXTD1, &extcfg);

	return TRUE;
}
Beispiel #24
0
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)));
	}
}
Beispiel #25
0
/*
 * Application entry point.
 */
int main(void)
{
	enum led_status lstat = LST_INIT;
	EventListener el0;
	alert_status_t proto_st = ALST_INIT;
	alert_status_t bmp085_st = ALST_INIT;
	alert_status_t mpu6050_st = ALST_INIT;
	alert_status_t hmc5883_st = ALST_INIT;

	/*
	 * 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();

#ifdef BOARD_IMU_AHRF
	/* Clear DRDY pad */
	palClearPad(GPIOA, GPIOA_DRDY);

	/* Activates serial */
	sdStart(&SD1, NULL);
	sdStart(&SD2, NULL);

	/* Activate pwm */
	pwmStart(&PWMD1, &pwm1cfg);

	/* Activate i2c */
	i2cStart(&I2CD1, &i2c1cfg);

	/* Activate exti */
	extStart(&EXTD1, &extcfg);

#endif /* BOARD_IMU_AHRF */
#ifdef BOARD_CAPTAIN_PRO2

	/* Activates serial */
	sdStart(&SD3, NULL);
	sdStart(&SD4, NULL);

	/* Activate pwm */
	pwmStart(&PWMD3, &pwm3cfg);
	pwmStart(&PWMD4, &pwm4cfg);
	pwmStart(&PWMD5, &pwm5cfg);

	/* Activate i2c */
	i2cStart(&I2CD1, &i2c1cfg);

	/* Activate exti */
	extStart(&EXTD1, &extcfg);

	/* Activate adc */
	adcStart(&ADCD1, NULL);

#endif /* BOARD_CAPTAIN_PRO2 */

	/* alert subsys */
	chEvtInit(&alert_event_source);
	chEvtRegister(&alert_event_source, &el0, 0);

	/* init devices */
	pt_init();
	chThdSleepMilliseconds(10); /* power on delay */
#ifdef HAS_DEV_BMP085
	bmp085_init();
	chThdSleepMilliseconds(50); /* init delay */
#endif
#ifdef HAS_DEV_MS5611
	ms5611_init(&ms5611cfg);
	chThdSleepMilliseconds(50); /* init delay */
#endif
#ifdef HAS_DEV_MPU6050
	mpu6050_init(&mpu6050cfg);
	chThdSleepMilliseconds(250); /* give some time for mpu6050 configuration */
#endif
#ifdef HAS_DEV_HMC5883
	hmc5883_init(&hmc5883cfg);
#endif
#ifdef HAS_DEV_SERVOPWM
	servopwm_init(&servopwmcfg);
#endif
#ifdef HAS_DEV_NTC10K
	ntc10k_init();
#endif
#ifdef HAS_DEV_RPM
	rpm_init();
#endif

#ifdef BOARD_IMU_AHRF
	/* Set DRDY pad */
	palSetPad(GPIOA, GPIOA_DRDY);
#endif

	while (TRUE) {
		eventmask_t msk = chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(100));

		if (msk & EVENT_MASK(0)) {
			flagsmask_t fl = chEvtGetAndClearFlags(&el0);

			if (fl & ALERT_FLAG_PROTO)
				proto_st = pt_get_status();

#ifdef HAS_DEV_MPU6050
			if (fl & ALERT_FLAG_MPU6050)
				mpu6050_st = mpu6050_get_status();
#endif

#ifdef HAS_DEV_HMC5883
			if (fl & ALERT_FLAG_HMC5883)
				hmc5883_st = hmc5883_get_status();
#endif

#ifdef HAS_DEV_BMP085
			if (fl & ALERT_FLAG_BMP085)
				bmp085_st = bmp085_get_status();
#endif

#ifdef HAS_DEV_MS5611
			if (fl & ALERT_FLAG_BMP085)
				bmp085_st = ms5611_get_status();
#endif

			pt_set_sens_state(mpu6050_st, hmc5883_st, bmp085_st);
		}

		if (proto_st == ALST_FAIL || mpu6050_st == ALST_FAIL || hmc5883_st == ALST_FAIL || bmp085_st == ALST_FAIL)
			lstat = LST_FAIL;
		else if (proto_st == ALST_INIT || mpu6050_st == ALST_INIT || hmc5883_st == ALST_INIT || bmp085_st == ALST_INIT)
			lstat = LST_INIT;
		else if (proto_st == ALST_NORMAL && mpu6050_st == ALST_NORMAL && hmc5883_st == ALST_NORMAL && bmp085_st == ALST_NORMAL)
			lstat = LST_NORMAL;

		led_update(lstat);
	}
}
Beispiel #26
0
/*
 * Application entry point.
 */
int main(void) {

  /* performance counters */
  int32_t adc_ints = 0;
  int32_t spi_ints = 0;
  int32_t uart_ints = 0;
  int32_t adc_idle_ints = 0;
  int32_t spi_idle_ints = 0;
  int32_t uart_idle_ints = 0;
  uint32_t background_cnt = 0;
  systime_t T = 0;

  /*
   * 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();

#if STM32_NAND_USE_EXT_INT
  extStart(&EXTD1, &extcfg);
#endif
  chTMObjectInit(&tmu_driver_start);
  chTMStartMeasurementX(&tmu_driver_start);
#if USE_BAD_MAP
  nandStart(&NAND, &nandcfg, &badblock_map);
#else
  nandStart(&NAND, &nandcfg, NULL);
#endif
  chTMStopMeasurementX(&tmu_driver_start);

  chThdSleepMilliseconds(4000);

  chThdCreateStatic(BackgroundThreadWA,
        sizeof(BackgroundThreadWA),
        NORMALPRIO - 20,
        BackgroundThread,
        NULL);

  nand_wp_release();

  /*
   * run NAND test in parallel with DMA load and background thread
   */
  dma_storm_adc_start();
  dma_storm_uart_start();
  dma_storm_spi_start();
  T = chVTGetSystemTimeX();
  general_test(&NAND, NAND_TEST_START_BLOCK, NAND_TEST_END_BLOCK, 1);
  T = chVTGetSystemTimeX() - T;
  adc_ints = dma_storm_adc_stop();
  uart_ints = dma_storm_uart_stop();
  spi_ints = dma_storm_spi_stop();
  chSysLock();
  background_cnt = BackgroundThdCnt;
  BackgroundThdCnt = 0;
  chSysUnlock();

  /*
   * run DMA load and background thread _without_ NAND test
   */
  dma_storm_adc_start();
  dma_storm_uart_start();
  dma_storm_spi_start();
  chThdSleep(T);
  adc_idle_ints = dma_storm_adc_stop();
  uart_idle_ints = dma_storm_uart_stop();
  spi_idle_ints = dma_storm_spi_stop();

  /*
   * ensure that NAND code have negligible impact on other subsystems
   */
  osalDbgCheck(background_cnt > (BackgroundThdCnt / 4));
  osalDbgCheck(abs(adc_ints  - adc_idle_ints)  < (adc_idle_ints  / 20));
  osalDbgCheck(abs(uart_ints - uart_idle_ints) < (uart_idle_ints / 20));
  osalDbgCheck(abs(spi_ints  - spi_idle_ints)  < (spi_idle_ints  / 10));

  /*
   * perform ECC calculation test
   */
  ecc_test(&NAND, NAND_TEST_END_BLOCK);

#if USE_KILL_BLOCK_TEST
  kill_block(&NAND, NAND_TEST_KILL_BLOCK);
#endif

  nand_wp_assert();

  /*
   * Normal main() thread activity, in this demo it does nothing.
   */
  while (true) {
    chThdSleepMilliseconds(500);
  }
}
Beispiel #27
0
void ExtiLocalStart(void){
  ModemStart();
  extStart(&EXTD1, &extcfg);
}
Beispiel #28
0
/*
 * M2FC Main Thread.
 * Starts all the other threads then puts itself to sleep.
 */
int main(void) {
    halInit();
    chSysInit();
    chRegSetThreadName("Main");

    /* Start the heartbeat thread so it will be resetting the watchdog. */
    chThdCreateStatic(waThreadHB, sizeof(waThreadHB), LOWPRIO,
                      ThreadHeartbeat, NULL);

    /* Configure and enable the watchdog timer, stopped in debug halt. */
    DBGMCU->APB1FZ |= DBGMCU_APB1_FZ_DBG_IWDG_STOP;
    IWDG->KR = 0x5555;
    IWDG->PR = 3;
    IWDG->KR = 0xCCCC;

    /* Various module initialisation */
    state_estimation_init();
    dma_mutexes_init();

    /* Read config from SD card and wait for completion. */
    Thread* cfg_tp = chThdCreateStatic(waConfig, sizeof(waConfig),
                                       NORMALPRIO, config_thread, NULL);
    while(cfg_tp->p_state != THD_STATE_FINAL) chThdSleepMilliseconds(10);
    if(conf.location == CFG_M2FC_BODY)
        LocalStatus = &M2FCBodyStatus;
    else if(conf.location == CFG_M2FC_NOSE)
        LocalStatus = &M2FCNoseStatus;
    if(conf.config_loaded)
        m2status_config_status(STATUS_OK);
    else
        m2status_config_status(STATUS_ERR);

    /* Activate the EXTI pin change interrupts */
    extStart(&EXTD1, &extcfg);

    /* Start module threads */
    m2serial_shell = m2fc_shell_run;
    M2SerialSD = &SD1;
    sdStart(M2SerialSD, NULL);
    chThdCreateStatic(waM2Serial, sizeof(waM2Serial), HIGHPRIO,
                      m2serial_thread, NULL);

    chThdCreateStatic(waM2Status, sizeof(waM2Status), HIGHPRIO,
                      m2status_thread, NULL);

    chThdCreateStatic(waDatalogging, sizeof(waDatalogging), HIGHPRIO,
                      datalogging_thread, NULL);

    chThdCreateStatic(waMission, sizeof(waMission), NORMALPRIO,
                      mission_thread, NULL);

    chThdCreateStatic(waMS5611, sizeof(waMS5611), NORMALPRIO,
                      ms5611_thread, NULL);

    chThdCreateStatic(waADXL345, sizeof(waADXL345), NORMALPRIO,
                      adxl345_thread, NULL);

    chThdCreateStatic(waADXL375, sizeof(waADXL375), NORMALPRIO,
                      adxl375_thread, NULL);

    chThdCreateStatic(waPyros, sizeof(waPyros), NORMALPRIO,
                      pyro_continuity_thread, NULL);

    if(conf.use_gyro) {
        chThdCreateStatic(waL3G4200D, sizeof(waL3G4200D), NORMALPRIO,
                          l3g4200d_thread, NULL);
    } else {
        m2status_gyro_status(STATUS_OK);
    }

    if(conf.use_magno) {
        chThdCreateStatic(waHMC5883L, sizeof(waHMC5883L), NORMALPRIO,
                          hmc5883l_thread, NULL);
    } else {
        m2status_magno_status(STATUS_OK);
    }

    if(conf.use_adc) {
        chThdCreateStatic(waAnalogue, sizeof(waAnalogue), NORMALPRIO,
                          analogue_thread, NULL);
    } else {
        m2status_adc_status(STATUS_OK);
    }

    /* Let the main thread idle now. */
    chThdSetPriority(LOWPRIO);
    chThdSleep(TIME_INFINITE);

    return 0;
}
Beispiel #29
0
void ExtiPnc::start(void){
  extStart(&EXTD1, &extcfg);
  extChannelEnable(&EXTD1, GPIOH_FPGA_IO11);
  ready = true;
}