一直想学习下ucos,下载了不少资料,最近才开始抽空看看。
虽然源代码没有完全看明白,但是可以从官网上下载到 Microchip 的dsPIC33JP 系列单片机的一个例子程序。连接地址: http://micrium.com/download/micrium_dspic33_ucos-ii/
dsPIC33JP 与dsPIC33EP 比较相似,直接从这个例子程序上修改就可以了。最关键的是 CPU寄存器出栈和入栈的汇编代码,在文件os_cpu_util_a.s中可以找到这两个宏定义以及具体代码。
.macro OS_REGS_SAVE ; Start of Macro
push.d w0 ; Push W0 and W1 onto the stack
push.d w2 ; Push W2 and W3 onto the stack
push.d w4 ; Push W4 and W5 onto the stack
push.d w6 ; Push W6 and W7 onto the stack
push.d w8 ; Push W8 and W9 onto the stack
push.d w10 ; Push W10 and W11 onto the stack
push.d w12 ; Push W12 and W13 onto the stack
push w14 ; Push W14 **ONLY** onto the stack
push ACCAL ; Push Accumulator A onto the stack
push ACCAH ; Push Accumulator A onto the stack
push ACCAU ; Push Accumulator A onto the stack
push ACCBL ; Push Accumulator B onto the stack
push ACCBH ; Push Accumulator B onto the stack
push ACCBU ; Push Accumulator B onto the stack
push TBLPAG ; Push the Table Page Register onto the stack
;push PSVPAG ; Push the Program Space Visibility Register onto the stack
push DSRPAG
push DSWPAG
push RCOUNT ; Push the Repeat Loop Counter Register onto the stack
push DCOUNT ; Push the Do Loop Counter Register onto the stack
push DOSTARTL ; Push the Do Loop Start Address Register onto the stack
push DOSTARTH ; Push the Do Loop Start Address Register onto the stack
push DOENDL ; Push the Do Loop End Address Register onto the stack
push DOENDH ; Push the Do Loop End Address Register onto the stack
push SR ; Push the CPU Status Register onto the stack
push CORCON ; Push the Core Control Register onto the stack
.endm ; End of Macro
比较E和F系列的CPU寄存器表,只有一点点区别F系列的寄存器 PSVPAG ,在E系列变成了 DSRPAG,DSWPAG 两个,其它都一样。
这个改好之后,然后就是 头文件修改。例子代码中用的是 Mplab C30编译器,这个编译器没有 dsPIC33E系列的头文件定义,所以这里改为 XC16编译器,在安装目录中可以找到相应的头文件。另外例子程序用的芯片用256K的flash和30720B的RAM,程序编译出来也比较大。如果用dsPIC33EP64MC204,还要删掉源代码中的一些不必要的语句,否则会出现编译错误,具体不知是flash不足还是RAM不知。
目前修改好的程序可以交替点亮两个LED灯,其他应用还有待进一步学习。