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

📄 syslib.c

📁 VxWorks BSP for AT91RM92
💻 C
📖 第 1 页 / 共 2 页
字号:
    {
    static BOOL initialised = FALSE;

    if (initialised)
    	return;

	/* initialise the interrupt library and interrupt driver */

	intLibInit (AT91_INT_NUM_LEVELS, AT91_INT_NUM_LEVELS, INT_MODE);
	at91IntDevInit();


	/* configure timer interrupt polarities and types */

	at91IntLvlConfigure (SYS_TIMER_INT_LVL, AT91C_AIC_SRCTYPE_INT_EDGE_TRIGGERED);
	at91IntLvlConfigure (AUX_TIMER_INT_LVL, AT91C_AIC_SRCTYPE_INT_EDGE_TRIGGERED);


	/* connect sys clock interrupt and auxiliary clock interrupt */

	(void)intConnect (INUM_TO_IVEC (SYS_TIMER_INT_VEC), sysClkInt, 0);
	(void)intConnect (INUM_TO_IVEC (AUX_TIMER_INT_VEC), sysAuxClkInt, 0);

    /* system peripheral */

	at91IntLvlConfigure (INT_LVL_SYS, AT91C_AIC_SRCTYPE_INT_EDGE_TRIGGERED);

	(void)intConnect (INUM_TO_IVEC (INT_VEC_SYS), sysPeripheralIntHandler, 0);

#ifdef INCLUDE_SERIAL
    
	/* configure serial interrupt polarities and types */

	at91IntLvlConfigure (INT_LVL_SERIAL_1, AT91C_AIC_SRCTYPE_INT_EDGE_TRIGGERED);

    /* connect serial interrupt */
    sysSerialHwInit2();

#endif /* INCLUDE_SERIAL */

#if defined(INCLUDE_NETWORK) && defined(INCLUDE_END)

    /* init END device table */
    sysLanInit ();  /* sysEnd.c */

#endif /* INCLUDE_NETWORK && INCLUDE_END */

    initialised = TRUE;

    /* switch off all user LEDs */
    PIOB_REG(PIO_SODR) = LED_LEDS_MASK;

#ifdef INCLUDE_HEART_BEAT
    /* start heart beat activity */
    sysHeartBeatWdId = wdCreate();
    (void) wdStart(sysHeartBeatWdId, sysClkRateGet()/2, (FUNCPTR) sysHeartBeat, 0);
#endif /* INCLUDE_HEART_BEAT */
    }

/*******************************************************************************
*
* sysPhysMemTop - get the address of the top of physical memory
*
* This routine returns the address of the first missing byte of memory,
* which indicates the top of memory.
*
* Normally, the user specifies the amount of physical memory with the
* macro LOCAL_MEM_SIZE in config.h.  BSPs that support run-time
* memory sizing do so only if the macro LOCAL_MEM_AUTOSIZE is defined.
* If not defined, then LOCAL_MEM_SIZE is assumed to be, and must be, the
* true size of physical memory.
*
* NOTE: Do no adjust LOCAL_MEM_SIZE to reserve memory for application
* use.  See sysMemTop() for more information on reserving memory.
*
* RETURNS: The address of the top of physical memory.
*
* SEE ALSO: sysMemTop()
*/

char * sysPhysMemTop (void)
    {
    static char * physTop = NULL;

    if (physTop == NULL)
        {
#ifdef LOCAL_MEM_AUTOSIZE

#error   "Dynamic memory sizing not supported"

#else
        /* Don't do autosizing, if size is given */

        physTop = (char *)(LOCAL_MEM_LOCAL_ADRS + LOCAL_MEM_SIZE);

#endif /* LOCAL_MEM_AUTOSIZE */
        }

    return physTop;
    }

/*******************************************************************************
*
* sysMemTop - get the address of the top of VxWorks memory
*
* This routine returns a pointer to the first byte of memory not
* controlled or used by VxWorks.
*
* The user can reserve memory space by defining the macro USER_RESERVED_MEM
* in config.h.  This routine returns the address of the reserved memory
* area.  The value of USER_RESERVED_MEM is in bytes.
*
* RETURNS: The address of the top of VxWorks memory.
*/

char * sysMemTop (void)
    {
    static char * memTop = NULL;

    if (memTop == NULL)
	{
	memTop = sysPhysMemTop () - USER_RESERVED_MEM;
	}

    return memTop;
    }

/*******************************************************************************
*
* sysToMonitor - transfer control to the ROM monitor
*
* This routine transfers control to the ROM monitor.  It is usually called
* only by reboot() -- which services ^X -- and bus errors at interrupt
* level.  However, in some circumstances, the user may wish to introduce a
* new <startType> to enable special boot ROM facilities.
*
* RETURNS: Does not return.
*/

STATUS sysToMonitor
    (
    int startType	/* passed to ROM to tell it how to boot */
    )
    {
    FUNCPTR	pRom;
    UINT32 *	p = (UINT32 *)ROM_TEXT_ADRS;

#ifdef INCLUDE_SERIAL
    sysSerialReset ();	/* put serial devices into quiet state */
#endif

    /*
     * Examine ROM - if it's a VxWorks boot ROM, jump to the warm boot entry
     * point; otherwise jump to the start of the ROM.
     * A VxWorks boot ROM begins
     *    MOV	R0,#BOOT_COLD
     *    B	...
     *    DCB	"Copyright"
     * We check the first and third words only. This could be tightened up
     * if required (see romInit.s).
     */
                         
    if (p[0] == 0xE3A00002 && p[2] == 0x706F430A)
        pRom = (FUNCPTR)(ROM_TEXT_ADRS + 4);	/* warm boot address */
    else
        pRom = (FUNCPTR)ROM_TEXT_ADRS;		    /* start of ROM */

    VM_ENABLE(FALSE);	/* disable the MMU, cache(s) and write-buffer */

    /*
     * On 920T, can have the I-cache enabled once the MMU has been
     * disabled, so, unlike the other processors, disabling the MMU does
     * not disable the I-cache.  This would not be a problem, as the
     * 920T boot ROM initialisation code disables and flushes both caches.
     * However, in case we are, in fact, using a 7TDMI boot ROM,
     * disable and flush the I-cache here, or else the boot process may
     * fail.
     */

    cacheDisable (INSTRUCTION_CACHE);

    (*pRom)(startType);	/* jump to boot ROM */

    return OK;		/* in case we ever continue from ROM monitor */
    }

/****************************************************************************
*
* sysProcNumGet - get the processor number
*
* This routine returns the processor number for the CPU board, which is
* set with sysProcNumSet().
*
* RETURNS: The processor number for the CPU board.
*
* SEE ALSO: sysProcNumSet()
*/

int sysProcNumGet (void)
    {
    return 0;
    }

/****************************************************************************
*
* sysProcNumSet - set the processor number
*
* Set the processor number for the CPU board.  Processor numbers should be
* unique on a single backplane.
*
* NOTE
* By convention, only processor 0 should dual-port its memory.
*
* RETURNS: N/A
*
* SEE ALSO: sysProcNumGet()
*/

void sysProcNumSet
    (
    int procNum		/* processor number */
    )
    {
    sysProcNum = procNum;
    }

/******************************************************************************
*
* sysLedSet - set a user LED value
*
* This routine can be used to set or unset a LEDs
* TRUE switches the LED on; FALSE switches off.
*
* RETURNS: previous state of LEDs.
*/

int sysLedSet
    (
    int led,
    BOOL flag
    )
    {
    int	 	    current;
    UINT32      value;

    /* read current value from hardware and mask off undefined bits */
    current  = (int) ((~PIOB_REG(PIO_PDSR)) & LED_LEDS_MASK);

    /* set new value */
    value = ((UINT32) led) & LED_LEDS_MASK;

    if (flag)
        {
        PIOB_REG(PIO_CODR) = value;
        }
    else
        {
        PIOB_REG(PIO_SODR) = value;
        }

    return (current);
    }


#ifdef INCLUDE_HEART_BEAT
/******************************************************************************
*
* sysHeartBeat - system heart beat
*
* This routine uses the user LED 0 to signal life activity.
*
* RETURNS: N/A
*/

void sysHeartBeat
    (
    void
    )
    {
    static int flipFlop = 0;
    
    flipFlop = 1 - flipFlop;    /* will always be 0 or 1 */
    
    sysLedSet(USRLED0, flipFlop);

    if (sysHeartBeatWdId != NULL)
        {
        (void) wdStart(sysHeartBeatWdId, sysClkRateGet()/2, (FUNCPTR) sysHeartBeat, 0);
        }
    }
#endif /* INCLUDE_HEART_BEAT */

#ifdef INCLUDE_FLASH
/******************************************************************************
*
* sysFlashWriteEnable - enable write access to the Flash memory
*
* This routine is used by flashMem.c to enable write access to the
* Flash memory.
*
* RETURNS: N/A
*/

void sysFlashWriteEnable (void)
     {
     /* TODO - Enable Vpp and write access */
     }

/******************************************************************************
*
* sysFlashWriteDisable - disable write access to the Flash memory
*
* This routine is used by flashMem.c to disable write access to the
* Flash memory.
*
* RETURNS: N/A
*/

void sysFlashWriteDisable (void)
     {
     /* TODO - Disable Vpp and write access */
     }
#endif /* INCLUDE_FLASH */

/*******************************************************************************
*
* sysPeripheralIntHandler - system peripheral interrupt handler
*
* This routine checks the origin of the interrupt and call the appropriate function.
*
* RETURNS: N/A.
*/

void sysPeripheralIntHandler
    (
    void
    )
    {
    VOIDFUNCPTR func;
    int         arg;
#ifdef CHECK_STATUS
    UINT32      status;
    UINT32      mask;
    UINT32      regStatus;
    UINT32      regMask;
#endif
    int         i;
    BOOL        enabled;

    /* check interrupt source and call appropriate handler */
    for (i = 0; i < SP_MAX_ID; i++)
        {
        /*
         * we should check which system peripheral generated the interrupt,
         * but reading the status register, reset the status and the called handler cannot check the reason.
         */
        enabled   = sysPeripheralHandlerTbl[i].enabled;

#ifdef CHECK_STATUS
        regStatus = sysPeripheralHandlerTbl[i].regStatus; 
        regMask   = sysPeripheralHandlerTbl[i].regMask;

        status = *((volatile UINT32 *) regStatus);
        mask   = *((volatile UINT32 *) regMask);

        if ((mask & status) && enabled)
            {
            func = sysPeripheralHandlerTbl[i].func;
            arg  = sysPeripheralHandlerTbl[i].arg;

            if (func != NULL)
                (*func) (arg);

            }
#else
        if (enabled)
            {
            func = sysPeripheralHandlerTbl[i].func;
            arg  = sysPeripheralHandlerTbl[i].arg;

            if (func != NULL)
                (*func) (arg);

            }
#endif
        }
    }

/*******************************************************************************
*
* sysPeripheralIntConnect - connect a routine to a system peripheral interrupt
*
* The user specified interrupt handling routine is connected to the specified
* vector.
*
* RETURNS: OK or ERROR for invalid arguments.
*/

STATUS sysPeripheralIntConnect
    (
    int         sysPeripheralId, /* System Peripheral ID */
    VOIDFUNCPTR routine,         /* routine to connect */
    int         arg              /* associated argument */
    )
    {
    if (sysPeripheralId < 0 || sysPeripheralId > SP_MAX_ID)
        {
        return (ERROR);
        }

    sysPeripheralHandlerTbl[sysPeripheralId].func = routine;
    sysPeripheralHandlerTbl[sysPeripheralId].arg  = arg;

    return (OK);
    }


/*******************************************************************************
*
* sysPeripheralIntEnable - enable system peripheral interrupts
*
* Enable system peripheral interrupts.
*
* RETURNS: OK or ERROR for invalid arguments.
*/

STATUS sysPeripheralIntEnable
    (
    int     sysPeripheralId /* System Peripheral ID */
    )
    {
    if (sysPeripheralId < 0 || sysPeripheralId > SP_MAX_ID)
        {
        return (ERROR);
        }
    
    sysPeripheralHandlerTbl[sysPeripheralId].enabled = TRUE;
    
    return(intEnable(AT91C_ID_SYS));
    }

/*******************************************************************************
*
* sysPeripheralIntDisable - disable system peripheral interrupts
*
* Disable system peripheral interrupts.
*
* RETURNS: OK or ERROR for invalid arguments.
*/

STATUS sysPeripheralIntDisable
    (
    int     sysPeripheralId /* System Peripheral ID */
    )
    {
    int     i;
    BOOL    found = FALSE;
    STATUS  status = OK;
    
    if (sysPeripheralId < 0 || sysPeripheralId > SP_MAX_ID)
        {
        return (ERROR);
        }
    
    sysPeripheralHandlerTbl[sysPeripheralId].enabled = FALSE;

    /* check if any peripheral still enabled */
    for (i = 0; i < SP_MAX_ID; i++)
        {
        if (sysPeripheralHandlerTbl[sysPeripheralId].enabled)
            {
            found = TRUE;
            break;
            }
        }

    if (!found)
        {
        status = intDisable(AT91C_ID_SYS);
        }
    
    return(status);
    }

/*******************************************************************************
*
* sysDelay - a small delay
*
*/

void sysDelay (void)
    {
    volatile UINT32 p;
    volatile int    i;

    for (i = 0; i < 1000; i++)
        {
        /* Read from ROM, a known timing */

        p = *((volatile UINT32 *) ROM_TEXT_ADRS);
    
        /*
         * Create a little more delay: some arithmetic operations that
         * involve immediate constants that cannot be performed in one
         * instruction.  Clearly it is possible that compiler changes will
         * affect this code and leave this no longer calibrated.
         */
    
        p &=0xffff;
        p +=0xff11;
        p +=0xff51;
        }

    return;
    }


⌨️ 快捷键说明

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