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

📄 bsp.c

📁 μC/OS-II and the Xilinx MicroBlaze
💻 C
字号:
/***********************************************************************************************************                                                uC/OS-II*                                          The Real-Time Kernel**                            (c) Copyright 1992-2006, Micrium, Inc., Weston, FL*                                           All Rights Reserved**                                          Board Support Package*                                              Xilinx ML403**********************************************************************************************************/#include "bsp.h"/***********************************************************************************************************                                                LED_On()** Description : This function is used to control any or all the LEDs on the board.** Arguments   : led    is the number of the LED to control** Returns     : None**********************************************************************************************************/void  LED_On (INT8U led){    INT32U  led_status;#if OS_CRITICAL_METHOD == 3                        /* Allocate storage for CPU status register         */    OS_CPU_SR  cpu_sr;#endif        led_status = XGpio_mGetDataReg(BSP_GPIO_ADDR,1);    OS_ENTER_CRITICAL();    switch (led) {        case 0:            led_status |= 0x0000000F;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;        case 1:            led_status |= 0x00000001;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;        case 2:            led_status |= 0x00000002;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;        case 3:            led_status |= 0x00000004;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;        case 4:            led_status |= 0x00000008;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;    }    OS_EXIT_CRITICAL();}/***********************************************************************************************************                                               LED_Off()** Description : This function is used to control any or all the LEDs on the board.** Arguments   : led    is the number of the LED to turn OFF** Returns     : None**********************************************************************************************************/void  LED_Off (INT8U led){    INT32U  led_status;#if OS_CRITICAL_METHOD == 3                        /* Allocate storage for CPU status register         */    OS_CPU_SR  cpu_sr;#endif        led_status = XGpio_mGetDataReg(BSP_GPIO_ADDR,1);    OS_ENTER_CRITICAL();    switch (led) {        case 0:            led_status &= ~0x0000000F;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;        case 1:            led_status &= ~0x00000001;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;        case 2:            led_status &= ~0x00000002;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;        case 3:            led_status &= ~0x00000004;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;        case 4:            led_status &= ~0x00000008;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;    }    OS_EXIT_CRITICAL();}/***********************************************************************************************************                                             LED_Toggle()** Description : This function is used to alternate the state of an LED** Arguments   : led    is the number of the LED to control** Returns     : None**********************************************************************************************************/void  LED_Toggle (INT8U led){    INT32U  led_status;#if OS_CRITICAL_METHOD == 3                        /* Allocate storage for CPU status register         */    OS_CPU_SR  cpu_sr;#endif        led_status = XGpio_mGetDataReg(BSP_GPIO_ADDR,1);    OS_ENTER_CRITICAL();    switch (led) {        case 0:            led_status ^= 0x0000000F;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;        case 1:            led_status ^= 0x00000001;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;        case 2:            led_status ^= 0x00000002;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;        case 3:            led_status ^= 0x00000004;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;        case 4:            led_status ^= 0x00000008;            XGpio_mSetDataReg(BSP_GPIO_ADDR,1,led_status);            break;    }    OS_EXIT_CRITICAL();}/***********************************************************************************************************                                               LED_Init()** Description: This function initializes all of the board's LEDs** Arguments  : None** Returns    : None**********************************************************************************************************/void  LED_Init (void) {    XGpio_mWriteReg(BSP_GPIO_ADDR, XGPIO_TRI_OFFSET, 0x00000000);     LED_Off(0);                                    /* Turn off all of the LEDs                         */}/***********************************************************************************************************                                           BSP_Timer1Handler()* * Description: This function services interrupts produced by the timer counter.  These interrupts serve*              as uC/OS-II's tick source.* Arguments  : baseaddr_p     is a pointer to the XTmrCtr driver structure** Returns    : None**********************************************************************************************************/void  BSP_Timer1Handler (void *baseaddr_p){             int baseaddr;    unsigned int csr;    baseaddr = *(int *)baseaddr_p;    csr      = XTmrCtr_mGetControlStatusReg(BSP_TIMER1_ADDR, 0);    if (csr & XTC_CSR_INT_OCCURED_MASK) {                      XTmrCtr_mSetControlStatusReg(BSP_TIMER1_ADDR, 0, csr);                                                    /* Notify uC/OS-II that a tick interrupt occurred   */        OSTimeTick();                                                    }}/***********************************************************************************************************                                               Tmr_Init()** Description: This function should intialize the timers used by your application** Arguments  : None** Returns    : None**********************************************************************************************************/void  Tmr_Init (void){                                                   /* Set the timer's period                           */    XTmrCtr_mSetLoadReg(BSP_TIMER1_ADDR, 0, BSP_TMR_VAL);                                                    /* Reset the timer                                  */    XTmrCtr_mSetControlStatusReg(BSP_TIMER1_ADDR, 0, XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK);                                                   /* Start the timer                                  */    XTmrCtr_mSetControlStatusReg(BSP_TIMER1_ADDR, 0, XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK | XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK);}/***********************************************************************************************************                                            BSP_IntHandler()** Description: This function is called by OS_CPU_ISR() in os_cpu_a.s to service all active interrupts *              from the interrupt controller.  Two versions of this function are provided.  One of these *              versions uses the interrupt controller's IVR to determine the highest priority pending *              interrupt, while the other version consults the relevant status register.  The code that *              uses the IVR is capable of processing interrupts quickly, so the relatively slow code that *              uses a status register is excluded with a #if 0 directive.  If, however, your interrupt *              controller has been modified from the default configuration and it doesn't offer the IVR, *              you will need to place a #if 0 around the faster code, and include the code that is *              currently ignored in your project.**              Handlers for devices connected to the interrupt controller can be registered in one of *              two ways: via the "Interrupt Handlers" section of your project's "Software Platform*              Settings", or by calling XIntc_Connect(), which is used to register a handler for the *              operating system's tick interrupt in this file's BSP_InitIntCtrl().  Both of these methods *              achieve similar results, placing a pointer to your handler in the table accessed by *              BSP_IntHandler().  Regardless of which method is used, then, the interrupt corresponding *              to your device should be enabled by calling XIntc_Enable() or a similar function.* * Arguments  : None** Returns    : None**********************************************************************************************************/void  BSP_IntHandler (void) {	                                                    /* This handler uses the interrupt controller's IVR */    INT32U                  int_status;       INT32U                  int_mask;    INT32U                  int_vector;    XIntc_Config           *CfgPtr;    XIntc_VectorTableEntry *tbl_ptr;    CfgPtr = &XIntc_ConfigTable[0];    int_status = XIntc_mGetIntrStatus(BSP_INTC_ADDR);    while (int_status != 0) {                                                   /* Get the interrupts waiting to be serviced        */        int_vector = *(INT32U *)(BSP_INTC_ADDR + 0x00000018);        int_mask   = 1 << int_vector;        if (((CfgPtr->AckBeforeService) & int_mask) != 0) {            XIntc_mAckIntr(BSP_INTC_ADDR, int_mask);        }        tbl_ptr = &(CfgPtr->HandlerTable[int_vector]);        tbl_ptr->Handler(tbl_ptr->CallBackRef);    /* Call the handler assigned to the interrupt       */        if (((CfgPtr->AckBeforeService) & int_mask) == 0) {            XIntc_mAckIntr(BSP_INTC_ADDR, int_mask);        }        int_status = XIntc_mGetIntrStatus(BSP_INTC_ADDR);    }}
#if 0
void  BSP_IntHandler (void) {	 	 
	                                                    /* This handler doesn't use the IVR                 */                       Xuint32 IntrStatus;                                             Xuint32 IntrMask = 1;                                               int IntrNumber;                                                     XIntc_Config *CfgPtr;      CfgPtr = &XIntc_ConfigTable[(Xuint32)BSP_INTC_DEVICE_ID];    IntrStatus = XIntc_mGetIntrStatus(CfgPtr->BaseAddress);      for (IntrNumber = 0; IntrNumber < XPAR_INTC_MAX_NUM_INTR_INPUTS;         IntrNumber++)    {        if (IntrStatus & 1)        {            XIntc_VectorTableEntry *TablePtr;            if (CfgPtr->AckBeforeService & IntrMask)            {                XIntc_mAckIntr(CfgPtr->BaseAddress, IntrMask);            }            TablePtr = &(CfgPtr->HandlerTable[IntrNumber]);            TablePtr->Handler(TablePtr->CallBackRef);            if ((CfgPtr->AckBeforeService & IntrMask) == 0)            {                XIntc_mAckIntr(CfgPtr->BaseAddress, IntrMask);            }            if (CfgPtr->Options == XIN_SVC_SGL_ISR_OPTION)            {                return;            }        }        IntrMask <<= 1;        IntrStatus >>= 1;          if (IntrStatus == 0)        {            break;        }    } }
#endif
/***********************************************************************************************************                                            BSP_IntDisAll()* * Description: Disable all interrupts at the interrupt controller.** Arguments  : None** Returns    : None**********************************************************************************************************/void  BSP_IntDisAll (void){    XIntc_mMasterDisable(BSP_INTC_ADDR);                 }/***********************************************************************************************************                                           BSP_InitIntCtrl()** Description: This function intializes the interrupt controller by registering the appropriate handler*              functions and enabling interrupts.** Arguments  : None** Returns    : None**********************************************************************************************************/static  void  BSP_InitIntCtrl (void) {    XStatus  init_status;    XIntc    int_ctl;#if OS_CRITICAL_METHOD == 3                        /* Allocate storage for CPU status register         */    OS_CPU_SR  cpu_sr;#endif                                                       /* Initialize a handle for the interrupt controller */    init_status = XIntc_Initialize(&int_ctl, BSP_INTC_DEVICE_ID);                                                   /* Connect the first timer with its handler         */    init_status = XIntc_Connect(&int_ctl, BSP_INTC_TIMER1_ID,BSP_Timer1Handler,(void *)0);                                                   /* Enable interrupts from the first timer           */    XIntc_Enable(&int_ctl, BSP_INTC_TIMER1_ID);                                                     /* Start the interrupt controller                   */    init_status = XIntc_Start(&int_ctl, XIN_REAL_MODE);}/***********************************************************************************************************                                              BSP_InitIO()* * Description: Initialize all the I/O devices.** Arguments  : None** Returns    : None**********************************************************************************************************/void  BSP_InitIO (void)    {    BSP_InitIntCtrl();                             /* Initialize the interrupt controller              */    Tmr_Init();                                    /* Initialize the timers                            */    LED_Init();                                    /* Initialize LEDs                                  */           }

⌨️ 快捷键说明

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