开发工具:
文件大小: 124kb
下载次数: 0
上传时间: 2019-08-11
详细说明: 不超过100行的FReeRTOS,只有核心代码。只适合转牛角尖者,研究FReeRTOS原理者。 #include "task.h" #include "usart.h" TCB *TCBCur; u32 Prio_t = 0; TCB TCBL[64]; void task_create(void (* task)(void ),u32 *STK,u32 prio) { TCBCur = &TCBL;[prio]; *(--STK) = 1<<24; *(--STK) = ( u32 ) task; TCBL[prio].stkPtr = STK-14; } void CtxSw( void ) { TCBCur = &TCBL;[ Prio_t ]; } u8 STK_SizeChk(u32 *STK) { u32 i=0; while(!*STK++)i++; return i; } __asm void OSstart( void ) { extern TCBCur; PRESERVE8 ldr r3, =TCBCur /* Obtain location of TCBCur. */ ldr r1, [r3] ldr r0, [r1] /* The first item in TCBCur is the task top of stack. */ adds r0, #32 /* Discard everything up to r0. */ msr psp, r0 /* This is now the new top of stack to use in the task. */ movs r0, #2 /* Switch to the psp stack. */ msr CONTROL, r0 pop {r0-r5} /* Pop the registers that are saved automatically. */ mov lr, r5 /* lr is now in r5. */ cpsie i /* The first task has its context and interrupts can be enabled. */ pop {pc} /* Finally, pop the PC to jump to the user defined task code. */ ALIGN } __asm void PendSV_Handler( void ) { extern CtxSw extern TCBCur PRESERVE8 mrs r0, psp ldr r3, =TCBCur /* Get the location of the current TCB. */ ldr r2, [r3] subs r0, #32 /* Make space for the remaining low registers. */ str r0, [r2] /* Save the new top of stack. */ stmia r0!, {r4-r7} /* Store the low registers that are not saved automatically. */ mov r4, r8 /* Store the high registers. */ mov r5, r9 mov r6, r10 mov r7, r11 stmia r0!, {r4-r7} push {r3, r14} cpsid i bl CtxSw cpsie i pop {r2, r3} /* lr goes in r3. r2 now holds tcb pointer. */ ldr r1, [r2] ldr r0, [r1] /* The first item in TCBCur is the task top of stack. */ adds r0, #16 /* Move to the high registers. */ ldmia r0!, {r4-r7} /* Pop the high registers. */ mov r8, r4 mov r9, r5 mov r10, r6 mov r11, r7 msr psp, r0 /* Remember the new top of stack for the task. */ subs r0, #32 /* Go back for the low registers that are not automatically restored. */ ldmia r0!, {r4-r7} /* Pop low registers. */ bx r3 ALIGN }
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
相关搜索: