2

我在omap4460(皮质a9)上编写裸机代码(无操作系统),但我没有成功设置正确的gptimer1。

这是我的代码(遵循 OMAP4460 TRM)

/* for forwarding pending interrupts from distributor to Cpu interfaces */
*(volatile unsigned int *)(GICD_BASE + GICD_CTLR ) |= 0x00000001;

/* signaling interrupt by the cpu interface to the connected processor*/
*(volatile unsigned int *)(GICC_BASE + GICC_CTLR ) |= 0x00000001;

/* position the timer1 handler */
irq_table_function[GPT1_IRQ] = timer1handler;

/* clocks timer1 block */
*(volatile unsigned int *)CM_WKUP_CLKSTCTRL |= 0x00000003;
*(volatile unsigned int *)CM_WKUP_GPTIMER1_CLKCTRL |= 0x01000000;
*(volatile unsigned int *)CM_WKUP_GPTIMER1_CLKCTRL |= 0x00000002;

/* enable GPTimer1 functional and interface blocks */
*(volatile unsigned int *)GPT1MS_TIOCP_CFG |= 0x00000300;

/* capture interrupt enable */
*(volatile unsigned int *)GPT_TIER |= 0x00000004;

/* enable autoreload */
*(volatile unsigned int *)GPT_TCLR |= 0x00000002;

/* prescaler equal to zero */
*(volatile unsigned int *)GPT_TCLR &= ~0x0000003C;

/* positive increment value */
*(volatile unsigned int *)GPT_TPIR = 232000;

/* negative increment value */
*(volatile int *)GPT_TNIR = -768000;

/* load value */
*(volatile unsigned int *)GPT_TLDR = 0xFFFFFFE0;

/* enable timer1 */
*(volatile unsigned int *)GPT_TIER |= 0x00000001;

当我运行代码时,我从不去我的中断向量表,我的中断向量表设置正确,因为“svc 0”有效。

我什至没有看到计时器在运行。

请任何想法,我错过了什么?罗尼。

4

2 回答 2

1

我终于得到了正确的初始化序列,但忘记发回我的代码。

这就是我初始化gptimer1的方式,希望它可以帮助

/* clocks timer1 block */
    *(volatile unsigned int *)CM_WKUP_CLKSTCTRL |= 0x00000003;

    *(volatile unsigned int *)CM_WKUP_GPTIMER1_CLKCTRL &= ~0x01000000;
    *(volatile unsigned int *)CM_WKUP_GPTIMER1_CLKCTRL |= 0x00000002;

   /* enables for forwarding pending interrupts from distributor
      to Cpu interfaces */
    *(volatile unsigned int *)(GICD_BASE + GICD_CTLR ) |= 0x00000003;

    /* set the priority of the interrupt */
    *(volatile unsigned int *)(GICD_BASE + GICD_IPRIORITYR_IRQ37 ) |= 0x00000200;
    /* set enable bit of IRQ37 */
    *(volatile unsigned int *)(GICD_BASE + GICD_ISENABLER37) |= 0x00000002;

    /* enables signaling interrupt by the cpu interface to the connected processor*/
    *(volatile unsigned int *)(GICC_BASE + GICC_CTLR ) |= 0x00000003;

    /* interrupt priority mask */
    *(volatile unsigned int *)(GICC_BASE + GICC_PMR ) = 0x00000080;

    /* forward the interrupt only to the processor which request the interrupt */
    *(volatile unsigned int *)(GICD_BASE + GICD_SGIR) |= 0x02000000;

    /* software reset */
    *(volatile unsigned int *)GPT1MS_TIOCP_CFG |= 0x00000002;

    /* RESET & Power settings*/
    /* wait until reset release */
    while( (*(volatile unsigned int *)GPT_TISTAT & 0x00000001) == 0)
        waitingtime++;
    /*GPT1MS_TIOCP_CFG [0]AUTOIDLE =0x0 : L4 clock free-running*/
    *(volatile unsigned int *)GPT1MS_TIOCP_CFG &= ~(0x1 << 0);
    /* idle mode equals to no-idle mode */
    *(volatile unsigned int *)GPT1MS_TIOCP_CFG |= 0x00000008;
    /*Functional clock is maintained during wake-up period */
    *(volatile unsigned int *)GPT1MS_TIOCP_CFG |= 0x00000300;
    /*NO Wake-up line assertion GPT1MS_TIOCP_CFG[2]ENAWAKEUP=0x0*/
    *(volatile unsigned int *)GPT1MS_TIOCP_CFG &= ~(0x1 << 2) ;
    /*GPT1MS_TIOCP_CFG [5]EMUFREE =0x1 : Timer counter free running in emulation*/
    *(volatile unsigned int *)GPT1MS_TIOCP_CFG |= (0x1 << 5);

    /* Enable wake-up interrupt events */
    *(volatile unsigned int *)GPT_TWER |= 0x00000007;
    /* Posted mode active */
    *(volatile unsigned int *)GPT_TSICR |= 0x00000004;
    /* enable autoreload */
    *(volatile unsigned int *)GPT_TCLR |= 0x00000002;

    /* set prescale clock timer value (PTV) to 1 */
    /* set PREscaler =128
and thus FCLK=38.4 MHz / 128 = 300 KHz << OCPCLK=38.4 / 4 = 9.6 MHz */
    *(volatile unsigned int *)GPT_TCLR |= 0x00000018;
    /* enable prescaler */
    *(volatile unsigned int *)GPT_TCLR |= 0x00000020;
    /* Overflow interrupt enable */
    *(volatile unsigned int *)GPT_TIER |= 0x00000007;

    /* Load timer counter value */
    *(volatile unsigned int *)GPT_TCRR = 0xFD000000;

    /* load value */
    *(volatile unsigned int *)GPT_TLDR = 0xFFE00000;


    *(volatile unsigned int *)GPT_TPIR = 232000;
    /* negative increment value */
    *(volatile int *)GPT_TNIR = 0xFFF44800;

    /* we position the timer1 handler */
     irq_table_function[GPT1_IRQ] = timer1handler;

    /* enable timer1 */
    *(volatile unsigned int *)GPT_TCLR |= 0x00000001;

此致,

罗尼

于 2014-03-13T08:36:01.813 回答
1

您是否检查过定时器模块已通电并且定时器模块的时钟已启用?时钟源的选择是在电源、复位和时钟管理 (PRCM) 模块中进行的(TRM 的第 3 章)。

如果您没有为PRCM模块中的定时器外设模块启用电源并配置时钟源,定时器将什么也不做。

于 2014-03-12T08:27:45.917 回答