怎样写监控程序

上传人:ji****72 文档编号:45510447 上传时间:2018-06-17 格式:PDF 页数:31 大小:165.58KB
返回 下载 相关 举报
怎样写监控程序_第1页
第1页 / 共31页
怎样写监控程序_第2页
第2页 / 共31页
怎样写监控程序_第3页
第3页 / 共31页
怎样写监控程序_第4页
第4页 / 共31页
怎样写监控程序_第5页
第5页 / 共31页
点击查看更多>>
资源描述

《怎样写监控程序》由会员分享,可在线阅读,更多相关《怎样写监控程序(31页珍藏版)》请在金锄头文库上搜索。

1、Boot Loader A Key Technique for MCU Development 清华清华 Freescale MCU/DSP 应用开发研究中心应用开发研究中心Monitor/Debug or Boot Loader A basic residential program in MCU Initialize the MCU system Communication with people Download application program from outside and run Some debug utilities It is a basic development

2、tool for Hardware and Software A Minimum MCU System A minimum MCU system is the BASIC hardware tool foe application development Basic hardware system includes: Power supply Reset circuit Clock circuit A communication port (in most case: RS-232)Tools for Hardware Test Power supplyMulti-meter Rest Mul

3、ti-meter Clock circuitOscilloscope Be careful with the PCB design,reserve a oscillator module on the PCB RS-232Multi-meter Oscilloscope Need a program to test: Initial SCI Send out a ASCII loopNeed a tool to download program (BDM) anywayMonitor/Debug (Boot Loader) Initialize the MCU system Communica

4、tion with people Download application program from outside and run Some debug utilitiesInitialize the MCU system Initial Stack Pointer SPLDS #STACK ; Init. Stack Pointer Initial SCI SCI need system clock, which maybe complicated Use external clock first Then the PLL initialInitial SCISC_Init LDAA #$

5、0C ; Initial SCI STAA SCI0CR2 ; Enable T Use default Protocol STAA SCI0BDH ; 8b, No parity,1stop LDAA #$9C ; 9600 baud rate (clock related) STAA SCI0BDL SCI clock = baud rate x 16 = bus clock/dividerBus clock is from external clock OR PLL!May not needSCI Test and DebugWrite a program send: AAAAAAAAA

6、AAAAAAAAAOUTCH LDB#A OUTCH1BRCLR SCI0SR1,#$80,* STABSCI0DRL;Write to SCI BRAOUTCH1Till now, we believe that IT WORKS! Only 9 lines ASM code!Then Replace the BRA to RTSInput char Test* INCHBRCLR SCI0SR1,$20,INCH ;Check status LDAB SCI0DRL BSR OUTCH BRA INCHThen Replace the BRA to RTSGet_CharINCH BRCL

7、R SCI0SR1,$20,INCH; Without Echo LDAA SCI0DRL RTS * INCHE BSR INCH ; With Echo BRA OUTCHAssembler Example: OUTCH* Out space(s) Routine: OUT2S BSR OUT1S OUT1S LDAA #$20 ;ASCII Code for Space * OUTCH BRCLR SCI0SR1,#$80,* ; Check if TBF Empty? STAA SCI0DRL ; Out char. RTS * Print string PDATA: PRINT JS

8、R OUTCH PDATA LDAA ,X+ CMPA #EOT BNE PRINT RTSBasic Functions of the Debug Initialize the MCU system Communication with people (Talk to CPU) Download program and run Some debug utilitiesDynamic and Static CPU Registers Image During IRQ or SWI, CPU registers are pushed into stack automatically That i

9、s dynamic CPU Register Image. A data structure in RAM, which has the same structure with above, it is called static image Get Static Image : Copy Dynamic to Static Let SP?Dynamic, then run SWI Stack Structure after SWICCRSP - 9Last Valid Data in the stackSPPCLSP - 1PCHSP - 2YLSP - 3YHSP - 4XLSP - 5X

10、HSP - 6ASP - 7BSP - 8Stack free byteAfter IRQ/SWI SP=SP-9Before IRQ SPStack GrowthHigh AddressLow AddressRun Program In uC/OS-II a tasks context switch (CPU registers) is in the stack Move SP to the stack top run RTI Instruction to resume the task If we move the SP and let it points to the static Im

11、age and Run TRI, what happens? Display SP Initialed Here MRB RMB 1 ;SP + 1 MRA RMB 1 ;SP + 2 MRX RMB 2 ;SP + 3 MRY RMB 2 ;SP + 5 MRPC RMB 2 ;SP + 7 SPBUF RMB 2 ;SP + 9 See Page 374You can Use C (see: OS_CPU_C.C)void *OSTaskStkInit(void (*task)(void *pd), void *pdata, void *ptos, INT16U opt) INT16U *

12、stk; stk= (INT16U *)ptos; / Load stack pointer *-stk = opt; / opt one byte blank *-stk = (INT16U)(task); / PC for use of opt in task *-stk = (INT16U)(task); / PC *-stk = (INT16U)(0x1122); / Y *-stk = (INT16U)(0x3344); / X (INT8U *)stk)-;/ One byte for A *(INT8U *)stk = (INT8U)(INT16U)pdata)8); / A (

13、INT8U *)stk)-;/ One byte for B *(INT8U *)stk = (INT8U)(pdata); / B (INT8U *)stk)-;/ One byte for CCR *(INT8U *)stk = (INT8U)(0x00); / CCR (INT8U *)stk)-;/ One byte for PPAGE *(INT8U *)stk = *(INT8U *)pdata; / PPAGE return (void *)stk); Run ProgramGOLDS SPBUF ;Current SP LDX MRPC PSHX LDX MRY PSHX LS

14、X MRX PSHX LDA MRB PSHA LDAA MRCC PSHA RTICommand Jump TableJMPTAB FCC E FDB ERSPLSH FCC D FDB MDUMP FCC G FDB GO FCC H FDB HELP FCC L FDB DWNLD FCC M FDB MEMCHG FCC R FDB REGDSP FCC Z FDB CLEARBP TBLEND EQU *Increment command One by OneNXTCMD JSR INCH LDX #JMPTAB NXTCHR CMPB 0,X ; According to the command BNE NEXT ; Jump to the corresponding routine LDX 1,X JSR 0,X BRA NXTCMD NEXTCMD INX INX INX C

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号