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

📄 bsp.c

📁 基于 Philips 公司的 ARM-7 使用之 uC/OS-II 作业系统,此例程是移植于 LPC-2888 上的应用,不同于一般的 Porting 其最主要是加入了支援 OS_View 观察器功能
💻 C
📖 第 1 页 / 共 4 页
字号:

static  void  PB_Init (void)
{
    MODE1C_2 = BSP_PB1 | BSP_PB2;
    MODE0C_2 = BSP_PB1 | BSP_PB2;
}

/*
*********************************************************************************************************
*                                          ADC INITIALIZATION
*
* Description: This function initializes the ADC1 and ADC0 for continuous operation with 5 bits of
*              precision.
*
* Argument(s): none
*
* Returns    : none
*********************************************************************************************************
*/

static  void  ADC_Init (void)
{
    ADCPD    = 0x00000000;

    ADCSEL   = (ADCSEL_SEL0 & (5 << 0))
             | (ADCSEL_SEL1 & (5 << 4));

    ADCCON   = ADCCON_SELVREF
             | ADCCON_ADCENAB
             | ADCCON_CSCAN
             | ADCCON_ADCSTRT;

    ADCCON   = ADCCON_SELVREF
             | ADCCON_ADCENAB
             | ADCCON_CSCAN;
}

/*
*********************************************************************************************************
*                                    INITIALIZE THE EXTERNAL SDRAM
*
* Description: This function initializes the external SDRAM.
*
* Argument(s): None.
*
* Returns    : None.
*********************************************************************************************************
*/

static  void  SDRAM_Init (void)
{
    CPU_INT08U  wtemp;


    EMCCONTROL            = 0x00000001;                         /* Enable EMC                                               */
    EMCCONFIG             = 0x00000000;                         /* Big-endian mode                                          */

    EMCDYNAMICCONFIG      = 0x00001488;                         /* Low-power SDRAM, 8Mx16, 4 banks                          */

    EMCDYNAMICRASCAS      = 0x00000202;                         /* Set RAS latency to 1 HCLK cycle; CAS to 2 HCLK cycles    */

    EMCDYNAMICREADCONFIG  = 0x00000000;                         /* Clock out delayed strategy                               */
    EMCDYNAMICRP          = 0x00000003;                         /* Set tRP   [60ns]                                         */
    EMCDYNAMICRAS         = 0x00000001;                         /* Set tRAS  [37ns]                                         */
    EMCDYNAMICSREX        = 0x00000002;                         /* Set tSRES (tXSR) [67ns]                                  */
    EMCDYNAMICAPR         = 0x00000002;                         /* ?                                                        */
    EMCDYNAMICDAL         = 0x00000004;                         /* Set tDAL [4tCK]                                          */
    EMCDYNAMICWR          = 0x00000001;                         /* Set tDPL [2tCK]                                          */
    EMCDYNAMICRC          = 0x00000002;                         /* Set tRC  [60ns]                                          */
    EMCDYNAMICRFC         = 0x00000002;                         /* Set tRFC [60ns]                                          */
    EMCDYNAMICXSR         = 0x00000003;                         /* Set tXSR [67ns]                                          */
    EMCDYNAMICRRD         = 0x00000000;                         /* Set tRRD [14ns]                                          */
    EMCDYNAMICMRD         = 0x00000001;                         /* Set tMRD [2tCK]                                          */

    EMCDYNAMICCONTROL     = EMCDYNAMICCONTROL_FORCECKE          /* Force CKE high continuously (begin initialization)       */
                          | EMCDYNAMICCONTROL_FORCECLKOUT       /* Force CLKOUT to run continuously to dynamic memory       */
                          | EMCDYNAMICCONTROL_NOP;              /* Send NOP command                                         */

    BSP_DelayM(200);                                            /* Delay for 200 ms                                         */

    EMCDYNAMICCONTROL     = EMCDYNAMICCONTROL_FORCECKE          /* Force CKE high continuously (begin initialization)       */
                          | EMCDYNAMICCONTROL_FORCECLKOUT       /* Force CLKOUT to run continuously to dynamic memory       */
                          | EMCDYNAMICCONTROL_PALL;             /* Send PALL = Precharge ALL command                        */

    EMCDYNAMICREFRESH     = 0x00000002;                         /* Select 32 HCLK refresh period                            */

    BSP_DelayM(100);                                            /* Delay for at least eight refresh cycles                  */

    EMCDYNAMICREFRESH     = 0x0000000C;                         /* Select appropriate refresh rate                          */

    EMCDYNAMICRASCAS      = 0x00000202;                         /* Set RAS latency to 1 HCLK cycle; CAS to 2 HCLK cycles    */

    EMCDYNAMICCONFIG      = 0x00001488;                         /* Low-power SDRAM, 8Mx16, 4 banks                          */

    EMCDYNAMICCONTROL     = EMCDYNAMICCONTROL_FORCECKE          /* Force CKE high continuously (begin initialization)       */
                          | EMCDYNAMICCONTROL_FORCECLKOUT       /* Force CLKOUT to run continuously to dynamic memory       */
                          | EMCDYNAMICCONTROL_MODE;             /* Allow for programming of mode register                   */

    wtemp                 = *(CPU_INT08U *)(0x30008C00);        /* Program mode register                                    */
    (void)wtemp;

    EMCDYNAMICCONTROL     = EMCDYNAMICCONTROL_0V;               /* Change command to normal                                 */

    EMCDYNAMICCONFIG      = 0x00081488;                         /* Low-power SDRAM, 8Mx16, 4 banks, enable buffers          */
}


/*
*********************************************************************************************************
*                                  DELAY FUNCTION FOR THE EXTERNAL SDRAM
*
* Description: This function initializes the external SDRAM.
*
* Argument(s): ms       is the number of milliseconds for which to delay
*
* Returns    : None.
*********************************************************************************************************
*/

static  void  BSP_DelayM (CPU_INT08U ms)
{
    CPU_INT32U  tmr_start_val;
    CPU_INT32U  clocks;


#if OS_VIEW_MODULE == 0
    T1CTRL = 0;                                                 /* Disable timer 1                                          */
    T1CTRL = 0x80;                                              /* Prescaler set to no division; enable timer 1             */
#endif

    clocks = ms * BSP_CPU_ClkFreq();

    tmr_start_val = (CPU_INT32U)((~T1VALUE) & 0x000FFFFF);      /* Read timer 0                                             */
    while (((CPU_INT32U)((~T1VALUE) & 0x000FFFFF) - tmr_start_val) < clocks) {
        ;
    }
}

/*
*********************************************************************************************************
*                                       TICKER INITIALIZATION
*
* Description: This function is called to initialize uC/OS-II's tick source (typically a timer generating
*              interrupts every 1 to 100 mS).
*
* Argument(s): None
*
* Returns    : None
*********************************************************************************************************
*/

static  void  Tmr_TickInit (void)
{
    CPU_INT32U   clk_freq;


    BSP_IntInstall(VIC_TIMER0, Tmr_TickISR_Handler, 1);

    clk_freq = BSP_CPU_ClkFreq();

    T0CTRL         = 0;                                         /* Disable timer 0                                          */
    T0LOAD         = (clk_freq * 1000) / OS_TICKS_PER_SEC ;
    T0CTRL         = 0xC0;                                      /* Prescaler set to no division; enable timer 0             */
}

/*
*********************************************************************************************************
*                                         TIMER #0 IRQ HANDLER
*
* Description: This function handles the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Argument(s): None
*
* Returns    : None
*********************************************************************************************************
*/

void  Tmr_TickISR_Handler (void)
{
    T0CLR = 0x0;
    OSTimeTick();
}


/*
******************************************************************************************************************************
*                                             INTERRUPT SERVICES
******************************************************************************************************************************
*/

/*
*********************************************************************************************************
*                                          ISR HANDLER
*
* Description : This function is called to determine the source of the interrupt
*               and process it accordingly.
*
* Arguments   : None.
*********************************************************************************************************
*/

void  OS_CPU_ExceptHndlr (CPU_INT32U  except_id)
{
    BSP_PFNCT   pfnct;
    CPU_INT08U  irq_no;

    if ((except_id == OS_CPU_ARM_EXCEPT_IRQ) ||
        (except_id == OS_CPU_ARM_EXCEPT_FIQ)) {

        irq_no = (INT_VECTOR0 & 0x000000FF) >> 3;
        pfnct  = (BSP_PFNCT)(Int_Table[irq_no]);

        if (pfnct != (BSP_PFNCT)0) {                                /* Make sure we don't have a NULL pointer                   */
          (*pfnct)();                                               /* Execute the ISR for the interrupting device              */
        }
    } else {
        while (DEF_TRUE) {
            ;
        }
    }
}

/*
*********************************************************************************************************
*                                    INSTALL INTERRUPT VECTOR
*
* Description: This function installs an interrupt vector.
*
* Argument(s): irq      is the IRQ number of the interrupt
*              isr      is the pointer to the ISR handler
*              priority is the assigned priority to the interrupt
*
* Returns    : None.
*
* Caller(s)  :
*********************************************************************************************************
*/


void  BSP_IntInstall(CPU_INT08U irq, void (*isr)(void), CPU_INT08U priority)
{
    CPU_INT32U  int_req;


    int_req               = 0x80300400 + (irq << 2);            /* Address of INT_REQ register                              */
    Int_Table[irq]        = (CPU_INT32U)isr;                    /* Assign ISR vector to vector array                        */

    *(CPU_INT32U *)int_req = ((1 << 27) |                       /* Target is stored in bit 8                                */
                              (1 << 26) |                       /* Enable is stored in bit 16                               */
                              (1 << 16) |                       /* Enable the interrupt                                     */
                              (1 << 28) |                       /* Value in 3:0 indicates the priority                      */
                              priority);                        /* Set priority to 6                                        */
}

/*
*********************************************************************************************************
*                                        INITIALIZE VECTORED INTERRUPT CONTROLLER
*
* Description: This function initializes the exception vecotrs to the dummy ISR handler.
*
* Argument(s): None
*
* Returns    : None
*********************************************************************************************************
*/

static  void  BSP_IntInit (void)
{
    CPU_INT08U  i;


    for (i = 1; i <= 29; i++) {                                 /* Initialize VIC vector table                              */
        Int_Table[i] = (CPU_INT32U)BSP_Dummy_ISR_Handler;
    }
}

/*
*********************************************************************************************************
*                                           DUMMY IRQ HANDLER
*
* Description: This function is called to handle invalid IRQs
*
* Argument(s): None
*
* Returns    : None
*********************************************************************************************************
*/

static  void  BSP_Dummy_ISR_Handler (void)
{

}

/*
*********************************************************************************************************
*                                     DISABLE ALL INTERRUPTS
*
* Description: This function disables all interrupts from the interrupt controller.
*
* Argument(s): None
*
* Returns    : None
*********************************************************************************************************
*/

void  BSP_IntDisAll (void)
{
    INT_REQ1  = 0x00000000;
    INT_REQ2  = 0x00000000;
    INT_REQ3  = 0x00000000;
    INT_REQ4  = 0x00000000;
    INT_REQ5  = 0x00000000;
    INT_REQ6  = 0x00000000;
    INT_REQ7  = 0x00000000;
    INT_REQ8  = 0x00000000;
    INT_REQ9  = 0x00000000;
    INT_REQ10 = 0x00000000;
    INT_REQ11 = 0x00000000;
    INT_REQ12 = 0x00000000;
    INT_REQ13 = 0x00000000;
    INT_REQ14 = 0x00000000;
    INT_REQ15 = 0x00000000;
    INT_REQ16 = 0x00000000;
    INT_REQ17 = 0x00000000;
    INT_REQ18 = 0x00000000;
    INT_REQ19 = 0x00000000;
    INT_REQ20 = 0x00000000;
    INT_REQ21 = 0x00000000;
    INT_REQ22 = 0x00000000;
    INT_REQ23 = 0x00000000;
    INT_REQ24 = 0x00000000;
    INT_REQ25 = 0x00000000;
    INT_REQ26 = 0x00000000;
    INT_REQ27 = 0x00000000;
    INT_REQ28 = 0x00000000;
    INT_REQ29 = 0x00000000;
}

⌨️ 快捷键说明

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