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

📄 syslib.c

📁 Embedded Planet公司的ep8260单板计算机的BSP包(VxWorks)
💻 C
📖 第 1 页 / 共 4 页
字号:

    /* Wait for any previous commands to finish */
    while ( *M8260_CPCR( immrVal ) & M8260_CPCR_FLG )
	{}

    *M8260_CPCR( immrVal ) =  M8260_CPCR_RESET | M8260_CPCR_FLG;

    /* See if the command has been accepted. */
    while ( *M8260_CPCR( immrVal ) & M8260_CPCR_FLG )
    {}

    return;
}

/*******************************************************************************
*
* bootParamKeySearch - Search for the given record key and return a pointer to
*		       value associated with the key
*
* This routine searches a parameter area for the desired key value. If found it
* returns the value of the key. The key and value are in the form of:
*
*	2 character key value (PV for example) followed by an ASCII equal (=)
*       followed by an ASCII value field.
*
* RETURNS: NULL on failure or pointer the the value of the key requested.
*/

static char *bootParamKeySearch
    (
    char *token,
    char *search_area
    )
    {
    FAST char *cPtr;
    FAST int i = 0;

    cPtr = search_area;

    while (i < 256)
	{
	    if (cPtr[0] == token[0])
	    {
		if (cPtr[1] == token[1])
		    return ((char *)&cPtr[3]); /* return pointer to data after the = */
	    	else
		{
		    i++;

		    cPtr++;
		}
	    }
	    else
	    {
	    	cPtr++;
	    	i++;
	    }
	}

    return (NULL);
    }

/*******************************************************************************
*
* rpxToVxBootParams - translate the Planet Core boot parameters into a vxWorks
*		      compatible boot line and set the ethernet MAC address.
*
* This routine provides the conversion of the stored Planet Core boot parameters
* that are in DPRAM to compatible vxWorks boot parameters, system parameters and
* hardware MAC address for the ethernet. The address supplied is stored by the
* routine sysInit contained in sysALib.s
*
* RETURNS: None, parameters must have been set via Planet Core prior to running
*          vxWorks.
*/

LOCAL void rpxToVxBootParams(char *params)	/* address in DPRAM of Planet Core params to convert */
{
  char *tmpPtr, val;
  int  i, j;

    /* search for the monitor (console) port baud rate */
    tmpPtr = bootParamKeySearch ("SB", params);
    if (tmpPtr != NULL)
    	sysConsoleBaud = atoi(tmpPtr);   /* retrieve the console baud rate parameter */

    /* search for the size of 60x bus DRAM */
    tmpPtr = bootParamKeySearch ("D1", params);
    if (tmpPtr != NULL)
    	sysMemSize = atoi(tmpPtr) * 0x100000;   /* convert parameter to megabytes */

    /* search for the size of local bus DRAM */
    tmpPtr = bootParamKeySearch ("D2", params);
    if (tmpPtr != NULL)
	sysLocalBusMemSize = atoi(tmpPtr) * 0x100000;   /* convert parameter to megabytes */

    /* search for the size of DRAM */
    tmpPtr = bootParamKeySearch ("NV", params);
    if (tmpPtr != NULL)
    	sysNvRamSize = atoi(tmpPtr) * 1024;   /* convert parameter to kilobytes */

    /* search for the board type parameter */
    tmpPtr = bootParamKeySearch ("BO", params);
    if (tmpPtr != NULL)
	for (i = 0; i < (PARAM_MAX_LEN - 1); i++)
	    {
		if (*tmpPtr == 0x0a)
		    break;

    		sysBoardTypeStr[i] = *tmpPtr++;
	    }

    /* search for the board revision parameter */
    tmpPtr = bootParamKeySearch ("BR", params);
    if (tmpPtr != NULL)
	for (i = 0; i < (PARAM_MAX_LEN - 1); i++)
 	    {
		if (*tmpPtr == 0x0a)
		    break;

    		sysBoardRevStr[i] = *tmpPtr++;
	    }

    /* search for the processor type parameter */
    tmpPtr = bootParamKeySearch ("PR", params);
    if (tmpPtr != NULL)
	for (i = 0; i < (PARAM_MAX_LEN - 1); i++)
 	    {
		if (*tmpPtr == 0x0a)
		    break;

    		sysCpuTypeStr[i] = *tmpPtr++;
	    }

    /* search for the processor variant parameter */
    tmpPtr = bootParamKeySearch ("PV", params);
    if (tmpPtr != NULL)
	for (i = 0; i < (PARAM_MAX_LEN - 1); i++)
 	    {
		if (*tmpPtr == 0x0a)
		    break;

    		sysCpuVariantStr[i] = *tmpPtr++;
	    }

    /* search for the serial port parameter */
    tmpPtr = bootParamKeySearch ("SP", params);
    if (tmpPtr != NULL)
	for (i = 0; i < (PARAM_MAX_LEN - 1); i++)
 	    {
		if (*tmpPtr == 0x0a)
		    break;

    		sysSerPortStr[i] = *tmpPtr++;
	    }
    /*	search for IP parameter*/
    tmpPtr = bootParamKeySearch ("IP", params);
    if (tmpPtr != NULL)
	for (i = 0; i < (PARAM_MAX_LEN - 1); i++)
 	    {
		if (*tmpPtr == 0x0a)
		    break;

    		sysIP[i] = *tmpPtr++;
	    }
    sysIP[i] = '\0';
    /*seach for TIP parameter*/
    
    tmpPtr = bootParamKeySearch ("TI", params);
    if (tmpPtr != NULL)
	{
	tmpPtr++;
	for (i = 0; i < (PARAM_MAX_LEN - 1); i++)
 	    {
		if (*tmpPtr == 0x0a)
		    break;

    		sysTIP[i] = *tmpPtr++;
	    }

	}
    sysTIP[i] = '\0';
    /* search for the ethernet hardware MAC address */
    tmpPtr = bootParamKeySearch ("EA", params);
    if (tmpPtr != NULL)
    {
        /* de-asciify the MAC address */
        for (i = 0; i < 6; i++)
        {
            val = 0;

            for (j = 0; j < 2; j++)
            {
                if (isdigit (*tmpPtr))
                {
                    val = (val * 16) + (*tmpPtr - '0');
                    tmpPtr++;
                    continue;
                }

                if (isxdigit (*tmpPtr))
                {
                    val = (val << 4) + (*tmpPtr + 10 - (islower (*tmpPtr) ? 'a' : 'A'));
                    tmpPtr++;
                    continue;
                }

            }
#ifdef      INCLUDE_MOT_FCC
            sysFccEnetAddr[i] = val;  /* de-asciif'ied the FCC MAC address by octet */
#endif

        }
    }
}

/*
 * Create a local copy of the sysNvRamxxxx routines that make use of the Planet Core
 * parameters for the non volatile memory size.
 */

#ifndef NV_RAM_READ
#   define NV_RAM_READ(x) \
	(*(UCHAR *)((int)NV_RAM_ADRS + ((x) * NV_RAM_INTRVL)))
#endif /*NV_RAM_READ*/

#ifndef NV_RAM_WRITE
#   define NV_RAM_WRITE(x,y) \
	(*(UCHAR *)((int)NV_RAM_ADRS + ((x) * NV_RAM_INTRVL)) = (y))
#endif /*NV_RAM_WRITE*/

/******************************************************************************
*
* sysNvRamGet - get the contents of non-volatile RAM
*
* This routine copies the contents of non-volatile memory into a specified
* string.  The string is terminated with an EOS.
*
* RETURNS: OK, or ERROR if access is outside the non-volatile RAM range.
*
* SEE ALSO: sysNvRamSet()
*/

STATUS sysNvRamGet
    (
    char *string,    /* where to copy non-volatile RAM    */
    int strLen,      /* maximum number of bytes to copy   */
    int offset       /* byte offset into non-volatile RAM */
    )

    {
    offset += NV_BOOT_OFFSET;   /* boot line begins at <offset> = 0 */

    if ((offset < 0)
     || (strLen < 0)
     || ((offset + strLen) > sysNvRamSize))
        return (ERROR);

    while (strLen--)
	{
	*string = NV_RAM_READ (offset);
	string++, offset++;
	}
    *string = EOS;

    return (OK);
    }

/*******************************************************************************
*
* sysNvRamSet - write to non-volatile RAM
*
* This routine copies a specified string into non-volatile RAM.
*
* RETURNS: OK, or ERROR if access is outside the non-volatile RAM range.
*
* SEE ALSO: sysNvRamGet()
*/

STATUS sysNvRamSet
    (
    char *string,     /* string to be copied into non-volatile RAM */
    int strLen,       /* maximum number of bytes to copy           */
    int offset        /* byte offset into non-volatile RAM         */
    )

    {
    STATUS result = OK;

    offset += NV_BOOT_OFFSET;   /* boot line begins at <offset> = 0 */

    if ((offset < 0)
     || (strLen < 0)
     || ((offset + strLen) > sysNvRamSize))
        return ERROR;

    while (strLen--)
	{
	char data;

	data = *string; /* avoid any macro side effects */

	NV_RAM_WRITE (offset, data);

	/* verify data */
	if (NV_RAM_READ (offset) != (UCHAR)data)
	    {
	    result = ERROR;
	    goto exit;
	    }

	string++, offset++;
	}

exit:

    return result;
    }

/*******************************************************************************
* sysNvRamSetup - configure the MMU tables based on PlanetCore param, clear the
*                 NvRam to a known state and set the initial boot line if not
*                 set previously.
*
* RETURNS: void
*/

LOCAL void sysNvRamSetup (void)
{
char		tempStr[BOOT_LINE_SIZE];
char		*tmpPtr,ipAddrStr[PARAM_MAX_LEN];
int		i,bootLineLen;
BOOT_PARAMS	bootParamStruct;

    sysPhysMemDesc[2].len = (ULONG)sysNvRamSize;	/* set NV size based on DPRAM */

    if(sysNvRamSize != 0){	/* if we have any NVRAM, check if boot line exists */
	*BCSR2 |= 0x10;		/* enable nvram */
	sysNvRamGet(tempStr,6,0);
	if(strncmp(tempStr,"motfcc",6) && strncmp(tempStr,"cpm",3)){
		strcpy(tempStr,DEFAULT_BOOT_LINE);
		sysNvRamSet(tempStr,1 + strlen(tempStr),0);
	}
        bootLineLen = 1 + strlen((char*)(NV_RAM_ADRS+NV_BOOT_OFFSET));
        sysNvRamGet(sysBootLine,bootLineLen,0);
	bootStringToStruct(sysBootLine,&bootParamStruct);

	/* search for pCore's IP address */
	if((tmpPtr = bootParamKeySearch("IP",rpxBootParams))){
		for(i = 0;i < (PARAM_MAX_LEN - 1);++i){
			if(*tmpPtr == 0x0a)
				break;
			ipAddrStr[i] = *tmpPtr++;
		}
		ipAddrStr[i] = '\0';
		if(strcmp(ipAddrStr,bootParamStruct.ead)){
			strcpy(bootParamStruct.ead,ipAddrStr);
			bootStructToString(sysBootLine,&bootParamStruct);
			sysNvRamSet(sysBootLine,1 + strlen(sysBootLine),0);
		}
	}
    }
    return;
}

LOCAL void BootlineConfig(void)
{
	char		tempStr[BOOT_LINE_SIZE];
	char		*tmpPtr,ipAddrStr[PARAM_MAX_LEN];
	int		i,bootLineLen;
	BOOT_PARAMS	bootParamStruct;
	

	
	strcpy(tempStr,sysBootLine);
	
	/*memset(tempStr,BOOT_LINE_SIZE,0);*/

	bootStringToStruct(tempStr,&bootParamStruct);

	strcpy(bootParamStruct.ead,sysIP);

	strcpy(bootParamStruct.had,sysTIP);
	
	/*memset(tempStr,BOOT_LINE_SIZE,0);	*/

	bootStructToString(tempStr,&bootParamStruct);
	
	strcpy(sysBootLine,tempStr);
	
	return;
}
void testled(void)
{
	unsigned char *led_addr;
	unsigned char led;
	led_addr=(unsigned char *)0xfa000003;
	led=*led_addr;
	led&=0xf8;
	*led_addr=led;

}

⌨️ 快捷键说明

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