2014-03-06 40 views
2

我在omap4460(cortex a9)上編寫裸機代碼(no os),並且我沒有成功正確設置gptimer1。在omap4460上設置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」作品。

我什至不看到計時器計數器運行。

請問我有什麼想法嗎? Rony。

回答

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; 

最好的問候,

羅尼

1

您是否檢查過定時器模塊已上電並且定時器模塊的時鐘已啓用?時鐘源的選擇在電源,復位和時鐘管理(PRCM)模塊(TRM的第3章)中進行。

如果您尚未啓用電源併爲PRCM模塊中的定時器外設模塊配置了時鐘源,則定時器將不會執行任何操作。

+0

@Pipenbrinck我已經相應修改我的代碼,請參閱我的回答 – bonpiedlaroute