⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 嵌入式---程序示例1.htm

📁 bsp基本概念
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0043)http://drew.nease.net/mypage/sourcecode.htm -->
<HTML><HEAD><TITLE>嵌入式---程序示例</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY background=嵌入式---程序示例1.files/background.gif>
<P>&gt;&gt;<BIG><BIG><A name=returntop></A></BIG><A 
href="http://drew.nease.net/">Drew的主页</A></BIG>----&gt;程序示例</P>
<DIV align=center>
<CENTER>
<TABLE borderColor=#88deea height=23 cellSpacing=1 borderColorDark=#88deea 
width=754 bgColor=#ffffff borderColorLight=#88deea 
background=嵌入式---程序示例1.files/404.htm border=1>
  <TBODY>
  <TR>
    <TD align=middle width=83 height=1>
      <P align=center><A href="http://drew.nease.net/"><BIG>主页</BIG></A></P></TD>
    <TD align=middle width=83 height=1>
      <P align=center><A href="http://drew.nease.net/mypage/VxWorks.htm"><FONT 
      lang=ZH-CN face=System>VxWorks</FONT></A></P></TD>
    <TD align=middle width=84 height=1>
      <P align=center><A href="http://drew.nease.net/processor/arm.htm"><FONT 
      lang=ZH-CN face=System>ARM</FONT></A></P></TD>
    <TD align=middle width=84 height=1>
      <P align=center><A href="http://drew.nease.net/processor/mpc860.htm"><FONT 
      lang=ZH-CN face=System>PowerPC</FONT></A></P></TD>
    <TD align=middle width=84 height=1>
      <P align=center><A href="http://drew.nease.net/mypage/driver.htm"><FONT 
      lang=ZH-CN face=System>硬件驱动</FONT></A></P></TD>
    <TD align=middle width=84 height=1>
      <P align=center><A href="http://drew.nease.net/mypage/network.htm"><FONT 
      lang=ZH-CN face=System>网络协议</FONT></A></P></TD>
    <TD align=middle width=84 height=1>
      <P align=center><FONT lang=ZH-CN face=System>程序示例</FONT></P></TD>
    <TD align=middle width=84 height=1><A href="http://www.embhelp.com/bbs" 
      target=_blank><FONT face=System color=#8000ff>技术论坛</FONT></A></TD>
    <TD align=middle width=84 height=1>
      <P align=center><A href="http://www.embhelp.com/download"><FONT lang=ZH-CN 
      face=System>下载</FONT></A></P></TD></TR></TBODY></TABLE></CENTER></DIV>
<P align=center> </P>
<P align=center><FONT 
color=#0000ff><BIG><BIG><BIG>程序示例</BIG></BIG></BIG></FONT></P>
<P align=center> </P>
<P><BIG><STRONG>&nbsp;&nbsp;&nbsp; 
这里是一些程序示例和源码解释.一些相关程序代码会陆续补上.相关问题可参见</STRONG></BIG><A 
href="http://drew.nease.net/mypage/driver.htm" target=_blank><FONT lang=ZH-CN 
face=System>硬件驱动</FONT></A></P>
<BLOCKQUOTE>
  <DIV align=left>
  <TABLE height=269 width=529 border=0>
    <TBODY>
    <TR>
      <TD width=254 height=33><B><A 
        href="http://drew.nease.net/mypage/sourcecode.htm#INIT">系统初始化(PowerPC汇编)</A> 
        </B></TD>
      <TD width=263 height=33><A 
        href="http://drew.nease.net/mypage/example/config.htm"><B>VxWorks 
        BSP文件配置及生成下载</B></A><B>&nbsp;</B></TD></TR>
    <TR>
      <TD width=254 height=33><A 
        href="http://drew.nease.net/mypage/sourcecode.htm#INT"><B>硬件中断</B></A></TD>
      <TD width=263 height=33><A 
        href="http://drew.nease.net/mypage/sourcecode.htm#NIC"><B>VxWorks网络驱动</B></A></TD></TR>
    <TR>
      <TD width=254 height=33><A 
        href="http://drew.nease.net/mypage/example/flashrom.htm"><B>FlashROM驱动(ARM汇编)</B></A></TD>
      <TD width=263 height=33><A 
        href="http://drew.nease.net/mypage/example/ARM_Boot.htm"><B>ARM Boot 
        Load程序(ARM汇编)</B></A></TD></TR>
    <TR>
      <TD width=254 height=34><A 
        href="http://drew.nease.net/mypage/example/UART.htm"><B>串口(UART)程序示例</B></A></TD>
      <TD width=263 height=34><A 
        href="http://drew.nease.net/mypage/example/pci.htm"><U><B>PCI设备(网卡)初始化代码分析</B></U></A></TD></TR>
    <TR>
      <TD width=254 height=34><U><B>文件系统</B></U></TD>
      <TD width=263 height=34></TD></TR>
    <TR>
      <TD width=254 height=34><A 
        href="http://drew.nease.net/mypage/sourcecode.htm#LCD"><B>LCD和触摸屏</B></A></TD>
      <TD width=263 height=34></TD></TR>
    <TR>
      <TD width=254 height=34><A 
        href="http://drew.nease.net/mypage/sourcecode.htm#MODEM"><B>MODEM 
        拨号</B></A></TD>
      <TD width=263 height=34></TD></TR>
    <TR>
      <TD width=254 height=34><B><A 
        href="http://drew.nease.net/mypage/sourcecode.htm#RTC">实时时钟 RTC</A> 
      </B></TD>
      <TD width=263 height=34></TD></TR></TBODY></TABLE></DIV></BLOCKQUOTE>
<BLOCKQUOTE>
  <P> </P></BLOCKQUOTE>
<P><A name=INIT></A><BIG><BIG><STRONG>系统初始化</STRONG></BIG></BIG></P>
<BLOCKQUOTE>
  <P><STRONG>系统初始化对不同的CPU,基本步骤是类似的.</STRONG></P>
  <P><STRONG>系统初始化的主要步骤如下</STRONG></P>
  <BLOCKQUOTE>
    <UL>
      <LI><STRONG>启动</STRONG> 
      <LI><STRONG>关闭中断</STRONG> 
      <LI><STRONG>放boot type到堆栈</STRONG> 
      <LI><STRONG>清空缓存</STRONG> </LI></UL></BLOCKQUOTE>
  <P><STRONG>VxWorks 系统的 PowerPC BSP,系统开机后执行的第一个函数 
  romInit(),在ROM的起点,这里是使用的PowerPC汇编语言</STRONG></P>
  <BLOCKQUOTE>
    <P>/* 定义内部函数 internals */<BR>.globl romInit /* start of system code 
    */<BR>.globl _romInit /* start of system code */<BR><BR>/* 定义外部函数 externals 
    */<BR>.extern romStart /* system initialization routine 
    */<BR><BR>.text<BR>.align 
    2<BR><BR>/*******************************************************************************<BR>* 
    <BR>* romInit ( int startType /@ only used by 2nd entry point @/ 
    )<BR>*/<BR><BR>romInit:<BR>_romInit:<BR>bl cold&nbsp;&nbsp;&nbsp; /* 冷启动 
    */<BR>bl warm&nbsp;&nbsp;&nbsp; /* 热启动 */<BR><BR>cold:<BR>li p5, 
    BOOT_COLD<BR>bl start /* skip over next instruction */<BR><BR>warm:<BR>or 
    p5, p0, p0 /* startType to p5 
    */<BR><BR>start:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* 
    <STRONG>此处是系统启动开始</STRONG> */</P>
    <P>/* <STRONG>屏蔽MSR中CE,EE位,关闭所有的外部中断</STRONG><BR>/*<BR>* Disable external 
    interrupts <BR>*/<BR><BR>mfmsr p0 /* p0 = msr */<BR>INT_MASK (p0, p1) /* 
    mask EE and CE bit */<BR>ori p1,p1,_PPC_MSR_ME /* enable machine checks 
    */<BR>mtmsr p1 /* msr = p1 */<BR>isync<BR><BR>/* 
    <STRONG>下面两步是按照硬件定义初始化一些SPR,DCR寄存器,置0或置1</STRONG></P>
    <P><STRONG>/* 
    SPR是特殊功能寄存器,DCR为设备控制寄存器,还有MSR机器状态寄存器,这些是PowerPC内核中很重要的寄存器</STRONG></P>
    <P>/* 初始化SPR,DCR寄存器置0<BR>* Initalize registers that need to be set to 
    zero.<BR>*/<BR><BR>addi r4,r0,0x0000<BR>mtspr SGR,r4 /* 解锁所有存储区域 SPR 中 SGR 
    位置0 */<BR>mtspr ESR, r4 /* SPR中的错误状态位 ESR 清0 */<BR>mtspr TCR, r4 /* 关闭所有的 
    timers */<BR>mtspr PIT, r4 /* 清0 PIT timer */<BR>mtdcr UICER, r4 /* 
    关闭中断控制器(UIC)中的所有中断 */<BR>mtspr XER, r4 /* 清0 integer exception 寄存器 
    */<BR><BR>/* 初始化另一些SPR,DCR寄存器置1<BR>* Initalize registers that need to be 
    cleared with 0xFFFFFFFF.<BR>*/<BR><BR>addis r4,r0,0xffff<BR>ori 
    r4,r4,0xffff<BR>mtspr TSR, r4 /* timer&nbsp; */<BR>mtspr DBSR, r4 /* 调试状态位置1 
    */<BR>mtdcr UICSR, r4 /* 清除中断控制器(UIC)中的所有 pending 中断 */<BR>mtdcr dmasr, r4 
    /* DMA状态寄存器置1 */<BR><BR>/* 
    <STRONG>PowerPC405用两个缓存,一个是16K指令缓存(ICU),一个是6K数据缓存(DCU),下面是清空着两个缓存,并根据硬件设置缓存</STRONG> 
    */</P>
    <P>/* 清空指令缓存 */<BR>/*BESR type regs ZZZZZZZZZZZZ <BR>* Invalidate the entire 
    instruction cache. This can be done<BR>* with a single iccci instruction in 
    the processor core.<BR>*/<BR><BR>iccci r0, r0<BR><BR>/*清空数据缓存<BR>* 
    Invalidate the entire data cache.<BR>* The 405 processor core in the 405GP 
    has 128 congruence classes.<BR>* Each cache line in the 405 processor is 32 
    bytes.<BR>*/<BR><BR>/*<BR>* Turn the instruction cache on for faster 
    boot-up.<BR>* Also, the icache is needed to help initialize Bank 0<BR>* of 
    the EBC to speed up accesses to flash.<BR>* address space 
    0x00000000-0x07ffffff is cached<BR>* address space 0xf8000000-0xffffffff is 
    cached<BR>*/<BR><BR>lis p0, HIADJ(_PPC403_ICCR_DEFAULT_VAL)<BR>addi p0, p0, 
    LO(_PPC403_ICCR_DEFAULT_VAL)<BR>mtspr _PPC403_ICCR, 
    p0<BR>isync<BR><BR>/*<STRONG> 
    初始化外部总线控制器(EBC)</STRONG>,<STRONG>跳转指令BL,执行extBusCntlrInit</STRONG><BR>* 
    /<BR><BR>bl extBusCntlrInit<BR><BR>/*<BR>* Now that the EBC Bank 0 has been 
    set up, turn the I-cache off if<BR>* i-cache was not specified in config.h. 
    It is also invalidated<BR>* again.<BR>*/<BR><BR>#ifndef 
    USER_I_CACHE_ENABLE<BR>li p0, 0 /* clear p0 */<BR>mtspr _PPC403_ICCR, p0 /* 
    turn off i-cache */<BR>isync<BR>iccci r0, r0 /* invalidate the I-cache again 
    */<BR>#endif<BR><BR>/* 初始化和SDRAM相关的IIC(inter-integrated circut)寄存器IIC0,<BR>* 
    Initialize IIC0 for use in automatic SDRAM configuration<BR>*/<BR><BR>#ifdef 
    LOCAL_MEM_AUTOSIZE<BR>bl iic0Init<BR>#endif<BR><BR>/* 
    <STRONG>初始化SDRAM</STRONG>,<STRONG>BL跳转执行sdramInit</STRONG><BR>* Configure 
    the SDRAM controller only if this is a cold boot.<BR>* If the SDRAM 
    controller is reinitialized on a warm boot, the<BR>* boot line will get 
    wiped out because of the ECC SDRAM memory<BR>* 
    initialization.<BR>*/<BR><BR>li p0, BOOT_COLD<BR>and. p0, p0, p5 /* p5 is 
    saved at the entry of romInit */<BR>beq skip<BR><BR>bl 
    sdramInit<BR><BR>skip:<BR><BR>/*<BR>* Clear the CPU reservation 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -