能否有人给我展示一个在没有实时操作系统或Linux操作系统的裸机环境下如何使用C或内联汇编来设置ARM9中断向量表的例子呢?
具体来说,我该如何使用内联汇编或C将分支设置到我的用C编写的IRQ中断处理程序ISR上呢?
/// timer1 64-bit mode interrupt handler connected to TINT2 interrupt=#34
/// \todo I think I need to ACK it once I get working
interrupt void interruptHandlerTimer1(void) {
printf("\n [* ISR *] \n");
// ACK TINT2 interrupt #34
AINTC ->IRQ1 = 1 << (34 - 32);
}
void main(void) {
TIMER1 ->TCR = 0x00000000;
// TGCR: TIMMODE=0 64-bit GP, TIM34RS=TIM12RS=1
TIM0ER1 ->TGCR = 0x00000003;
TIMER1 ->TIM34 = 0x00000000;
TIMER1 ->TIM12 = 0x00000000;
TIMER1 ->PRD34 = 0x00000000;
TIMER1 ->PRD12 = 0x0000ffff;
// TCR: inc until period match, then reset
TIMER1 ->TCR = (2 << 6);
// This is wrong.
// I think I need to insert opcode or assembly to branch to interruptHandlerTimer1 ?
// AINTC ->EABASE located @ 0x00000000
uint32_t** ptrEabase = (uint32_t**) (AINTC ->EABASE);
ptrEabase[34] = (uint32_t*) (interruptHandlerTimer1);
// Set INT34 TINT2 to IRQ priority 2
AINTC ->INTPRI4 = 0x00000200;
// Enable INT34
AINTC ->EINT1 = (1 << (34 - 32));
// Enable IRQ in CPSR
// "TMS32DM644x ARM Subsystem", 3.3 Processor Status registers
asm(" ;Enable IRQ in CPSR");
asm(" mrs r0, cpsr");
asm(" bic r0, r0, #0x80");
asm(" msr cpsr_c, r0");
// I expected to see " [* ISR *] " print
// when TIMER1->TIM12 reaches 0x0000ffff
while (1) {
printf("%08x %08x\r\n", TIMER1 ->TIM34, TIMER1 ->TIM12);
}
}
提前感谢任何提示或指导。
很难找到针对ARM9的裸机开发示例。
Ed
- TI TMS320DM6466
- Code Composer Studio v5.5
ldr pc,[pc,#offset]
。您有像VEC_IRQ
等的数组索引。填充表并将值设置为[pc,#offset]
到您实际的'C'例程。您必须使用函数属性,例如__attribute__(("interrupt"))
。请参见:FIQ vs IRQ。 - artless noise__attribute(("interrupt"))
可以在gcc中给出正确的返回代码,例如subs pc,lr,#4
;你的工具需要类似的东西,否则你需要保存寄存器并返回到一些执行适当返回的汇编程序。 - artless noise