Ejemplo n.º 1
0
__EXPORT void up_wspeedinit()
{
	// Initialize interrupts (GPIO 1-4)
	stm32_gpiosetevent(GPIO_GPIO0_INPUT, true, true, false, sensor_int1);
	stm32_gpiosetevent(GPIO_GPIO1_INPUT, true, true, false, sensor_int2);
	stm32_gpiosetevent(GPIO_GPIO2_INPUT, true, true, false, sensor_int3);
	stm32_gpiosetevent(GPIO_GPIO3_INPUT, true, true, false, sensor_int4);
	
	// Initialize timer 5
	timer =  stm32_tim_init(5);
	// Configure timer 5 for a frequency of 1000000 Hz (overflow after 4295 s)
	STM32_TIM_SETCLOCK(timer, 1000000);
	STM32_TIM_SETMODE(timer, STM32_TIM_MODE_UP | STM32_TIM_MODE_CK_INT);
    
    // Initialize timer for filter interrupt at a interval of 5ms
    timer2 = stm32_tim_init(4);
    STM32_TIM_SETISR(timer2, filter_interrupt, 0);
    STM32_TIM_ENABLEINT(timer2, 0);
    STM32_TIM_SETPERIOD(timer2, 4096);
    STM32_TIM_SETCOMPARE(timer2, 1, 5000);
    
    STM32_TIM_SETCLOCK(timer2, 1000000); // 1000000 Hz -> period: 1us
	STM32_TIM_SETMODE(timer2, STM32_TIM_MODE_UP | STM32_TIM_MODE_CK_INT);
    
    printf("[WSPEED] initialized\n");
}
Ejemplo n.º 2
0
int sif_anout_init(void)
{
    vsn_sif.tim3 = stm32_tim_init(3);
    vsn_sif.tim8 = stm32_tim_init(8);

    if (!vsn_sif.tim3 || !vsn_sif.tim8) return ERROR;

    // Use the TIM3 as PWM modulated analogue output

    STM32_TIM_SETPERIOD(vsn_sif.tim3, 5);
    STM32_TIM_SETCOMPARE(vsn_sif.tim3, GPIO_OUT_PWM_TIM3_CH, 3);

    STM32_TIM_SETCLOCK(vsn_sif.tim3, 36e6);
    STM32_TIM_SETMODE(vsn_sif.tim3, STM32_TIM_MODE_UP);
    STM32_TIM_SETCHANNEL(vsn_sif.tim3, GPIO_OUT_PWM_TIM3_CH, STM32_TIM_CH_OUTPWM | STM32_TIM_CH_POLARITY_NEG);

    // Use the TIM8 to drive the upper power mosfet

    STM32_TIM_SETISR(vsn_sif.tim8, sif_anout_isr, 0);
    STM32_TIM_ENABLEINT(vsn_sif.tim8, 0);

    STM32_TIM_SETPERIOD(vsn_sif.tim8, 4096);
    STM32_TIM_SETCOMPARE(vsn_sif.tim8, GPIO_OUT_PWRPWM_TIM8_CH, 5000);

    STM32_TIM_SETCLOCK(vsn_sif.tim8, 36e6);
    STM32_TIM_SETMODE(vsn_sif.tim8, STM32_TIM_MODE_UP);
    //STM32_TIM_SETCHANNEL(vsn_sif.tim8, GPIO_OUT_PWRPWM_TIM8_CH, STM32_TIM_CH_OUTPWM | STM32_TIM_CH_POLARITY_NEG);

    vsn_sif.i2c1 = up_i2cinitialize(1);
    vsn_sif.i2c2 = up_i2cinitialize(2);

    vsn_sif.spi2 = up_spiinitialize(2);

    return OK;
}
Ejemplo n.º 3
0
static int up_lcdirqattach(xcpt_t isr)
{
  lcddbg("%s IRQ\n", isr == NULL ? "Detach" : "Attach");

  if (isr != NULL)
    {
      STM32_TIM_SETISR(tim, up_lcdextcominisr, 0);
      g_isr = isr;
    }
  else
    {
      STM32_TIM_SETISR(tim, NULL, 0);
      g_isr = NULL;
    }

  return OK;
}
Ejemplo n.º 4
0
static int up_lcdirqattach(xcpt_t isr, void * arg)
{
  lcdinfo("%s IRQ\n", isr == NULL ? "Detach" : "Attach");

  if (isr != NULL)
    {
      STM32_TIM_SETISR(tim, up_lcdextcominisr, arg, ATIM_SR_UIF);
      g_isr = isr;
    }
  else
    {
      STM32_TIM_SETISR(tim, NULL, NULL, ATIM_SR_UIF);
      g_isr = NULL;
    }

  return OK;
}
Ejemplo n.º 5
0
/**
 * @brief System entrypoint. CONFIG_USER_ENTRYPOINT should point to this function.
 */
int timesync_init(void) {
    int rc;

    timesync_rollover_master_timer = stm32_tim_init(TIMESYNC_ROLLOVER_TIMER_MASTER_ID);
    if (!timesync_rollover_master_timer) {
        lldbg("error initializing master time-sync rollover timer #%d\n",
              TIMESYNC_ROLLOVER_TIMER_MASTER_ID);
        PANIC();
        return ERROR;
    }
    timesync_rollover_slave_timer = stm32_tim_init(TIMESYNC_ROLLOVER_TIMER_SLAVE_ID);
    if (!timesync_rollover_slave_timer) {
        lldbg("error initializing slave time-sync rollover timer #%d\n",
              TIMESYNC_ROLLOVER_TIMER_SLAVE_ID);
        PANIC();
        return ERROR;
    }

    timesync_strobe_timer = stm32_tim_init(TIMESYNC_STROBE_TIMER_ID);
    if (!timesync_strobe_timer) {
        lldbg("error initializing timesync strobe timer #%d\n",
              TIMESYNC_STROBE_TIMER_ID);
        PANIC();
        return ERROR;
    }

    /* TIM8 fundamental frequency */
    lldbg("Frame-time basic-frequency %dHz\n", STM32_TIM18_FREQUENCY);

    timesync_disable();
    timesync_rollover_timer_irq = STM32_TIM_SETISR(timesync_rollover_slave_timer,
                                                   timesync_frame_time_rollover_handler, 0);
    if (timesync_rollover_timer_irq == ERROR) {
        lldbg("Unable to latch timer #%d interrupt!\n",
              TIMESYNC_ROLLOVER_TIMER_SLAVE_ID);
        PANIC();
        return ERROR;
    }
    timesync_strobe_timer_irq = STM32_TIM_SETISR(timesync_strobe_timer,
                                                 timesync_strobe_handler, 0);
    if (timesync_strobe_timer_irq == ERROR) {
        lldbg("Unable to latch timer #%d interrupt!\n",
              TIMESYNC_STROBE_TIMER_ID);
        PANIC();
        return ERROR;
    }

#ifdef CONFIG_ARCH_TIMESYNC_DEBUG
    /* timesync_debug exists for debug and informational purposes only */
    sem_init(&dbg_thread_sem, 0, 0);

    rc = task_create("timesync_debugd", TIMESYNC_TASK_PRIORITY,
                     TIMESYNC_TASK_STACK_SIZE, timesync_debugd_main, NULL);
    if (rc == ERROR) {
        dbg_error("failed to start timesync_debugd\n");
        return rc;
    }
    timesync_debug_pid = rc;
#else
    (void)rc;
#endif

    return 0;
}