[8/16-bit MCU] powerpc架构MPC5604B单片机ADC例程

[复制链接]
 楼主| Jessicakjdsl 发表于 2016-1-23 21:02 | 显示全部楼层 |阅读模式
main.c
  1. #include "MPC5604B_M27V.h"
  2. #define  LED        SIU.GPDO[76].B.PDO


  3. uint16_t AD_IN1,AD_IN2;

  4. /* *****************************************************************************
  5.    Function:        void SWT_DisableWatchDog(void)
  6.    Description:     Disable The Software WatchDog Timer (SWT)
  7.    Parameters:      Input:    None
  8.                     Output:   None
  9.    Notes:           To Clear The SWT_CR[SLK] Soft Lock Bit,
  10.                     The Value 0xC520 Followed By 0xD928 Is Written To The WSC Field.
  11.    ***************************************************************************** */
  12. void SWT_DisableWatchDog(void)
  13. {
  14.   SWT.SR.R = 0x0000C520;                // 向SR中写入C520和D928清除CR中的SLK位
  15.   SWT.SR.R = 0x0000D928;               
  16.   SWT.CR.R = 0x8000010A;                // 清除看门狗使能位 (WEN),禁止软件看门狗工作。
  17. }

  18. /* *****************************************************************************
  19.    Function:        void SYSTEM_Init(void)
  20.    Description:     Initialize Following System Peripherals
  21.                     - The Mode Entry (ME)
  22.                     - Clock Generation Module (CGM)
  23.                     - Frequency Modulated Phase Locked Loop (FMPLL)
  24.                     - Clock Monitor Unit (CMU)
  25.                     - Power Control Unit (PCU)
  26.                     - ReSet Generation Module (RGM)
  27.                     - System Status And Configuration Module (SSCM)
  28.    Parameters:      Input:    None
  29.                     Output:   None
  30.    Notes: 系统初始化函数
  31.    ***************************************************************************** */
  32. void SYSTEM_Init(void)
  33. {
  34. //模式配置: 使能DRUN, RUN0, SAFE, RESET模式
  35.   ME.MER.R = 0x0000001D;   

  36. //初始化锁相环,
  37. //外部晶振为8MHz,设置PLL0为64MHz  // 0x05400100: 0000 0101 0100 0000 0000 0001 0000 0000
  38. //设置IDF=2,ODF=4,NDIV=64;
  39. //锁相环输出时钟phi=(clkin*NDIV)/(IDF*ODF)=(8*64)/(2*4)=64MHz
  40.   CGM.FMPLL_CR.R = 0x05400100;

  41. //RUN0配置: 主电压调节器打开,Data Flash处于正常模式。Code Flash处于正常模式。
  42. //使能锁相环,锁相环输出时钟作为系统时钟。
  43.   ME.RUN[0].R   = 0x001F0074;           
  44.   
  45. //外设运行配置0: 外设在所有模式下都工作
  46.   ME.RUNPC[0].R = 0x000000FE;           
  47.   
  48. // ADC: 选择 ME.RUNPC[0] 的配置  
  49.   ME.PCTL[32].R = 0x00;                 

  50. // SIUL: 选择 ME.RUNPC[0] 的配置  
  51.   ME.PCTL[68].R = 0x00;                 

  52. // 设置进入RUN0模式
  53.   ME.MCTL.R = 0x40005AF0;               //写入模式和密钥
  54.   ME.MCTL.R = 0x4000A50F;               //写入模式和反密钥

  55. //等待模式转换完成
  56.   while(ME.GS.B.S_MTRANS) {};           
  57. //验证进入了RUN0模式
  58.   while(ME.GS.B.S_CURRENTMODE != 4) {}  
  59. }


  60. /************************************************************/
  61. /*                       初始化SIU                          */
  62. /************************************************************/
  63. void init_SIU(void)
  64. {

  65.         SIU.PCR[76].R = 0x0220;               // 设置PE[12]为开漏输出,控制D1

  66.         SIU.PCR[20].R = 0x2000;               // 设置PB[4]为ADC0模数转换输入
  67.         SIU.PCR[21].R = 0x2000;               // 设置PB[5]为ADC1模数转换输入

  68. }

  69. /************************************************************/
  70. /*                     初始化ADC转换                        */
  71. /************************************************************/
  72. void ADC_init(void)
  73. {
  74.   ADC.MCR.R        = 0x20000000;        //初始化ADC为扫描模式,时钟为32MHz。
  75.   ADC.NCMR[0].R    = 0x00000003;        //选择转换ADC0和ADC1
  76.   ADC.CTR[0].R     = 0x00008606;        //设置转换时间
  77.   ADC.MCR.B.NSTART = 1;                 //启动AD转换
  78. }

  79. /************************************************************/
  80. /*                         主函数                           */
  81. /************************************************************/
  82. int main(void)
  83. {
  84.         SWT_DisableWatchDog();
  85.         SYSTEM_Init();
  86.         init_SIU();
  87.         ADC_init();       

  88.         for (;;)
  89.         {
  90.             while(ADC.CDR[0].B.VALID != 1) {}         //等待ADC0转换结果有效
  91.             AD_IN1 = (uint16_t)ADC.CDR[0].B.CDATA;    //读取ADC0的转换结果
  92.             while(ADC.CDR[1].B.VALID != 1) {}         //等待ADC0转换结果有效
  93.             AD_IN2 = (uint16_t)ADC.CDR[1].B.CDATA;    //读取ADC0的转换结果
  94.                 if(AD_IN1>AD_IN2)
  95.                         LED=0;      //点亮指示灯
  96.                 else
  97.                         LED=1;           //熄灭指示灯
  98.         }
  99. }




 楼主| Jessicakjdsl 发表于 2016-1-23 21:03 | 显示全部楼层
  1. #include "Exceptions.h"    /* IVPR and default exception handlers setup */
  2. #include "INTCInterrupts.h" /* INTC Interrupts Requests configuration */
  3. #include "MPC5604B_M27V_HWInit.h"

  4. #pragma section code_type ".init"

  5. #define INIT_DERIVATIVE_INTERNAL_SETUP 1
  6. #define INIT_EXTERNAL_BUS_INTERFACE_SETUP 0

  7. #ifndef INIT_DERIVATIVE_INTERNAL_SETUP
  8. #pragma error INIT_DERIVATIVE_INTERNAL_SETUP should be defined !
  9. #endif

  10. #ifndef INIT_EXTERNAL_BUS_INTERFACE_SETUP
  11. #pragma error INIT_EXTERNAL_BUS_INTERFACE_SETUP should be defined !
  12. #endif

  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif

  16. extern __asm void __start();
  17. __asm void usr_init();
  18. /*lint -esym(752,__start) */

  19. #ifdef __cplusplus
  20. }
  21. #endif

  22. /*****************************************************************/
  23. /* usr_init():                                                   */
  24. /*   Define here the needed hardware initializations at startup  */

  25. __asm void usr_init()
  26. {
  27.     /* Add needed hardware initializations in this function */
  28.     nofralloc

  29.     mflr     r30                         /* Save off return address in NV reg */

  30. #if INIT_DERIVATIVE_INTERNAL_SETUP==1
  31.     bl      INIT_Derivative              /* Derivative specific hardware initializations */
  32. #endif
  33. #if INIT_EXTERNAL_BUS_INTERFACE_SETUP==1
  34.     bl      INIT_ExternalBusAndMemory    /* Set up access to external memory (inc. chip select and MMU) */
  35. #endif
  36.     bl      EXCEP_InitExceptionHandlers   /* Set up Default Exception handling */
  37.     bl      INTC_InitINTCInterrupts       /* Set up INTC Interrupts Requests handling */

  38.     mtlr    r30                          /* Get saved return address */

  39.     blr
  40. }

  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif

  44. /**************************************************************/
  45. /* RCHW and Reset Vector setup:                               */
  46. /*   The chip is by default setup to boot from internal Flash */
  47. /*   and the watchdog is disabled.                            */

  48. typedef void (*resetfuncptr)(void);

  49. #pragma push /* Save the current state */
  50. #pragma section const_type sconst_type ".__bam_bootarea"
  51. extern const unsigned long bam_rchw;
  52. extern const resetfuncptr bam_resetvector;

  53. /* RCHW_VALUE Flags */
  54. #define RCHW_WTE 0x0400L        /* Enable Watchdog */
  55. #define RCHW_VLE 0x0100L        /* Enable Variable Length Encoding*/
  56. #define RCHW_PS0_32BITS 0x0000L /* Boot from External Bus CS0, 32-bit CS0 port size. */
  57. #define RCHW_PS0_16BITS 0x0200L /* Boot from External Bus CS0, 16-bit CS0 port size. */
  58. #define RCHW_BOOTIDENTIFIER 0x005AL

  59. /* Used RCHW value: boot from internal flash, watchdog disabled */
  60. #if VLE_IS_ON == 1
  61. #define RCHW_VALUE RCHW_BOOTIDENTIFIER|RCHW_PS0_32BITS|RCHW_VLE
  62. #else
  63. #define RCHW_VALUE RCHW_BOOTIDENTIFIER|RCHW_PS0_32BITS
  64. #endif

  65. const unsigned long bam_rchw = ((RCHW_VALUE)<<16) + (RCHW_VALUE);
  66. const resetfuncptr bam_resetvector = __start;

  67. #pragma pop

  68. #ifdef __cplusplus
  69. }
  70. #endif

 楼主| Jessicakjdsl 发表于 2016-1-23 21:04 | 显示全部楼层

  1. /*
  2. *
  3. * FILE : MPC5604B_M27V_HWInit.c
  4. *
  5. * DESCRIPTION:
  6. *  This file contains all MPC5604B_M27V derivative needed initializations,
  7. *  and all initializations for the MPC5604B_M27V boards which are supported.
  8. *  This includes setting up the External Bus Interface to allow access
  9. *  to memory on the external bus, and ensuring there is a valid entry in
  10. *  the MMU for the external memory access.
  11. */

  12. /*---------------------------------------------------------------------------*/
  13. /* Includes                                                                  */
  14. /*---------------------------------------------------------------------------*/

  15. #include "MPC5604B_M27V.h"      /* MPC56xx platform development header            */
  16. #include "MPC5604B_M27V_HWInit.h"

  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif

  20. /*******************************************************/
  21. /* MPC5604B_M27V derivative specific hardware initialization */
  22. /*******************************************************/

  23. /* Symbol L2SRAM_LOCATION is defined in the application linker command
  24.    file (.lcf)  It is defined to the start of the internal SRAM in the
  25.    MPC5604B_M27V.
  26. */
  27. /*lint -esym(752, L2SRAM_LOCATION) */
  28. extern long L2SRAM_LOCATION;  


  29. __asm void INIT_Derivative(void)
  30. {
  31. nofralloc

  32.     /* MPC5604B_M27V SRAM initialization code                              */
  33.     lis r11,L2SRAM_LOCATION[url=home.php?mod=space&uid=945]@h[/url]       /* Base of SRAM, 64-bit word aligned */
  34.     ori r11,r11,L2SRAM_LOCATION@l

  35.     li r12,256        /* Loops to cover 32K SRAM; 32k/4 bytes/32 GPRs = 384 */
  36.     mtctr r12

  37.     init_l2sram_loop:
  38.         stmw r0,0(r11)        /* Write 32 GPRs to SRAM                     */
  39.         addi r11,r11,128      /* Inc the ram ptr; 32 GPRs * 4 bytes = 128B */
  40.         bdnz init_l2sram_loop /* Loop for 32k of SRAM                      */

  41.     blr
  42. }

  43. /*******************************************************/
  44. /* MPC5604B_M27V boards specific hardware initializations    */
  45. /*******************************************************/

  46. /** This macro allows to use C defined address with the inline assembler */
  47. #define MAKE_HLI_COMPATIBLE(hli_name, c_expr) enum { hli_name=/*lint -e30*/((int)(c_expr)) };

  48. /*----------------------------------------------------------------------------*/
  49. /* Function declarations                                                      */
  50. /*----------------------------------------------------------------------------*/

  51. /* Initialize a set of contiguous PCRs */
  52. __asm void InitPCRs(void);

  53. /* Initialize the SIU External Bus Interface */
  54. __asm void __initSIUExtBusInterface(void);

  55. /* Initialize the used EBI Chip Selects */
  56. __asm void __initEBIChipSelects(void);

  57. /* Write one MMU Table Entry */
  58. __asm void WriteMMUTableEntry( void );

  59. /* Initialize the needed MMU Table entries */
  60. __asm void __initMMUExternalMemory(void);

  61. /*----------------------------------------------------------------------------*/
  62. /* Function implementations                                                   */
  63. /*----------------------------------------------------------------------------*/

  64. __asm void INIT_ExternalBusAndMemory(void)
  65. {
  66. nofralloc

  67.     mflr     r28
  68.    
  69.     /* Initialize the SIU External Bus Interface */
  70.     bl __initSIUExtBusInterface
  71.     /* Initialize the used EBI Chip Selects */
  72.     bl __initEBIChipSelects
  73.     /* Initialize the needed MMU Table entries */
  74.     bl __initMMUExternalMemory
  75.    
  76.     mtlr     r28
  77.    
  78.     blr
  79. }

  80. /*----------------------------------------------------------------------------*/
  81. /* External Memory Locations from lcf file                                    */
  82. /*----------------------------------------------------------------------------*/

  83. #if INIT_USED_BOARD==MPC5604B_M27VDEMO_AXM_0321
  84. /* Symbol AXM_0321_EXTERNAL_RAM is defined in the application linker command file (.lcf)
  85.    It is defined to the start of the external memory on the MPC5604B_M27VDEMO_AXM-0321 board
  86. */
  87. extern unsigned long AXM_0321_EXTERNAL_RAM[];
  88. #endif

  89. /*----------------------------------------------------------------------------*/
  90. /* SIU External Bus Interface                                                 */
  91. /*----------------------------------------------------------------------------*/

  92. /* Initialize a set of contiguous PCRs:               */
  93. /* r3: the firts PCR to initialize                    */
  94. /* r4: the value to write in the PCRs                 */
  95. /* r5: the number of PCRs to initialize               */
  96. __asm void InitPCRs(void)
  97. {
  98. nofralloc

  99.     mtctr r5                   /* intialize ctr with the number of PCRs to initialize */
  100.     pcr_init_loop:
  101.         sth r4,0(r3)           /* Write r4 to current PCR address */
  102.         addi r3,r3, 2          /* Inc the memory ptr by 2 to point to the next PCR */
  103.         bdnz pcr_init_loop     /* Loop for ctr PCRs */

  104.     blr
  105. }

  106. /* Initialize the SIU External Bus Interface */
  107. __asm void __initSIUExtBusInterface(void)
  108. {
  109. MAKE_HLI_COMPATIBLE(SIU_PCR0,&SIU.PCR[0].R)
  110. MAKE_HLI_COMPATIBLE(SIU_PCR4,&SIU.PCR[4].R)
  111. MAKE_HLI_COMPATIBLE(SIU_PCR28,&SIU.PCR[28].R)
  112. MAKE_HLI_COMPATIBLE(SIU_PCR62,&SIU.PCR[62].R)
  113. MAKE_HLI_COMPATIBLE(SIU_PCR64,&SIU.PCR[64].R)
  114. MAKE_HLI_COMPATIBLE(SIU_PCR68,&SIU.PCR[68].R)
  115. nofralloc

  116.     mflr r27

  117.     /*  This initializes the MPC5604B_M27V external bus
  118.         Set up the pins
  119.         Address bus PCR 4 - 27
  120.         Configure address bus pins
  121.     */
  122.     lis r3,SIU_PCR4@h          /* First PCR Address bus is PCR 4 */
  123.     ori r3,r3,SIU_PCR4@l
  124.     li r5,24                   /* Loop counter to get all address bus PCR (4 to 27) -> 24 PCRs  */
  125.     li r4, 0x0440              /* PCRs initialization value */
  126.     bl InitPCRs

  127.     /*  Data bus PCR 28-59
  128.         Configure data bus pins
  129.     */
  130.     lis r3,SIU_PCR28@h         /* First PCR for data bus is PCR 28 */
  131.     ori r3,r3,SIU_PCR28@l
  132.     li r5,32                   /* Loop counter to get all data bus PCR (28-59) -> 32 PCRs  */
  133.     li r4, 0x0440              /* PCRs initialization value */
  134.     bl InitPCRs

  135.     /*  Configure minimum bus control pins
  136.         RD/WR  & BDIP PCR 62/63
  137.     */
  138.     lis r3,SIU_PCR62@h         /* First PCR for is PCR 62 */
  139.     ori r3,r3,SIU_PCR62@l
  140.     li r5,2                    /* Loop counter to get all PCR (62-63) -> 2 PCRs  */
  141.     li r4, 0x0440              /* PCRs initialization value */
  142.     bl InitPCRs

  143.     /*  WE[0-4] PCR 64-67
  144.     */
  145.     lis r3,SIU_PCR64@h         /* First PCR for is PCR 64 */
  146.     ori r3,r3,SIU_PCR64@l
  147.     li r5,4                    /* Loop counter to get all PCR (64-67) -> 4 PCRs  */
  148.     li r4, 0x0443              /* PCRs initialization value */
  149.     bl InitPCRs

  150.     /*  OE & TS
  151.     */
  152.     lis r3,SIU_PCR68@h         /* First PCR for is PCR 68 */
  153.     ori r3,r3,SIU_PCR68@l
  154.     li r5,2                    /* Loop counter to get all PCR (68-69) -> 2 PCRs  */
  155.     li r4, 0x0443              /* PCRs initialization value */
  156.     bl InitPCRs
  157.    
  158.     /*  Configure the chip selects
  159.         CS[0-3]
  160.     */
  161.     lis r3,SIU_PCR0@h          /* First PCR for is PCR 0 */
  162.     ori r3,r3,SIU_PCR0@l
  163.     li r5,4                    /* Loop counter to get all PCR (0-3) -> 4 PCRs  */
  164.     li r4, 0x0443              /* PCRs initialization value */
  165.     bl InitPCRs
  166.    
  167.     mtlr r27
  168.    
  169.     blr
  170. }

  171. /*----------------------------------------------------------------------------*/
  172. /* EBI Chip Selects                                                           */
  173. /*----------------------------------------------------------------------------*/

  174. /* Initialize the used EBI Chip Selects */
  175. __asm void __initEBIChipSelects(void)
  176. {
  177. #if INIT_USED_BOARD==MPC5604B_M27VDEMO_AXM_0321
  178. MAKE_HLI_COMPATIBLE(EBBI_CS0_BR,&EBI.CS[0].BR.R)
  179. MAKE_HLI_COMPATIBLE(EBBI_CS0_OR,&EBI.CS[0].OR.R)
  180. #endif
  181. nofralloc

  182. #if INIT_USED_BOARD==MPC5604B_M27VDEMO_AXM_0321
  183.     /*  CY7C1338 512K External SRAM - 4 beat burst, 0 wait
  184.         Set up Memory Controller CS0 [url=home.php?mod=space&uid=72445]@[/url] AXM_0321_EXTERNAL_RAM
  185.     */
  186.     /*  EBI.CS[0].BR.R = (unsigned long)AXM_0321_EXTERNAL_RAM | 0x41UL;
  187.     */
  188.     lis      r3,AXM_0321_EXTERNAL_RAM@h
  189.     addi     r0,r3,AXM_0321_EXTERNAL_RAM@l
  190.     ori      r0,r0,0x0041   
  191.     lis      r3,EBBI_CS0_BR@h
  192.     ori      r3,r3,EBBI_CS0_BR@l
  193.     stw      r0,0(r3)
  194.     /*  EBI.CS[0].OR.R = 0xfff80000;
  195.     */
  196.     lis      r0,0xfff8
  197.     lis      r3,EBBI_CS0_OR@h
  198.     ori      r3,r3,EBBI_CS0_OR@l
  199.     stw      r0,0(r3)   
  200. #endif

  201.     blr
  202. }

  203. /*----------------------------------------------------------------------------*/
  204. /* Writing to MMU Table Entries                                               */
  205. /*----------------------------------------------------------------------------*/

  206. /* Write one MMU Table Entry:               */
  207. /* r3, r4, r5 and r6 must hold              */
  208. /* the values of MAS0, MAS1, MAS2 and MAS3  */
  209. __asm void WriteMMUTableEntry( void )
  210. {
  211. nofralloc

  212.     /* Write MMU Assist Register 0 (MAS0); SPR 624 */
  213.     mtspr   624, r3
  214.     /* Write MMU Assist Register 1 (MAS1); SPR 625 */
  215.     mtspr   625, r4
  216.     /* Write MMU Assist Register 2 (MAS2); SPR 626 */
  217.     mtspr   626, r5
  218.     /* Write MMU Assist Register 3 (MAS3); SPR 627 */
  219.     mtspr   627, r6
  220.     /* Write the table entry */
  221.     tlbwe

  222.     blr
  223. }

  224. /* Initialize the needed MMU Table entries */
  225. __asm void __initMMUExternalMemory(void)
  226. {
  227. #if INIT_USED_BOARD==MPC5604B_M27VDEMO_AXM_0321
  228. /* Set up MMU for External Memory
  229.    Base address = 0x2000_0000
  230.    16 MByte Memory Space, Not Guarded, Cachable, All Access
  231. */
  232. MAKE_HLI_COMPATIBLE(AXM_0321_EXT_RAM_MAS0_VALUE,MAS0_VALUE(2))
  233. /* 16 MB memory space, valid, protected, global which matches with all process IDs */
  234. MAKE_HLI_COMPATIBLE(AXM_0321_EXT_RAM_MAS1_VALUE,MAS1_VALUE(V_VALID, IPROT_PROTECTED, TID_GLOBAL, 0, TSIZE_16MB))
  235. MAKE_HLI_COMPATIBLE(AXM_0321_EXT_RAM_MAS2_FLAGS,MAS2_FLAGS(SHARED_CACHE_STATE_NOT_USED, WRITE_BACK, CACHEABLE, MEM_COHERENCE_NREQ, NOT_GUARDED, BIG_ENDIAN ))
  236. MAKE_HLI_COMPATIBLE(AXM_0321_EXT_RAM_MAS3_FLAGS,MAS3_FLAGS(READ_WRITE_EXECUTE))
  237. #endif
  238. nofralloc

  239.      mflr     r27

  240. #if INIT_USED_BOARD==MPC5604B_M27VDEMO_AXM_0321
  241.      /* load r3 with MAS0 value */
  242.      lis r3,AXM_0321_EXT_RAM_MAS0_VALUE@h
  243.      ori r3,r3,AXM_0321_EXT_RAM_MAS0_VALUE@l
  244.      
  245.      /* load r4 with MAS1 value */
  246.      lis r4,AXM_0321_EXT_RAM_MAS1_VALUE@h
  247.      ori r4,r4,AXM_0321_EXT_RAM_MAS1_VALUE@l
  248.      
  249.      /* load r5 with the external RAM address from the lcf file */      
  250.      lis r5,AXM_0321_EXTERNAL_RAM@h
  251.      ori r5,r5,AXM_0321_EXTERNAL_RAM@l
  252.      
  253.      /* mask with 0xfffff000 */
  254.      clrrwi   r5,r5,12
  255.      
  256.      /* copy the masked external ram address to r6 also */
  257.      mr r6,r5
  258.      
  259.      /* end MAS2 setup in r3 */
  260.      ori r5,r5,AXM_0321_EXT_RAM_MAS2_FLAGS@l
  261.      
  262.      /* end MAS3 setup in r4 */
  263.      ori r6,r6,AXM_0321_EXT_RAM_MAS3_FLAGS@l
  264.      
  265.      /* write the MMU entry defined through r3, r4, r5 and r6 */
  266.      bl WriteMMUTableEntry
  267. #endif

  268.      mtlr r27

  269.      blr
  270. }

  271. #ifdef __cplusplus
  272. }
  273. #endif
 楼主| Jessicakjdsl 发表于 2016-1-23 21:05 | 显示全部楼层
  1. #include "Exceptions.h"    /* IVPR and default exception handlers setup */
  2. #include "INTCInterrupts.h" /* INTC Interrupts Requests configuration */
  3. #include "MPC5604B_M27V_HWInit.h"

  4. #pragma section code_type ".init"

  5. #define INIT_DERIVATIVE_INTERNAL_SETUP 0
  6. #define INIT_EXTERNAL_BUS_INTERFACE_SETUP 0

  7. #ifndef INIT_DERIVATIVE_INTERNAL_SETUP
  8. #pragma error INIT_DERIVATIVE_INTERNAL_SETUP should be defined !
  9. #endif

  10. #ifndef INIT_EXTERNAL_BUS_INTERFACE_SETUP
  11. #pragma error INIT_EXTERNAL_BUS_INTERFACE_SETUP should be defined !
  12. #endif

  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif

  16. extern __asm void __start();
  17. __asm void usr_init();
  18. /*lint -esym(752,__start) */

  19. #ifdef __cplusplus
  20. }
  21. #endif

  22. /*****************************************************************/
  23. /* usr_init():                                                   */
  24. /*   Define here the needed hardware initializations at startup  */

  25. __asm void usr_init()
  26. {
  27.     /* Add needed hardware initializations in this function */

  28.     nofralloc

  29.     mflr     r30                         /* Save off return address in NV reg */

  30. #if INIT_DERIVATIVE_INTERNAL_SETUP==1
  31.     bl      INIT_Derivative              /* Derivative specific hardware initializations */
  32. #endif
  33. #if INIT_EXTERNAL_BUS_INTERFACE_SETUP==1
  34.     bl      INIT_ExternalBusAndMemory    /* Set up access to external memory (inc. chip select and MMU) */
  35. #endif
  36.     bl      EXCEP_InitExceptionHandlers   /* Set up Default Exception handling */
  37.     bl      INTC_InitINTCInterrupts       /* Set up INTC Interrupts Requests handling */

  38.     mtlr    r30                          /* Get saved return address */
  39.    
  40.     blr
  41. }

 楼主| Jessicakjdsl 发表于 2016-1-23 21:08 | 显示全部楼层
  1. /*
  2.    File: ivor_branch_table_p1.c - for use with MPC560x only
  3.    Description:  Branch table for 16 e200z0h core interrupts
  4.    Copyright Freescale 2008.  All Rights Reserved
  5.    Rev 1.0 Jul  6 2007 S.M. - Initial version
  6.    Rev 1.1 May 13 2008 D.F. - Adapted 551x version for e200z0h processors
  7. */

  8. #pragma push

  9. #define SIXTEEN_BYTES 16

  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif

  13. /* IVOR4 will call this handler */
  14. extern void INTC_INTCInterruptHandler(void);

  15. #ifdef __cplusplus
  16. }
  17. #endif

  18. #pragma section code_type ".ivor_branch_table"
  19. #pragma force_active on

  20. #pragma function_align 16  

  21. __declspec(vle_on) asm void ivor_branch_table_p1(void) {
  22.   nofralloc

  23.                                 .align SIXTEEN_BYTES      
  24. IVOR0trap:  b        IVOR0trap         // IVOR 0 interrupt handler

  25.                                 .align SIXTEEN_BYTES      
  26. IVOR1trap:  b        IVOR1trap         // IVOR 1 interrupt handler
  27.                                                
  28.                                 .align SIXTEEN_BYTES      
  29. IVOR2trap:  b        IVOR2trap         // IVOR 2 interrupt handler

  30.                                 .align SIXTEEN_BYTES      
  31. IVOR3trap:  b        IVOR3trap         // IVOR 3 interrupt handler

  32.                                 .align SIXTEEN_BYTES      
  33. IVOR4trap:  b   INTC_INTCInterruptHandler // External Interrupt

  34.                                 .align SIXTEEN_BYTES      
  35. IVOR5trap:  b        IVOR5trap    // IVOR 5 interrupt handler

  36.                                 .align SIXTEEN_BYTES      
  37. IVOR6trap:  b        IVOR6trap         // IVOR 6 interrupt handler

  38.                                 .align SIXTEEN_BYTES      
  39. IVOR7trap:  b        IVOR7trap         // IVOR 7 interrupt handler

  40.                                 .align SIXTEEN_BYTES      
  41. IVOR8trap:  b        IVOR8trap         // IVOR 8 interrupt handler

  42.                                 .align SIXTEEN_BYTES      
  43. IVOR9trap:  b        IVOR9trap         // IVOR 9 interrupt handler

  44.                                 .align SIXTEEN_BYTES      
  45. IVOR10trap: b   IVOR10trap   // IVOR 10 interrupt handler

  46.                                 .align SIXTEEN_BYTES      
  47. IVOR11trap:  b        IVOR11trap         // IVOR 11 interrupt handler

  48.                                 .align SIXTEEN_BYTES      
  49. IVOR12trap:  b        IVOR12trap         // IVOR 12 interrupt handler

  50.                                 .align SIXTEEN_BYTES      
  51. IVOR13trap:  b        IVOR13trap         // IVOR 13 interrupt handler

  52.                                 .align SIXTEEN_BYTES      
  53. IVOR14trap:  b        IVOR14trap         // IVOR 14 interrupt handler

  54.                                 .align SIXTEEN_BYTES      
  55. IVOR15trap:  b        IVOR15trap         // IVOR15 interrupt handler

  56.         nop  // fill to 0x100 bytes
  57.         nop
  58.         nop
  59.         
  60. }

  61. #pragma pop
Tennasi 发表于 2016-1-24 20:14 | 显示全部楼层
这个adc的采样率最高能达到多少啊
hao507 发表于 2016-4-13 13:11 | 显示全部楼层
谢谢楼主分享,有没有其他的例程分享下阿~~
linwx2010 发表于 2016-8-15 19:19 | 显示全部楼层
谢谢楼主分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

17

主题

116

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部