收藏 分销(赏)

threadx学习笔记专业资料.doc

上传人:精**** 文档编号:3896565 上传时间:2024-07-23 格式:DOC 页数:48 大小:132.54KB
下载 相关 举报
threadx学习笔记专业资料.doc_第1页
第1页 / 共48页
threadx学习笔记专业资料.doc_第2页
第2页 / 共48页
threadx学习笔记专业资料.doc_第3页
第3页 / 共48页
threadx学习笔记专业资料.doc_第4页
第4页 / 共48页
threadx学习笔记专业资料.doc_第5页
第5页 / 共48页
点击查看更多>>
资源描述

1、threadx学习笔记(一)tx_ill.s文献用来解决初始化过程中的汇编语言,它是面向解决器和开发工具的。Void_tx_initialize_low_level1、CPSCR|= FIQ_ MODE,SET SP_fiq;2、CPSCR|=IRQ_MODE,SET SP_irp;3、CPSCR|=SVC_MODE,SET SP_svc;4、设立中断向量表IRQ_TABLE;5、设立内部TIMER线程的堆栈起始地址,堆栈大小和优先级:tx_timer_stack_start,_tx_timer_stack_size,_tx_timer_priorit;6、设立初始化后未使用内存地址的初始值_

2、tx_initialize_unused_memory;Tx_tcs.s负责在中断发生时对上次的运营现场进行保存,它保存中断上下文,为了不覆盖R14_irq离得中断返回地址,TCS的返回是通过跳到_tx_irq_processing_return地址做到的。Tx_TCR.S负责中断解决程序执行完后的解决。Void _tx_thread_context_save1、把表达中断嵌套个数的变量_tx_thread_system_state+;2、if _tx_thread_system_state1,PUSH R0-R3,CPSR,R14 in IRQ stack,B _tx_irq_process

3、ing_return;3、else if _tx_thread_current_ptr=0判断是否有线程正在运营,if not ,B _tx_irq_processing_return;4、else,PUSH Context_irq in threads stack,SP_thread=new SP,B _tx_irq_processing_return;由于R13和R14在不同的CPU模式下相应的是不同的物理寄存器,所以若要得到中断前的线程堆栈指针,需要先返回到该线程的运营模式,同时严禁中断,取值后再返回到终端模式。R14_irq保存的是终端发生时PC值+8,R14_svc保存得失中断前线程

4、自己的返回地址。所以在中段上下文中,(R14_irq-4)应当存在中断地址,而R14_svc存在R14的位置。Void _tx_thread_context_restore1、_tx_thread_system_state-,if _tx_thread_system_state0,POP R0-R3,CPSR,R14 from IRQ stack,BX R14;2、else if _tx_thread_current_ptr=0?if =0 CPSR|=VC_MODE,CPSR|=TX_INT_ENABLE,跳到线程调度程序B _tx_thread_schedule;3、if!=0,则判断线程

5、抢占是否严禁 if _tx_thread_preempt_disable=0?if!=0,POP Context_irq from threads stack,BX R14;4、if=0,_tx_timer_time_slice=new value,_tx_thread_current_ptr=0,CPSR|=SVC_MODE,设立堆栈指针为系统指针SP=SP_svc,CPSR|=TX_INT_ENABLE;5、B _tx_thread_schedule;Tx_tsr.s用于从线程退回到系统态,负责保存线程的最小语境并退回到Threadx的调度循环状态。它保存的上下文是请求上下文。Void _

6、tx_thread_system_return1、 PUSH Context_request:in threads stack,CPSR|=TX_INT_DISABLE;2、 _tx_thread_current_ptr-SP=SP,CPSR|=SVC_MODE;3、 设立堆栈指针为系统指针SP=SP_svc,_tx_thread_current_ptr=0,CPSR|=TX_INT_ENABLE;4、 B _tx_thread_schedule;由于用户模式不能直接更改CPSR来关断的,所以要通过SWI指令进入特权模式,并且特权模式和用户模式的SP相应不同的物理寄存器,所以要在转入系统模式取

7、得用户模式下SP,最后再回到特权模式。TX_TS.S负责调度和恢复就绪的优先级最高的线程的最后语境。Void _tx_thread_schedule1、 while(_tx_thread_execute_ptr=0);2、 CPSR|=TX_INT_DISABLE,_tx_threadx_current_ptr=_tx_thread_execute_ptr;3、 _tx_thread_current_ptr-TX_run_count+,_tx_timer_time_slice=_tx_thread_current_ptr-tx_time_slice;4、 If线程堆栈的中断类型=1,resto

8、re Context_irq,else restore Context_request;Tx_tic.s用于开中断和关中断。Unint _tx_thread_interrupt_control(unint new _posture)1、 R1=CPSR;2、 SWI;3、 CPSR|=RO=new posture;4、 R0=R1,R0为返回值;移植该函数时,针对不同的解决器,应盖根据准热爱寄存器CPSR的中断严禁未来设立开关中断向量,重要修改TX_PORT.H中的TX_INT_ENABLE和TX_INT_DISABLE.R0用来传递的参数和结果。Tx_tsb.s负责创建每个线程的初始堆栈结构

9、,这个初始的结构在线程创建时会引起中断上下文返回到_tx_thread_shell_entry函数的开头。然后这个函数调用指定线程入口函数。其中断类型设立为1,表达中断上下文。Void _tx_thread_stack_build(TXTHREAD *thread_ptr,void (*function)(void)1、 保证堆栈起始地址八字节对齐;2、 中断地址存入线程调用的入口地址PUSH function_ptr;3、 R0-R12,R14的初始值都设立为0,PUSH初始值;4、 要存入堆栈的CPSR值设立为用户模式,开中断,标志位清零,R1=USER_MODE,PUSH R1;5、 T

10、hread_ptr-sp=new SP;当解决一个低档的中断时,tx_tpc.s决定是否发生抢占,它是可选的,大多数端口都用不到。TX_TIMIN.S负责解决定期中断。这两个函数只要将它们翻译成相应ARM汇编语言就可以了。threadx学习笔记(二)-1tx_kernel_enter();进入threadx核tx_kernel_enter()void tx_kernel_enter(void)所属文献调用者开关量demo.C启动代码无操作系统一方面从从量表直接进入该函数,在函数以前没有进行任何的硬件及软件的初始化!该函数重要包含_tx_initialize_low_level(),_tx_in

11、itialize_high_level(),tx_application_define(_tx_initialize_unused_memory),_tx_thread_schedule()。VOID _tx_initialize_kernel_enter(VOID)/*拟定编译器是否已经初始化过 */if (_tx_thread_system_state != TX_INITIALIZE_ALMOST_DONE)/* 没有初始化的话执行下面程序 */* 设立系统状态变量来表达现正在解决过程中 注意该变量在后边的中断嵌套中会使用*/_tx_thread_system_state = TX_IN

12、ITIALIZE_IN_PROGRESS;/* 进行一些基本硬件设立,启动程序等 */_tx_initialize_low_level();/*进行一些高级的初始化*/_tx_initialize_high_level();/*设立系统状态变量来表达现正在解决过程中 注意该变量在后边的中断嵌套中会使用*/_tx_thread_system_state = TX_INITIALIZE_IN_PROGRESS;/* 调用初始化中提供的应用程序 把第一个未使用的变量地址传送给它 */tx_application_define(_tx_initialize_unused_memory);/*设立系统壮

13、伟进入线程调度做准备*/_tx_thread_system_state = TX_INITIALIZE_IS_FINISHED;/* 进入线程循环开始执行线程 */_tx_thread_schedule();_tx_initialize_low_level()void tx_kernel_enter(void)所属文献调用者开关量tx_till.s启动代码无该函数实现对FIQ、IRQ和SVC模式下的sp寄存器的初始化,并对定期堆栈的基地址、大小和定期优先级变量进行初始化。/* 进行一些基本硬件设立,启动程序等 */*该函数在文献tx_ill.s文献中*/_tx_initialize_low_l

14、evel();/* VOID _tx_initialize_low_level(VOID);EXPORT _tx_initialize_low_level_tx_initialize_low_level; /* 保存系统堆栈指针. */; /* _tx_thread_system_stack_ptr = (VOID_PTR) A7 (SP); */;/*设立各个模式下的sp(堆栈指针)*/; /* We must be in SVC mode at this point! */;LDR a2, =|Image$ZI$Limit| ; Get end of non-initialized RAM

15、 areaLDR a3, pc, #FIQ_STACK_SIZE-.-8 ; 获得FIO堆栈地址(这里没有弄明白,有待?)MOV a1, #FIQ_MODE ; 设立FIQ_MODEMSR CPSR_c, a1 ; 进入FIQ模式ADD a2, a2, a3 ;计算FIQ堆栈的开始BIC a2, a2, #3 ; 将a2的低两位清零保证堆栈的的开始为long对齐SUB a2, a2, #4 ; 往回退一个字MOV sp, a2 ; 建立FIQ 堆栈指针(即FIQ模式的sp)MOV sl, #0 ; Clear sl(R10)MOV fp, #0 ; Clear fp(R11)LDR a3, p

16、c, #SYS_STACK_SIZE-.-8 ;获得 IRQ (system stack size)MOV a1, #IRQ_MODE ; 建立IRQ模式的 CPSRMSR CPSR_c, a1 ; 进入IRQ模式ADD a2, a2, a3 ; 计算IRQ stack的开始BIC a2, a2, #3 ; 将a2的低两位清零保证堆栈的的开始为long对齐SUB a2, a2, #4 ; 往回退一个字MOV sp, a2 ; 建立 IRQ 堆栈指针MOV a1, #SVC_MODE ; 建立SVC模式的CPSRMSR CPSR_c, a1 ; 进入 SVC模式LDR a4, pc, #SYS_

17、STACK_PTR-.-8 ; 获得stack 指针STR a2, a4, #0 ; 保存系统堆栈; /* Save the system stack pointer. */; _tx_thread_system_stack_ptr = (VOID_PTR) (sp);LDR a2, pc, #SYS_STACK_PTR-.-8 ; 获得系统堆栈指针的地址LDR a1, a2, #0 ; 获得系统堆栈指针 ADD a1, a1, #4 ; 增长一个long长度; /* Pickup the first available memory address. */; /* Allocate spac

18、e for the timer threads stack. */; _tx_timer_stack_start = first_available_memory; _tx_timer_stack_size = stack_size; _tx_timer_priority = 0;LDR a2, pc, #TIMER_STACK-.-8 ; 获得定期堆栈指针地址LDR a4, pc, #TIMER_STACK_SIZE-.-8 ; 获得定期堆栈大小地址LDR a3, pc, #TIM_STACK_SIZE-.-8 ; 获得实际定期堆栈大小STR a1, a2, #0 ;将定期堆栈的基地址放在堆

19、栈指针地址所相应的内存中STR a3, a4, #0 ; 存储定期器堆栈大小ADD a1, a1, a3 ; 新的空内存地址LDR a2, pc, #TIMER_PRIORITY-.-8 ; 获得定期器优先级地址MOV a3, #0 ; 获得定期器线程优先级STR a3, a2, #0 ; 存储定期器线程优先级; /*保存第一个变量内存地址. */; _tx_initialize_unused_memory = (VOID_PTR) System Stack + Timer Stack;LDR a3, pc, #UNUSED_MEMORY-.-8 ;获得没有使用的内存指针地址STR a1, a

20、3, #0 ; 保存第一个空内存地址; /* 建立周期性的定期中断. */STMDB LR/让lr入栈,保护lrBLTargetInit/TargetInit()为C语言编写的中断定期函数LDMIA lr/让lr出栈在这里加上ARM定期器已实现周期性的中断; /* Done, return to caller. */;MOV pc, lr ; Return to caller;_tx_irq_handler所属文献调用者开关量tx_till.s IRQ中断无该函数是在定期中断后调用,该函数调用了_tx_thread_context_save函数(包含在tx_tcs.s中),该函数又调用到_tx

21、_irq_processing_return函数处(包含在tx_till.s)EXPORT _tx_irq_handlerEXPORT _tx_irq_processing_return _tx_irq_handler; /* 调用函数保存线程上下文环境. */B _tx_thread_context_save_tx_irq_processing_return; /* At this point execution is still in the IRQ mode. The CPSR, point of; interrupt, and all C scratch registers are a

22、vailable for use. In ; addition, IRQ interrupts may be re-enabled - with certain restrictions -; if nested IRQ interrupts are desired. Interrupts may be re-enabled over; small code sequences where lr is saved before enabling interrupts and ; restored after interrupts are again disabled. */; /* For d

23、ebug purpose, execute the timer interrupt processing here. In; a real system, some kind of status indication would have to be checked; before the timer interrupt handler could be called. */;BL clearflag;清除中断标志位很重要(自己移植时加的,位置是否恰当?)BL _tx_timer_interrupt ; 定期中断解决函数; /* 系统线程上下文环境恢复函数 */B _tx_thread_con

24、text_restore_tx_timer_interrupt所属文献调用者开关量tx_timin.s启动代码无该函数重要是中断后将系统时钟加1,时间切片减1。定期部分比较多,没有完全看明白。IMPORT _tx_timer_time_sliceIMPORT _tx_timer_system_clockIMPORT _tx_timer_current_ptrIMPORT _tx_timer_list_startIMPORT _tx_timer_list_endIMPORT _tx_timer_expired_time_sliceIMPORT _tx_timer_expiredIMPORT _t

25、x_timer_threadIMPORT _tx_thread_current_ptrIMPORT _tx_thread_time_sliceIMPORT _tx_thread_resumeIMPORT _tx_thread_preempt_disable;PRESERVE8AREA |C$code|, CODE, READONLY|x$codeseg| DATA;VOID _tx_timer_interrupt(VOID);EXPORT _tx_timer_interrupt_tx_timer_interrupt; /* Upon entry to this routine, it is a

26、ssumed that context save has already; been called, and therefore the compiler scratch registers are available; for use. */; /* Increment the system clock. */; _tx_timer_system_clock+;LDR a2, pc, #SYSTEM_CLOCK-.-8 ; 获得系统时钟地址LDR a1, a2, #0 ; 获得系统时钟ADD a1, a1, #1 ; 将系统时钟加1STR a1, a2, #0 ; 存储新的系统时钟时间; /

27、* Test for time-slice expiration. */; if (_tx_timer_time_slice); ;LDR a4, pc, #TIME_SLICE-.-8 ; 获得链表中的定期切片数地址LDR a3, a4, #0 ; 获得定期切片数的值CMP a3, #0 ; 定期切片是否有效,0有效,=0无效BEQ _tx_timer_no_time_slice ; =0时,跳到_tx_timer_no_time_slice处; /* 时间切片减1. */; _tx_timer_time_slice-;SUB a3, a3, #1 ; 时间切片值减1STR a3, a4,

28、#0 ; 存储新的时间切片值; /* 检查是否到期. */; if (_tx_timer_time_slice = 0);CMP a3, #0 ; 0还是=0?BNE _tx_timer_no_time_slice ; 假如0,;当没有定期切片时,将定期切片数标志位置1,表达链表中没有切片了。; /* Set the time-slice expired flag. */; _tx_timer_expired_time_slice = TX_TRUE;LDR a4, pc, #EXPIRED_TIME_SLICE-.-8 ; 获得定期切片数是否为0标志地址MOV a1, #1 ; 将标志设为1

29、STR a1, a4, #0 ; 设立届时标志; ;_tx_timer_no_time_slice; /* Test for timer expiration. */; if (*_tx_timer_current_ptr); ;LDR a2, pc, #TIMER_CURRENT_PTR-.-8 ; 获得的是_tx_timer_current_ptr的地址;而TIMER_DECLARE TX_INTERNAL_TIMER *_tx_timer_current_ptr;LDR a1, a2, #0 ; 获得当前的_tx_timer_current_ptrLDR a3, a1, #0 ; 获得定

30、期列表的入口定期切片指针CMP a3, #0 ;链表中是否有定期切片存在BEQ _tx_timer_no_timer ; 不存在, 调用_tx_timer_no_time将;_tx_timer_current_ptr+; /* Set expiration flag. */; _tx_timer_expired = TX_TRUE;LDR a4, pc, #EXPIRED-.-8 ; Pickup expriation flag addressMOV a3, #1 ; Build expired valueSTR a3, a4, #0 ; Set expired flagB _tx_timer

31、_done ; Finished timer processing; ; else; _tx_timer_no_timer; /* No timer expired, increment the timer pointer. */; _tx_timer_current_ptr+;ADD a1, a1, #4 ; Move to next timer; /* Check for wrap-around. */; if (_tx_timer_current_ptr = _tx_timer_list_end);LDR a4, pc, #LIST_END-.-8 ; Pickup addr of ti

32、mer list endLDR a3, a4, #0 ; Pickup list endCMP a1, a3 ; Are we at list end?BNE _tx_timer_skip_wrap ; No, skip wrap-around logic; /* Wrap to beginning of list. */; _tx_timer_current_ptr = _tx_timer_list_start;LDR a4, pc, #LIST_START-.-8 ; Pickup addr of timer list startLDR a1, a4, #0 ; Set current p

33、ointer to list start;_tx_timer_skip_wrap;STR a1, a2, #0 ; Store new current timer pointer; ;_tx_timer_done; /* See if anything has expired. */; if (_tx_timer_expired_time_slice) | (_tx_timer_expired); ;LDR a4, pc, #EXPIRED_TIME_SLICE-.-8 ; Pickup addr of expired flagLDR a3, a4, #0 ; Pickup time-slic

34、e expired flagCMP a3, #0 ; Did a time-slice expire?BNE _tx_something_expired ; If non-zero, time-slice expiredLDR a2, pc, #EXPIRED-.-8 ; Pickup addr of other expired flagLDR a1, a2, #0 ; Pickup timer expired flagCMP a1, #0 ; Did a timer expire?BEQ _tx_timer_nothing_expired ; No, nothing expired;_tx_

35、something_expired;STR lr, sp, #-4! ; Save the lr register on the stack; /* Did a timer expire? */; if (_tx_timer_expired); ;LDR a2, pc, #EXPIRED-.-8 ; Pickup addr of expired flagLDR a1, a2, #0 ; Pickup timer expired flagCMP a1, #0 ; Check for timer expirationBEQ _tx_timer_dont_activate ; If not set,

36、 skip timer activation; /* Increment the preempt disable counter in preparation for ; thread resumption. */; _tx_thread_preempt_disable+;LDR a4, pc, #PREEMPT_DISABLE-.-8 ; Pickup addr of preempt disable LDR a3, a4, #0 ; Pickup actual flagADD a3, a3, #1 ; Incrment the preempt disable countSTR a3, a4,

37、 #0 ; Store it back; /* Activate the system timer thread. */; _tx_thread_resume(&_tx_timer_thread);LDR a1, pc, #TIMER_THREAD-.-8 ; Get timer thread control block addrBL _tx_thread_resume ; Call thread resume to wake up the; timer thread; _tx_timer_dont_activate; /* Did time slice expire? */; if (_tx

38、_timer_expired_time_slice); ;LDR a4, pc, #EXPIRED_TIME_SLICE-.-8 ; Pickup addr of time-slice expired LDR a3, a4, #0 ; Pickup the actual flagCMP a3, #0 ; See if the flag is setBEQ _tx_timer_not_ts_expiration ; No, skip time-slice processing; /* Time slice interrupted thread. */; if (!_tx_thread_time_

39、slice(); _tx_timer_time_slice = _tx_thread_current_ptr - tx_time_slice;BL _tx_thread_time_slice ; Call time-slice processingCMP a1, #0 ; Check return statusBNE _tx_timer_not_ts_expiration ; If time-sliced, skip reset processingLDR a2, pc, #CURRENT_PTR-.-8 ; Pickup addr of current thread pointerLDR a

40、1, a2, #0 ; Pickup thread pointerLDR a3, a1, #24 ; Pickup fresh time-slice for thread; (a fresh time slice was setup in ; the _tx_thread_time_slice function)LDR a4, pc, #TIME_SLICE-.-8 ; Pickup addr of time-slice variableSTR a3, a4, #0 ; Setup new time-slice; ;_tx_timer_not_ts_expiration;LDR a4, pc,

41、 #EXPIRED_TIME_SLICE-.-8 ; Pickup address of expired time-slice flagMOV a1, #0 ; Clear valueSTR a1, a4, #0 ; Clear time-slice expired flag;LDR lr, sp, #4 ; Recover lr register; ;_tx_timer_nothing_expired;MOV pc, lr ; Return to caller;TIME_SLICEDCD _tx_timer_time_sliceSYSTEM_CLOCKDCD _tx_timer_system

42、_clockTIMER_CURRENT_PTRDCD _tx_timer_current_ptrLIST_STARTDCD _tx_timer_list_startLIST_ENDDCD _tx_timer_list_endEXPIRED_TIME_SLICEDCD _tx_timer_expired_time_sliceEXPIREDDCD _tx_timer_expiredTIMER_THREADDCD _tx_timer_threadCURRENT_PTRDCD _tx_thread_current_ptrTHREAD_TIME_SLICEDCD _tx_thread_time_sliceRESUMEDCD _t

展开阅读全文
部分上传会员的收益排行 01、路***(¥15400+),02、曲****(¥15300+),
03、wei****016(¥13200+),04、大***流(¥12600+),
05、Fis****915(¥4200+),06、h****i(¥4100+),
07、Q**(¥3400+),08、自******点(¥2400+),
09、h*****x(¥1400+),10、c****e(¥1100+),
11、be*****ha(¥800+),12、13********8(¥800+)。
相似文档                                   自信AI助手自信AI助手
百度文库年卡

猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服