RT-Thread for AT91SAM9260 移植手记
需要实现的函数
-
rt_base_t rt_hw_interrupt_disable(void);
-
关中断,并返回之前的中断状态
-
-
void rt_hw_interrupt_enable(rt_base_t level);
-
开中断,参数为中断状态,一般为rt_hw_interrupt_disable的返回值
-
-
void rt_hw_context_switch_to(rt_uint32_t to);
-
上下文切换: 切换至to,用于系统启动时第一个线程的启动
-
-
void rt_hw_context_switch(rt_uint32_t from, rt_uint32_t to);
-
上下文切换: 由from切换到to,用于线程正常执行时被自己把自己挂起时切换
-
-
void rt_hw_context_switch_interrupt(rt_uint32_t from, rt_uint32_t to);
-
上下文切换: 在中断状态下由from切换到to.
-
一般在本函数中并不切换,只记录需要切换的from,to两个线程的信息,待中断退出后再执行真正的切换.
-
-
-
注:arm926ej-s和arm920t比较相近,这部分可以直接使用arm920t的实现
-
需要系统提示的服务
-
tick
-
at91sam9260平台采用了PIT定时器提供系统时钟服务,默认定时周期为10ms,即每秒tick数为100.
-
-
rt_kprintf打印(非必要,用于方便调试)
-
at91sam9260芯片总共有7个串口,其中包含一个DBGU,4个USART,2个UART。
-
rt-thread使用DBGU作为调试串口,波特率为115200,rt_kprintf和finsh都使用DBGU输入输出信息。
-
系统使用注意事项
-
中断向量注册使用注意事项
-
at91sam9260总共有32个中断源,system module共用sys中断,即中断0,每组GPIO共用一个中断源,总共有3组GPIO,因此有3个中断源用于GPIO中断。at91sam9260有96个GPIO,每个GPIO都可以配置为电平变化中断,rt-thread实现了所有这些中断的注册。使用方法如下:
属于系统的32个中断源直接使用以下接口 rt_hw_interrupt_install(int vector, rt_isr_handler_t new_handler, rt_isr_handler_t *old_handler); at91_gpio_irq_mask(int vector); at91_gpio_irq_umask(int vector); 对于GPIO中断,需要对以上函数的第一个参数vector需要做以下转换,即 vector = gpio_to_irq(pin name);其中pin name取值范围为AT91_PIN_PA0~AT91_PIN_PA31, AT91_PIN_PB0~AT91_PIN_PB31,AT91_PIN_PC0~AT91_PIN_PC31.