コード例 #1
0
ファイル: imx_i2c.c プロジェクト: art1/FloatSat-Project-G9
static void set_i2c_clock(uint32_t instance, uint32_t baud)
{
    // Adjust the divider to get the closest SCL frequency to baud rate 
    uint32_t src_clk = get_main_clock(IPG_PER_CLK);
    uint32_t divider = src_clk / baud;
    uint8_t index = 0;
    
    if (divider < i2c_freq_div[0][0])
    {
        divider = i2c_freq_div[0][0];
        index = 0;
      /*  debug_printf("Warning :can't find a smaller divider than %d.\n", divider);
        debug_printf("SCL frequency is set at %d - expected was %d.\n", src_clk/divider, baud);
        */
    }
    else if (divider > i2c_freq_div[49][0])
    {
        divider = i2c_freq_div[49][0];
        index = 49;
        /*
        debug_printf("Warning: can't find a bigger divider than %d.\n", divider);
        debug_printf("SCL frequency is set at %d - expected was %d.\n", src_clk/divider, baud);
        */
    }
    else
    {
        for (index = 0; i2c_freq_div[index][0] < divider; index++);
        divider = i2c_freq_div[index][0];
    }
    
    HW_I2C_IFDR_WR(instance, BF_I2C_IFDR_IC(i2c_freq_div[index][1]));
}
コード例 #2
0
ファイル: board.c プロジェクト: Davidfind/rt-thread
int rt_hw_timer_init(void)
{
    uint32_t freq;

    // Make sure the timer is off.
    HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 0;
    
    HW_ARMGLOBALTIMER_CONTROL.B.FCR0 =1;
    
    HW_ARMGLOBALTIMER_CONTROL.B.FCR1 =0;
    
    HW_ARMGLOBALTIMER_CONTROL.B.DBG_ENABLE =0;
    
    // Clear counter.
    HW_ARMGLOBALTIMER_COUNTER_HI_WR(0);
    HW_ARMGLOBALTIMER_COUNTER_LO_WR(0);
    
    // Now turn on the timer.
    HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 1;

    freq = get_main_clock(IPG_CLK);

    epit_init(HW_EPIT1, CLKSRC_IPG_CLK, freq / 1000000,
              SET_AND_FORGET, 10000, WAIT_MODE_EN | STOP_MODE_EN);

    epit_counter_enable(HW_EPIT1, 10000, IRQ_MODE);

    rt_hw_interrupt_install(IMX_INT_EPIT1, rt_hw_timer_isr, RT_NULL, "tick");
    rt_hw_interrupt_umask(IMX_INT_EPIT1);

    return 0;
}
コード例 #3
0
ファイル: board.c プロジェクト: DigFarmer/rt-thread
int rt_hw_timer_init(void)
{
    uint32_t freq;
    // The ARM private peripheral clock is half the CPU clock.
    uint32_t periphClock = get_main_clock(CPU_CLK) / 2;
    uint32_t prescaler = (periphClock / 1000000) - 1;

    // Divide down the prescaler until it fits into 8 bits. We add up the number of ticks
    // it takes to equal a microsecond interval.
    while (prescaler > 0xff)
    {
        prescaler /= 2;
    }

    // Make sure the timer is off.
    HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 0;

    // Clear counter.
    HW_ARMGLOBALTIMER_COUNTERn_WR(0, 0);
    HW_ARMGLOBALTIMER_COUNTERn_WR(1, 0);

    // Set prescaler and clear other flags.
    HW_ARMGLOBALTIMER_CONTROL_WR(BF_ARMGLOBALTIMER_CONTROL_PRESCALER(prescaler));

    // Now turn on the timer.
    HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 1;

    freq = get_main_clock(IPG_CLK);
    epit_init(HW_EPIT1, CLKSRC_IPG_CLK, freq / 1000000,
              SET_AND_FORGET, 10000, WAIT_MODE_EN | STOP_MODE_EN);

    epit_counter_enable(HW_EPIT1, 10000, IRQ_MODE);

    rt_hw_interrupt_install(IMX_INT_EPIT1, rt_hw_timer_isr, RT_NULL, "tick");
    rt_hw_interrupt_umask(IMX_INT_EPIT1);

    return 0;
}