예제 #1
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 the GPT drivers 2 and 3.
   */
  gptStart(&GPTD2, &gpt2cfg);
  gptPolledDelay(&GPTD2, 10); /* Small delay.*/
  gptStart(&GPTD3, &gpt3cfg);
  gptPolledDelay(&GPTD3, 10); /* Small delay.*/

  /*
   * Normal main() thread activity, it changes the GPT1 period every
   * five seconds.
   */
  while (TRUE) {
    palSetPad(GPIOD, GPIOD_LED4);
    gptStartContinuous(&GPTD2, 5000);
    chThdSleepMilliseconds(5000);
    gptStopTimer(&GPTD2);
    palClearPad(GPIOD, GPIOD_LED4);
    gptStartContinuous(&GPTD2, 2500);
    chThdSleepMilliseconds(5000);
    gptStopTimer(&GPTD2);
  }
}
예제 #2
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();

  palSetPadMode(GPIOF, GPIOF_LED_RED, PAL_MODE_OUTPUT_PUSHPULL);

  /*
   * Start the gpt drivers with the custom configurations.
   */
  gptStart(&GPTD1, &gpt1cfg);
  gptStart(&GPTD7, &gpt7cfg);

  /*
   * Normal main() thread activity
   */
  while (TRUE) {
    gptStartContinuous(&GPTD7, 5000);
    chThdSleepMilliseconds(5000);
    gptStopTimer(&GPTD7);
    gptStartContinuous(&GPTD7, 2500);
    chThdSleepMilliseconds(5000);
    gptStopTimer(&GPTD7);
  }
  
  return 0;
}
예제 #3
0
파일: main.c 프로젝트: AlexShiLucky/ChibiOS
/*
 * 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 the GPT driver 1.
   */
  gptStart(&GPTD1, &gpt1cfg);

#if !POLLED_TEST
  gptStartContinuous(&GPTD1, 2);
#endif

  while (1) {
#if POLLED_TEST
    gpt_lld_polled_delay(&GPTD1, 1) ;
    palTogglePad(GPIOB, GPIOB_LED);
#else
    chThdSleepMilliseconds(500);
#endif
  }
}
예제 #4
0
void play_note(float freq, int vol) {

  dprintf("audio play note freq=%d vol=%d", (int)freq, vol);

  if (!audio_initialized) {
      audio_init();
  }

  if (audio_config.enable && voices < 8) {

     // Cancel notes if notes are playing
    if (playing_notes) {
      stop_all_notes();
    }

    playing_note = true;

    envelope_index = 0;

    if (freq > 0) {
      frequencies[voices] = freq;
      volumes[voices] = vol;
      voices++;
    }

    gptStart(&GPTD8, &gpt8cfg1);
    gptStartContinuous(&GPTD8, 2U);
    RESTART_CHANNEL_1();
    RESTART_CHANNEL_2();
  }

}
예제 #5
0
void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat) {

  if (!audio_initialized) {
    audio_init();
  }

  if (audio_config.enable) {

    // Cancel note if a note is playing
    if (playing_note) {
      stop_all_notes();
    }

    playing_notes = true;

    notes_pointer = np;
    notes_count = n_count;
    notes_repeat = n_repeat;

    place = 0;
    current_note = 0;

    note_frequency = (*notes_pointer)[current_note][0];
    note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100);
    note_position = 0;

    gptStart(&GPTD8, &gpt8cfg1);
    gptStartContinuous(&GPTD8, 2U);
    RESTART_CHANNEL_1();
    RESTART_CHANNEL_2();
  }
}
예제 #6
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();

  palSetPadMode(IOPORT2, 7, PAL_MODE_OUTPUT_PUSHPULL);

  sdStart(&SD1, NULL);
  gptStart(&GPTD1, &gpt2cfg);

  gptStartContinuous(&GPTD1, 500);
  while (1) {
    chprintf(&SD1, "OCR1A: %d, TCCR1B: %x, period: %d, counter: %d , TCNT1: %d\r\n",
                   OCR1A,
                   TCCR1B,
                   GPTD1.period,
                   GPTD1.counter,
                   TCNT1);
    chThdSleepMilliseconds(100);
  }
}
예제 #7
0
int main(void) {
    // performs all the init required to use various peripherals
	halInit();
    // gets the operating system code up and running
    // one of the timer unit is init to generate interrupts at a spec rate
	chSysInit();
	
    // configure the I/O pin
	palSetPadMode(GPIOD, GPIOD_LED6, PAL_MODE_OUTPUT_PUSHPULL);
    palSetPadMode(GPIOD, GPIOD_LED5, PAL_MODE_OUTPUT_PUSHPULL);

    // configure the GPT Timer
    gptStart(&GPTD2, &gptcfg);

    // start timer in continuous mode
    gptStartContinuous(&GPTD2, 10); // 70KHz

	while (TRUE) {
		// sets a pin high
        palSetPad(GPIOD, GPIOD_LED5);
        // generates a 500ms delay
        // OS immediately shutsdown processor core & switches to low power mode
		chThdSleepMilliseconds(500);
        // sets a pin low
		palClearPad(GPIOD, GPIOD_LED5);
		chThdSleepMilliseconds(500);
	}
}
예제 #8
0
void dcf_task(arg_t c)
{
	(void) c;
	static uint8_t machine = 0;

	// machine start
	if (machine == 0)
	{
		ma_disable(1);
		gptStartContinuous(timer, 100);
		machine++;
	}
	else if (machine == 1)
	{
		if (decode_finished)
		{
			decode_finished = 0;
			machine = 0;
			shUnregisterStruct(&del);
			gptStopTimer(timer);
			dcf_decode();
			ma_disable(0);
			rdy = 1;
		}
	}
}
예제 #9
0
/* Private functions ---------------------------------------------------------*/
void dcf_init(void)
{
	palSetPadMode(DCF_PORT, DCF_PIN, PAL_MODE_INPUT);
	DBGMCU->CR |= DBGMCU_CR_DBG_TIM3_STOP;

	shFillStruct(&del, dcf_task, NULL, MS2ST(100), PERIODIC);
	gptStart(timer, &gpt);
	gptStart(secs , &sec_gpt);

	gptStartContinuous(secs,10000);
}
예제 #10
0
void timer_init(void) 
{
  	// start system tick timer
	gptStart (&GPTD3, &gpt3cfg);
	gptStartContinuous (&GPTD3, TICK_TIME_MS * 1000);

	// start stepper timer
	timer1_interval = 50000; // nominal rate
	gptStart (&GPTD1, &gpt1cfg);
	//gptStartOneShot (&GPTD1, timer1_interval);
}
예제 #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();

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

    /*
     * Starting GPT4 driver, it is used for triggering the ADC.
     */
    gptStart(&GPTD4, &gpt4cfg1);

    /*
     * Fixed an errata on the STM32F7xx, the DAC clock is required for ADC
     * triggering.
     */
    rccEnableDAC1(false);

    /*
     * Activates the ADC1 driver and the temperature sensor.
     */
    adcStart(&ADCD1, NULL);
    adcSTM32EnableTSVREFE();

    /*
     * Starts an ADC continuous conversion triggered with a period of
     * 1/10000 second.
     */
    adcStartConversion(&ADCD1, &adcgrpcfg1, samples1, ADC_GRP1_BUF_DEPTH);
    gptStartContinuous(&GPTD4, 100);

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

    /*
     * Normal main() thread activity, in this demo it does nothing.
     */
    while (true) {
        chThdSleepMilliseconds(500);
    }
}
예제 #12
0
void TimeKeeper::start(void) {

  unix_usec = rtc_get_time_unix_usec();

  gptStart(&RTC_GPTD, &gptcfg);
  gptStartContinuous(&RTC_GPTD, RTC_TIMER_STEP);

  worker = chThdCreateStatic(TimekeeperThreadWA, sizeof(TimekeeperThreadWA),
                             TIMEKEEPERPRIO, TimekeeperThread, this);
  osalDbgCheck(nullptr != worker); // Can not allocate memory
  Exti.pps(true);
  ready = true;
}
예제 #13
0
파일: main.c 프로젝트: KTannenberg/ChibiOS
/*
 * 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();

  /*
   * Starting DAC1 driver, setting up the output pins as analog as suggested
   * by the Reference Manual.
   */
  palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
  palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);
  dacStart(&DACD1, &dac1cfg1);

  /*
   * Starting GPT6 driver, it is used for triggering the DAC.
   */
  gptStart(&GPTD6, &gpt6cfg1);

  /*
   * Starting a continuous conversion.
   * Note, the buffer size is divided by two because two elements are fetched
   * for each transfer.
   */
  dacStartConversion(&DACD1, &dacgrpcfg1,
                     (dacsample_t *)dac_buffer, DAC_BUFFER_SIZE / 2U);
  gptStartContinuous(&GPTD6, 2U);

  /*
   * Normal main() thread activity, if the button is pressed then the DAC
   * transfer is stopped.
   */
  while (true) {
    if (palReadPad(GPIOA, GPIOA_BUTTON)) {
      gptStopTimer(&GPTD6);
      dacStopConversion(&DACD1);
    }
    chThdSleepMilliseconds(500);
  }
  return 0;
}
예제 #14
0
static void adctodac(void *arg)
{
    uint16_t temp = 0;
    adcStart(&ADCD1, &adccfg);
    dacStart(&DACD1, &dac1cfg1);

    gptStart(&GPTD6, &gpt6cfg1);

    while(!0)
    {
        adcStartConversion(&ADCD1, &adccg, samples_buf, ADC_BUF_DEPTH);
        temp = samples_buf[0];
        //dacPutChannelX(&DACD1, 1U, temp);
        dacStartConversion(&DACD1, &dacgrpcfg1, samples_buf, ADC_BUF_DEPTH);
        gptStartContinuous(&GPTD6, 2U);
        chThdSleepMilliseconds(1);
    }
}
예제 #15
0
파일: app1.c 프로젝트: shangma/Bootloader
msg_t app_thread(void *arg) {
	uint32_t cnt;

	(void) arg;

	cnt = 0;
	print("Hello from APP1\r\n");

	gptStart(&GPTD3, &gpt3cfg);
	gptStartContinuous(&GPTD3, 500);
	print("GPTD3 started\r\n");

	while (TRUE) {
		cnt++;
		/*test(cnt);*/
		chThdSleepMilliseconds(5000);
	}
	return 0;
}
예제 #16
0
파일: main.c 프로젝트: aarrtteemm/Workspace
/*
 * 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();
  
  static GPTConfig gpt2cfg =
{
  2000,    /* timer clock.*/
  gpt2cb        /* Timer callback.*/
};
  
  DDRB |= _BV(DDB7);

  sdStart(&SD1, NULL);
  gptStart(&GPTD1,&gpt2cfg);
  
  gptStartContinuous(&GPTD1, 500);
  while(1){
      chprintf(&SD1,"OCR1A: %d, TCCR1B, %x, period %d, counter: %d , TCNT1 %d\n",OCR1A,TCCR1B,GPTD1.period,GPTD1.counter,TCNT1);
      chThdSleepMilliseconds(100);
  }
    


  
  
  
  
  
  
}
예제 #17
0
/*
 * Application entry point.
 */
int main(void) {

  halInit();
  chSysInit();

  /*
  * Set PA3 - PA1 to Analog (DAC1_CH1, OPAMP1_INP)
  * You will have to connect these with a jumper wire
  */
  palSetPadMode(GPIOA, 3, PAL_MODE_INPUT_ANALOG);
  palSetPadMode(GPIOA, 1, PAL_MODE_INPUT_ANALOG);

  /*
   * Start peripherals
   */
  dacStart(&DACD1, &dac1cfg1);
  opampStart(&OPAMPD1, &opamp1_conf);
  gptStart(&GPTD6, &gpt6cfg1);

  /*
   * Starting a continuous conversion.
   */
  dacStartConversion(&DACD1, &dacgrpcfg1, dac_buffer, DAC_BUFFER_SIZE);
  gptStartContinuous(&GPTD6, 2U);

  opampEnable(&OPAMPD1);
  opampCalibrate();

  /*
   * Normal main() thread activity.
   */
  while (true) {

    chThdSleepMilliseconds(250);
    palToggleLine(LINE_LED3_RED);
  }
  return 0;
}
예제 #18
0
파일: main.c 프로젝트: aperiodic/stm32
/*
 * 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)));
	}
}
예제 #19
0
/**
 * @brief   IRQ storm execution.
 *
 * @param[in] cfg       pointer to the test configuration structure
 *
 * @api
 */
void irq_storm_execute(const irq_storm_config_t *cfg) {
  unsigned i;
  gptcnt_t interval, threshold, worst;

  /* Global configuration pointer.*/
  config = cfg;

  /* Starting timers using the stored configurations.*/
  gptStart(cfg->gpt1p, cfg->gptcfg1p);
  gptStart(cfg->gpt2p, cfg->gptcfg2p);

  /*
   * Initializes the mailboxes and creates the worker threads.
   */
  for (i = 0; i < IRQ_STORM_CFG_NUM_THREADS; i++) {
    chMBObjectInit(&mb[i], b[i], IRQ_STORM_CFG_MAILBOX_SIZE);
    threads[i] = chThdCreateStatic(irq_storm_thread_wa[i],
                                   sizeof irq_storm_thread_wa[i],
                                   IRQ_STORM_CFG_THREADS_PRIORITY,
                                   irq_storm_thread,
                                   (void *)i);
  }

  /* Printing environment information.*/
  chprintf(cfg->out, "");
  chprintf(cfg->out, "\r\n*** ChibiOS/RT IRQ-STORM long duration test\r\n***\r\n");
  chprintf(cfg->out, "*** Kernel:       %s\r\n", CH_KERNEL_VERSION);
  chprintf(cfg->out, "*** Compiled:     %s\r\n", __DATE__ " - " __TIME__);
#ifdef PORT_COMPILER_NAME
  chprintf(cfg->out, "*** Compiler:     %s\r\n", PORT_COMPILER_NAME);
#endif
  chprintf(cfg->out, "*** Architecture: %s\r\n", PORT_ARCHITECTURE_NAME);
#ifdef PORT_CORE_VARIANT_NAME
  chprintf(cfg->out, "*** Core Variant: %s\r\n", PORT_CORE_VARIANT_NAME);
#endif
  chprintf(cfg->out, "*** System Clock: %d\r\n", cfg->sysclk);
#ifdef PORT_INFO
  chprintf(cfg->out, "*** Port Info:    %s\r\n", PORT_INFO);
#endif
#ifdef PLATFORM_NAME
  chprintf(cfg->out, "*** Platform:     %s\r\n", PLATFORM_NAME);
#endif
#ifdef BOARD_NAME
  chprintf(cfg->out, "*** Test Board:   %s\r\n", BOARD_NAME);
#endif
  chprintf(cfg->out, "***\r\n");
  chprintf(cfg->out, "*** Iterations:   %d\r\n", IRQ_STORM_CFG_ITERATIONS);
  chprintf(cfg->out, "*** Randomize:    %d\r\n", IRQ_STORM_CFG_RANDOMIZE);
  chprintf(cfg->out, "*** Threads:      %d\r\n", IRQ_STORM_CFG_NUM_THREADS);
  chprintf(cfg->out, "*** Mailbox size: %d\r\n\r\n", IRQ_STORM_CFG_MAILBOX_SIZE);

  /* Test loop.*/
  worst = 0;
  for (i = 1; i <= IRQ_STORM_CFG_ITERATIONS; i++){

    chprintf(cfg->out, "Iteration %d\r\n", i);
    saturated = false;
    threshold = 0;

    /* Timer intervals starting at 2mS then decreased by 10% after each
       cycle.*/
    for (interval = 2000; interval >= 2; interval -= (interval + 9) / 10) {

      /* Timers programmed slightly out of phase each other.*/
      gptStartContinuous(cfg->gpt1p, interval - 1); /* Slightly out of phase.*/
      gptStartContinuous(cfg->gpt2p, interval + 1); /* Slightly out of phase.*/

      /* Storming for one second.*/
      chThdSleepMilliseconds(1000);

      /* Timers stopped.*/
      gptStopTimer(cfg->gpt1p);
      gptStopTimer(cfg->gpt2p);

      /* Did the storm saturate the threads chain?*/
      if (!saturated)
        chprintf(cfg->out, ".");
      else {
        chprintf(cfg->out, "#");
        if (threshold == 0)
          threshold = interval;
        break;
      }
    }
    /* Gives threads a chance to empty the mailboxes before next cycle.*/
    chThdSleepMilliseconds(20);
    chprintf(cfg->out, "\r\nSaturated at %d uS\r\n\r\n", threshold);
    if (threshold > worst)
      worst = threshold;
  }
  gptStopTimer(cfg->gpt1p);
  gptStopTimer(cfg->gpt2p);

  chprintf(cfg->out, "Worst case at %d uS\r\n", worst);
  chprintf(cfg->out, "\r\nTest Complete\r\n");

  /* Terminating threads and cleaning up.*/
  for (i = 0; i < IRQ_STORM_CFG_NUM_THREADS; i++) {
    chThdTerminate(threads[i]);
    chThdWait(threads[i]);
    threads[i] = NULL;
  }
}
예제 #20
0
/*
 * Application entry point.
 */
int main(void) {
  unsigned i;
  gptcnt_t interval, threshold, worst;

  /* Enables FPU exceptions.*/
  nvicEnableVector(FPU_IRQn, 1);

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

  /*
   * Prepares the Serial driver 2 and GPT drivers 4 and 3.
   */
  sdStart(&SD2, NULL);          /* Default is 38400-8-N-1.*/
  palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
  palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
  gptStart(&GPTD4, &gpt4cfg);
  gptStart(&GPTD3, &gpt3cfg);

  /*
   * Enabling TIM1 as a fast interrupts source.
   */
  rccEnableTIM1(false);
  nvicEnableVector(STM32_TIM1_UP_NUMBER, 0);
  TIM1->ARR  = 10000;
  TIM1->PSC  = 0;
  TIM1->CNT  = 0;
  TIM1->DIER = TIM_DIER_UIE;
  TIM1->CR1  = TIM_CR1_CEN;

  /*
   * Initializes the worker threads.
   */
  chThdCreateStatic(waWorkerThread, sizeof waWorkerThread,
                    NORMALPRIO - 20, WorkerThread, NULL);
  chThdCreateStatic(waPeriodicThread, sizeof waPeriodicThread,
                    NORMALPRIO - 10, PeriodicThread, NULL);

  /*
   * Test procedure.
   */
  println("");
  println("*** ChibiOS/RT IRQ-STORM-FPU long duration test");
  println("***");
  print("*** Kernel:       ");
  println(CH_KERNEL_VERSION);
  print("*** Compiled:     ");
  println(__DATE__ " - " __TIME__);
#ifdef PORT_COMPILER_NAME
  print("*** Compiler:     ");
  println(PORT_COMPILER_NAME);
#endif
  print("*** Architecture: ");
  println(PORT_ARCHITECTURE_NAME);
#ifdef PORT_CORE_VARIANT_NAME
  print("*** Core Variant: ");
  println(PORT_CORE_VARIANT_NAME);
#endif
#ifdef PORT_INFO
  print("*** Port Info:    ");
  println(PORT_INFO);
#endif
#ifdef PLATFORM_NAME
  print("*** Platform:     ");
  println(PLATFORM_NAME);
#endif
#ifdef BOARD_NAME
  print("*** Test Board:   ");
  println(BOARD_NAME);
#endif
  println("***");
  print("*** System Clock: ");
  printn(STM32_SYSCLK);
  println("");
  print("*** Iterations:   ");
  printn(ITERATIONS);
  println("");
  print("*** Randomize:    ");
  printn(RANDOMIZE);
  println("");

  println("");
  worst = 0;
  for (i = 1; i <= ITERATIONS; i++){
    print("Iteration ");
    printn(i);
    println("");
    saturated = FALSE;
    threshold = 0;
    for (interval = 2000; interval >= 10; interval -= interval / 10) {
      gptStartContinuous(&GPTD4, interval - 1); /* Slightly out of phase.*/
      gptStartContinuous(&GPTD3, interval + 1); /* Slightly out of phase.*/
      chThdSleepMilliseconds(1000);
      gptStopTimer(&GPTD4);
      gptStopTimer(&GPTD3);
      if (!saturated)
        print(".");
      else {
        print("#");
        if (threshold == 0)
          threshold = interval;
      }
    }
    /* Gives the worker threads a chance to empty the mailboxes before next
       cycle.*/
    chThdSleepMilliseconds(20);
    println("");
    print("Saturated at ");
    printn(threshold);
    println(" uS");
    println("");
    if (threshold > worst)
      worst = threshold;
  }
  gptStopTimer(&GPTD4);
  gptStopTimer(&GPTD3);

  print("Worst case at ");
  printn(worst);
  println(" uS");
  println("");
  println("Test Complete");

  /*
   * Normal main() thread activity, nothing in this test.
   */
  while (true) {
    chThdSleepMilliseconds(5000);
  }
}
예제 #21
0
파일: main.cpp 프로젝트: bnahill/acc_boat
static void timer_start(){
	gptStartContinuous(timer_driver, 1000);
}
예제 #22
0
/****************** Thread main loop ***********************************/
msg_t analogue_thread(void *args)
{
    (void)args;

    chRegSetThreadName("Analogue");
    chBSemObjectInit(&bsAnalogueInst, true);
    chBSemObjectInit(&bsAnalogueFX, true);

    adcInit();
    adcStart(&ADCD1, NULL);
    adcStart(&ADCD2, NULL);
    adcStartConversion(&ADCD1, &adc_con_group_1, (adcsample_t*)buffer1,
                       INST_BUF_DEPTH);
    adcStartConversion(&ADCD2, &adc_con_group_2, (adcsample_t*)fx_samples,
                       FX_BUF_DEPTH);

    dacInit();
    dacStart(&DACD1, &dac_cfg);
    dacStartConversion(&DACD1, &dac_conv_grp, (dacsample_t*)buffer3,
                       INST_BUF_DEPTH);
    // Enable DAC output buffer:
    DACD1.params->dac->CR |= DAC_CR_BOFF1;

    /* Start the GPT timers. They reload at after reaching 1 such that
     * TRGO frequency equals timer frequency. */
    gptStart(&GPTD3, &gpt_inst_config);
    GPTD3.tim->CR2 |= STM32_TIM_CR2_MMS(2);
    gptStartContinuous(&GPTD3, 2);
    GPTD3.tim->DIER &= ~STM32_TIM_DIER_UIE;

    gptStart(&GPTD8, &gpt_fx_config);
    GPTD8.tim->CR2 |= STM32_TIM_CR2_MMS(2);
    gptStartContinuous(&GPTD8, 2);
    GPTD8.tim->DIER &= ~STM32_TIM_DIER_UIE;

    state = 1;

    // States:
    // 1 - ADC:buf1, DSP:buf2, DAC:buf3
    // 2 - DSP:buf1, DAC:buf2, ADC:buf3
    // 3 - DAC:buf1, ADC:buf2, DSP:buf3

    /* Wait until the ADC callback boops the semaphore. */
    volatile uint16_t *dsp_buf;
    while(true) {
        chSysLock();
        chBSemWaitS(&bsAnalogueInst);
        chSysUnlock();

        state += 1;

        switch(state)
        {
            case 1:
                dmaSetOtherMemory(ADCD1.dmastp, buffer1);
                dsp_buf = buffer2;
                dmaSetOtherMemory(DACD1.params->dma, buffer3);
                break;
            case 2:
                dmaSetOtherMemory(ADCD1.dmastp, buffer3);
                dsp_buf = buffer1;
                dmaSetOtherMemory(DACD1.params->dma, buffer2);
                break;
            case 3:
                dmaSetOtherMemory(ADCD1.dmastp, buffer2);
                dsp_buf = buffer3;
                dmaSetOtherMemory(DACD1.params->dma, buffer1);
                break;
            default:
                state = 1;
                dmaSetOtherMemory(ADCD1.dmastp, buffer1);
                dsp_buf = buffer2;
                dmaSetOtherMemory(DACD1.params->dma, buffer3);
        }
        dsp_stuff(dsp_buf);
    }
}
예제 #23
0
파일: main.c 프로젝트: Tambralinga/ChibiOS
/*
 * Application entry point.
 */
int main(void) {
  unsigned i;
  gptcnt_t interval, threshold, worst;

  /*
   * 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, PA9 and PA10 are routed to USART1.
   */
  sdStart(&SD1, NULL);
  palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7));       /* USART1 TX.       */
  palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7));      /* USART1 RX.       */

  /*
   * Activates GPTs.
   */
  gptStart(&GPTD4, &gpt4cfg);
  gptStart(&GPTD3, &gpt3cfg);

  /*
   * Initializes the mailboxes and creates the worker threads.
   */
  for (i = 0; i < NUM_THREADS; i++) {
    chMBObjectInit(&mb[i], b[i], MAILBOX_SIZE);
    chThdCreateStatic(waWorkerThread[i], sizeof waWorkerThread[i],
                      NORMALPRIO - 20, WorkerThread, (void *)i);
  }

  /*
   * Test procedure.
   */
  println("");
  println("*** ChibiOS/RT IRQ-STORM long duration test");
  println("***");
  print("*** Kernel:       ");
  println(CH_KERNEL_VERSION);
  print("*** Compiled:     ");
  println(__DATE__ " - " __TIME__);
#ifdef PORT_COMPILER_NAME
  print("*** Compiler:     ");
  println(PORT_COMPILER_NAME);
#endif
  print("*** Architecture: ");
  println(PORT_ARCHITECTURE_NAME);
#ifdef PORT_CORE_VARIANT_NAME
  print("*** Core Variant: ");
  println(PORT_CORE_VARIANT_NAME);
#endif
#ifdef PORT_INFO
  print("*** Port Info:    ");
  println(PORT_INFO);
#endif
#ifdef PLATFORM_NAME
  print("*** Platform:     ");
  println(PLATFORM_NAME);
#endif
#ifdef BOARD_NAME
  print("*** Test Board:   ");
  println(BOARD_NAME);
#endif
  println("***");
  print("*** System Clock: ");
  printn(STM32_SYSCLK);
  println("");
  print("*** Iterations:   ");
  printn(ITERATIONS);
  println("");
  print("*** Randomize:    ");
  printn(RANDOMIZE);
  println("");
  print("*** Threads:      ");
  printn(NUM_THREADS);
  println("");
  print("*** Mailbox size: ");
  printn(MAILBOX_SIZE);
  println("");

  println("");
  worst = 0;
  for (i = 1; i <= ITERATIONS; i++){
    print("Iteration ");
    printn(i);
    println("");
    saturated = FALSE;
    threshold = 0;
    for (interval = 2000; interval >= 10; interval -= interval / 10) {
      gptStartContinuous(&GPTD4, interval - 1); /* Slightly out of phase.*/
      gptStartContinuous(&GPTD3, interval + 1); /* Slightly out of phase.*/
      chThdSleepMilliseconds(1000);
      gptStopTimer(&GPTD4);
      gptStopTimer(&GPTD3);
      if (!saturated)
        print(".");
      else {
        print("#");
        if (threshold == 0)
          threshold = interval;
      }
    }
    /* Gives the worker threads a chance to empty the mailboxes before next
       cycle.*/
    chThdSleepMilliseconds(20);
    println("");
    print("Saturated at ");
    printn(threshold);
    println(" uS");
    println("");
    if (threshold > worst)
      worst = threshold;
  }
  gptStopTimer(&GPTD4);
  gptStopTimer(&GPTD3);

  print("Worst case at ");
  printn(worst);
  println(" uS");
  println("");
  println("Test Complete");

  /*
   * Normal main() thread activity, nothing in this test.
   */
  while (TRUE) {
    chThdSleepMilliseconds(5000);
  }
}
예제 #24
0
static void buzzer_start(uint16_t freq) {
   gptStart(&BUZZER_GPT, &gpt_cfg);
   gptStartContinuous(&BUZZER_GPT, FREQ(freq));
}
예제 #25
0
파일: main.c 프로젝트: CNCBASHER/ChibiOS
/*
 * Application entry point.
 */
int main(void) {
  unsigned i;
  gptcnt_t interval, threshold, worst;

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

  /*
   * Prepares the Serial driver 2 and GPT drivers 1 and 2.
   */
  sdStart(&SD1, NULL);          /* Default is 38400-8-N-1.*/
  gptStart(&GPTD1, &gpt1cfg);
  gptStart(&GPTD2, &gpt2cfg);

  /*
   * Initializes the mailboxes and creates the worker threads.
   */
  for (i = 0; i < NUM_THREADS; i++) {
    chMBInit(&mb[i], b[i], MAILBOX_SIZE);
    chThdCreateStatic(waWorkerThread[i], sizeof waWorkerThread[i],
                      NORMALPRIO - 20, WorkerThread, (void *)i);
  }

  /*
   * Test procedure.
   */
  println("");
  println("*** ChibiOS/RT IRQ-STORM long duration test");
  println("***");
  print("*** Kernel:       ");
  println(CH_KERNEL_VERSION);
#ifdef CH_COMPILER_NAME
  print("*** Compiler:     ");
  println(CH_COMPILER_NAME);
#endif
  print("*** Architecture: ");
  println(CH_ARCHITECTURE_NAME);
#ifdef CH_CORE_VARIANT_NAME
  print("*** Core Variant: ");
  println(CH_CORE_VARIANT_NAME);
#endif
#ifdef CH_PORT_INFO
  print("*** Port Info:    ");
  println(CH_PORT_INFO);
#endif
#ifdef PLATFORM_NAME
  print("*** Platform:     ");
  println(PLATFORM_NAME);
#endif
#ifdef BOARD_NAME
  print("*** Test Board:   ");
  println(BOARD_NAME);
#endif
  println("***");
  print("*** System Clock: ");
  printn(LPC13xx_SYSCLK);
  println("");
  print("*** Iterations:   ");
  printn(ITERATIONS);
  println("");
  print("*** Randomize:    ");
  printn(RANDOMIZE);
  println("");
  print("*** Threads:      ");
  printn(NUM_THREADS);
  println("");
  print("*** Mailbox size: ");
  printn(MAILBOX_SIZE);
  println("");

  println("");
  worst = 0;
  for (i = 1; i <= ITERATIONS; i++){
    print("Iteration ");
    printn(i);
    println("");
    saturated = FALSE;
    threshold = 0;
    for (interval = 2000; interval >= 20; interval -= interval / 10) {
      gptStartContinuous(&GPTD1, interval - 1); /* Slightly out of phase.*/
      gptStartContinuous(&GPTD2, interval + 1); /* Slightly out of phase.*/
      chThdSleepMilliseconds(1000);
      gptStopTimer(&GPTD1);
      gptStopTimer(&GPTD2);
      if (!saturated)
        print(".");
      else {
        print("#");
        if (threshold == 0)
          threshold = interval;
      }
    }
    /* Gives the worker threads a chance to empty the mailboxes before next
       cycle.*/
    chThdSleepMilliseconds(20);
    println("");
    print("Saturated at ");
    printn(threshold);
    println(" uS");
    println("");
    if (threshold > worst)
      worst = threshold;
  }
  gptStopTimer(&GPTD1);
  gptStopTimer(&GPTD2);

  print("Worst case at ");
  printn(worst);
  println(" uS");
  println("");
  println("Test Complete");

  /*
   * Normal main() thread activity, nothing in this test.
   */
  while (TRUE) {
    chThdSleepMilliseconds(5000);
  }
  return 0;
}
예제 #26
0
//-----------------------------------------------------------------------------
static void
cmd_tcxo_test(BaseSequentialStream * chp, int argc, char * argv[])
{
    uint32_t passes = 0;
    if ( argc == 0 )
    {
        passes = PASSES;
    }
    else
    {
        passes = atoi(argv[0]);
        if ( passes > PASSES )
        {
            chprintf(chp, "WARNING: you asked for too many passes (%d), doing just (%d)\n",
                     passes, PASSES);
            passes = PASSES;
        }
    }

    //--------------------------------------------------------------------------
    gptStart(&GPTD2, &one_sec_cfg);
    gptStartContinuous(&GPTD2, 84000000-(factory_config.tcxo_compensation/2));

    // wait X seconds to make sure the GPS has started up...
    pps = 0;
    while (pps < 5)
    {
        st7565_clear(&ST7565D1);
        st7565_drawstring(&ST7565D1, 0, 0, "TCXO vs GPS TEST");
        INIT_CBUF();
        chprintf(bss, "Waiting on GPS: %d", 5-pps);
        st7565_drawstring(&ST7565D1, 0, 1, charbuf);
        st7565_display(&ST7565D1);
        chThdSleepMilliseconds(50);
    }

    kbg_setLED2(0);

    st7565_clear(&ST7565D1);
    chprintf(chp, "pass,PASSES,pps_diff\n");

    for ( uint32_t pass = 0 ; pass < passes ; )
    {
        chThdSleepMilliseconds(50);
        if ( one_sec_pps_changed )
        {
            kbg_setLED3(1);
            times[pass] = one_sec_pps_diff;
            int32_t diff_from_parity = 168000000 - pps_diff;
            chprintf(chp, "%6d,%6d,%14d,%6d,%14d\n", pass+1, passes,
                     one_sec_pps_diff, one_sec_pps_diff_diff, diff_from_parity);
            one_sec_pps_changed = FALSE;
            pass++;

            st7565_drawstring(&ST7565D1, 0, 0, "TCXO vs GPS CONF");

            INIT_CBUF();
            chprintf(bss,"Doing %d passes", passes);
            st7565_drawstring(&ST7565D1, 0, 1, charbuf);

            INIT_CBUF();
            chprintf(bss,"Pass: %d", pass);
            st7565_drawstring(&ST7565D1, 0, 2, charbuf);

            INIT_CBUF();
            chprintf(bss,"Time diff: %d", one_sec_pps_diff);
            st7565_drawstring(&ST7565D1, 0, 3, charbuf);

            st7565_display(&ST7565D1);
            st7565_clear(&ST7565D1);

            chThdSleepMilliseconds(10);
            kbg_setLED3(0);
        }
    }
    gptStopTimer(&GPTD2);
    gptStop(&GPTD2);
}