新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > lpc2124 啟動代碼詳解

        lpc2124 啟動代碼詳解

        作者: 時間:2016-11-11 來源:網絡 收藏
        ;/*****************************************************************************/

        ;/* STARTUP.S: Startup file for Philips LPC2000 */
        ;/*****************************************************************************/
        ;/* <<< Use Configuration Wizard in Context Menu >>> */
        ;/*****************************************************************************/
        ;/* This file is part of the uVision/ARM development tools. */
        ;/* Copyright (c) 2005-2007 Keil Software. All rights reserved. */
        ;/* This software may only be used under the terms of a valid, current, */
        ;/* end user licence from KEIL for a compatible version of KEIL software */
        ;/* development tools. Nothing else gives you the right to use this software. */
        ;/*****************************************************************************/

        本文引用地址:http://www.104case.com/article/201611/316684.htm


        ;/*
        ; * The STARTUP.S code is executed after CPU Reset. This file may be
        ; * translated with the following SET symbols. In uVision these SET
        ; * symbols are entered under Options - ASM - Define.
        ; *
        ; * REMAP: when set the startup code initializes the register MEMMAP
        ; * which overwrites the settings of the CPU configuration pins. The
        ; * startup and interrupt vectors are remapped from:
        ; * 0x00000000 default setting (not remapped)
        ; * 0x80000000 when EXTMEM_MODE is used
        ; * 0x40000000 when RAM_MODE is used
        ; *
        ; * EXTMEM_MODE: when set the device is configured for code execution
        ; * from external memory starting at address 0x80000000.
        ; *
        ; * RAM_MODE: when set the device is configured for code execution
        ; * from on-chip RAM starting at address 0x40000000.
        ; *
        ; * EXTERNAL_MODE: when set the PIN2SEL values are written that enable
        ; * the external BUS at startup.
        ; */

        ;
        ; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs.
        ; 處理器需定義七種工作方式
        ; 如下 7種定義的常量參數由來:
        ; 這7個常量定義為處理器 7種運行模式的參數,為7種“當前程序狀態寄存器” CPSR 模式設置位 M[4:0]的值。
        ; 比如這里的用戶模式,CPSR的M[4:0], 設置為10000就是0x10.
        ; 同理其他.詳見<<嵌入式系統開發與應用>>P71. CPSR設置很關鍵!
        ;
        ; ARM 有7種工作模式:
        ; User: 非特權模式,大部分任務執行在這種模式 正常程序執行的模式
        ; FIQ: 當一個高優先級(fast)中斷產生時將會進入這種模式 高速數據傳輸和通道處理
        ; IRQ: 當一個低優先級(normal)中斷產生時將會進入這種模式 通常的中斷處理
        ; SVC: 用于操作系統的保護模式
        ; Abort: 當存取異常時將會進入這種模式 虛擬存儲及存儲保護
        ; Undef: 當執行未定義指令時會進入這種模式 軟件仿真硬件協處理器
        ; System: 使用和User模式相同寄存器集的特權模式
        ;
        ; 這個7個值,將根據運行狀態需要寫到CPSR寄存器的第0,1,2,3,4,5位。
        ;
        ; ARM有7種運行狀態,每一種狀態的堆棧指針寄存器(SP)都是獨立的。

        ; 所以,對于程序中需要用的每一種處理器模式,
        ; 都要給SP定義一個堆棧地址。
        ; 流程為:修改狀態寄存器內的狀態位,使處理器切換到需要的模式,然后給SP賦值。
        ; 需要注意的是:不要切換到User模式, 進行該模式下的堆棧設置,因為進入User模式后就不能

        ; 再操作CPSR 返回到其他模式了。
        ; 先定義各種模式對應的CPSR寄存器M[4:0]的值,該值決定了進入何種模式。
        ; asm 中的 EQU 就是 C 語言中的 #define

        Mode_USR EQU 0x10;用戶模式
        Mode_FIQ EQU 0x11;FIQ模式
        Mode_IRQ EQU 0x12;IRQ模式
        Mode_SVC EQU 0x13;超級用戶模式
        Mode_ABT EQU 0x17;終止模式
        Mode_UND EQU 0x1B;未定義模式
        Mode_SYS EQU 0x1F;系統模式

        ;中斷屏蔽位 :也和CPSR寄存器的設置有關,這里兩位是禁止/開啟快速中斷和一般中斷的設置.
        ; 設置IRQ和FIQ中斷禁止位,這兩個值將被寫到CPSR寄存器的第6位(FIQ)和第7位(IRQ).1是禁止,0是允許。

        I_Bit EQU 0x80 ; when I bit is set, IRQ is disabled .IRQ中斷控制位,當被置位時,IRQ中斷被禁止

        F_Bit EQU 0x40 ; when F bit is set, FIQ is disabled.FIQ中斷控制位,當被置位時,FIQ中斷被禁止

        ; 狀態屏蔽位
        ; EQU T_bit, 0x20 ;T位,置位時在Thumb模式下運行,清零時在ARM下運行


        ;// Stack Configuration (Stack Sizes in Bytes)
        ;// Undefined Mode <0x0-0xFFFFFFFF:8>
        ;// Supervisor Mode <0x0-0xFFFFFFFF:8>
        ;// Abort Mode <0x0-0xFFFFFFFF:8>
        ;// Fast Interrupt Mode <0x0-0xFFFFFFFF:8>
        ;// Interrupt Mode <0x0-0xFFFFFFFF:8>
        ;// User/System Mode <0x0-0xFFFFFFFF:8>
        ;//
        各模式下定義的堆棧地址. 本段將完成堆棧相關的常量

        UND_Stack_Size EQU 0x00000000;未定義模式棧
        SVC_Stack_Size EQU 0x00000008;超級用戶模式棧
        ABT_Stack_Size EQU 0x00000000;終止模式棧
        FIQ_Stack_Size EQU 0x00000000;快速中斷棧
        IRQ_Stack_Size EQU 0x00000080;普通中斷堆棧
        USR_Stack_Size EQU 0x00000400;用戶模式定義棧

        ;//設置堆棧大小,
        ISR_Stack_Size EQU (UND_Stack_Size + SVC_Stack_Size + ABT_Stack_Size +
        FIQ_Stack_Size + IRQ_Stack_Size);//總堆棧長度

        ; 初始化棧空間
        ;//開辟堆棧段,定義為可讀可寫,不初始化內存單元或將內存寫0,字節對齊 ,arm 字為32位
        ; 定義一個數據段,名為STACK,NOINIT - 僅僅保留內存單元,還沒有寫入值,可讀寫,ALIGN=3 - 按字節對齊。
        AREA STACK, NOINIT, READWRITE, ALIGN=3

        ;//堆棧大小的設置,各公司寫的啟動代碼有所不同,但是不影響大局,可以借鑒一些你認為比較簡單的啟動代碼
        ;//,然后寫自己的堆棧地址和大小設置程序.
        ; 分配內存,用戶模式棧名為Stack_Mem,大小為1024字節;分配 ISR_Stack_Size的內存空間,在USR_Stack之上?。

        Stack_Mem SPACE USR_Stack_Size ;分配 0x00000400 長度空間,并置初始化為 0
        __initial_sp SPACE ISR_Stack_Size ;申請堆棧內存空間. SPACE 為偽指令

        Stack_Top;//堆棧段內容結束, 在這里放個標號,用來獲得堆棧頂部地址
        ; 下面一段轉來的對話
        ; Hello,

        ; could anybody tell me the information of this code line

        ; Stack_Mem SPACE USR_Stack_Size
        ; __initial_sp SPACE ISR_Stack_Size

        ; Stack_Top

        ; __initial_sp is the whole stack size - thats clear. But which information has the last code line Stack_Top?
        ; And why is the ; USR_Stack_Size in comparison to the other Stack_Sizes so big?


        ; The user-stack is for your application, with all calls and auto variables.

        ; The ISR stack is just for interrupt service routines, and they normally dont consume a l
        ; ot of stack space - especially if you dont allow them to nest.

        ; Have you spent some time reading up on the ARM architecture?



        關鍵詞: lpc2124啟動代

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 手游| 册亨县| 阿坝县| 五原县| 五台县| 壤塘县| 理塘县| 开鲁县| 汕头市| 大安市| 简阳市| 当涂县| 聂拉木县| 翼城县| 成武县| 蒙山县| 宽甸| 城市| 尚志市| 句容市| 宿州市| 永城市| 丰县| 三明市| 石楼县| 城固县| 得荣县| 滨州市| 逊克县| 呼伦贝尔市| 松潘县| 永和县| 金堂县| 永泰县| 陈巴尔虎旗| 修文县| 敦化市| 交口县| 浠水县| 堆龙德庆县| 宣城市|