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

📄 sysinit.c

📁 这是ARM在Vxworks的驱动源代码
💻 C
字号:
/***********************************************************************/
/*                                                                     */
/*   MODULE:  configs/std/sysinit.c                                    */
/*   DATE:    99/02/23                                                 */
/*   PURPOSE: Main system configuration file                           */
/*                                                                     */
/*                                                                     */
/*   This code in this module controls the configuration of the        */
/*   operating system.  Many configurations are possible, based on     */
/*   these inputs:                                                     */
/*     * Options selected in "sys_conf.h"                              */
/*     * The capabilities of the board-support package being used,     */
/*       as defined in "bsp.h"                                         */
/*     * Answers given to questions in the startup configuration       */
/*       dialog, if it is enabled                                      */
/*                                                                     */
/***********************************************************************/
#ifdef __cplusplus
extern "C" {
#endif

#define _SYSINIT_C 1
#include <vxWorks.h>
#include "sys_conf.h"
#include "bsp.h"
/*#include <drv_intf.h>*/
#include <bspfuncs.h>
/*#include <pna.h>
#include <configs.h>
#include <apdialog.h>*/
#include <version.h>
#include <mmulib.h>
#include <sysvars.h>

#if BSP_NEW_SERIAL
#include <disi.h>
#endif

#define TEST_FREEMEMPTR	0
extern void BspRawPrint(char * format,...);
extern UCHAR *FlashConfig(UCHAR*);
extern void reset_watch_dog(void);
UCHAR *FreeMemStart;
/*---------------------------------------------------------------------*/
/* User defined Tick Handler. If can be set to point to user defined   */
/* function, Which will be called from the Timer ISR                   */
/* anchor->psosct->kc_ticks2sec times_per_second.                      */
/*---------------------------------------------------------------------*/
void (*PssUserTickHandler)(void);

#if (BSP_SMEM && SC_PSOSM && (BSP_INT_MODE == 0))
extern void  ki_check(void);
extern UCHAR KiUp;
#endif
#define LED_CTRL_REG				((volatile uchar *)0xc8004003)

/*---------------------------------------------------------------------*/
/* This flag is cleared during .bss clearing at startup time.  It is   */
/* set to 1 by the task start callout in this module.                  */
/*---------------------------------------------------------------------*/
unsigned long PsosUpFlag;

static void (* volatile dummy)(void);

NV_Parms NVVars;

extern ULONG Dialog(void);

/*---------------------------------------------------------------------*/
/* Compile-time checks                                                 */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* External function declarations                                      */
/*---------------------------------------------------------------------*/
extern ULONG Print(char *format, ...);

#if !BSP_NEW_SERIAL
    extern void SerialSetup(ULONG, ULONG, ULONG);
#endif

#define SC_DRAM_SIZE		0xA000
#define MAGIC 0x65291989
#define ALIGN(addr, boundary) ((addr + boundary - 1) & ~(boundary - 1))

const char MemErrMsg[] =
  "System Initialization Failed: insufficient memory available!";

static const struct SD_parms SysVarsDefaults =
    {
    "lnPci",
    "TFTP",
    0,
    "192.2.2.42",
    "255.255.255.0",
    "192.2.2.40",
	"0.0.0.0",
	"vxworks",
	"aaa",
	"aaaaaa",
	0,
	0x80,
	0
	};

#if 0
    #if (BSP_MMU == YES)
        UCHAR *gGsBlkArea;          /* Start address of the GS block area */
        ULONG  gGsBlkAreaSize = 0;  /* Size of the allocated region */
    #endif
                                                    
    extern UCHAR *GSblkSetup(UCHAR *, ULONG, ULONG *);
    extern void SerialInit(void);

    /*-----------------------------------------------------------------*/
    /* Global variables set here used by dipi                          */
    /*-----------------------------------------------------------------*/
    int ProbeCon, ProbeHst;

#endif

#if 1
extern unsigned char *GSblkSetup(unsigned char *FreeMemPtr, ULONG ramsize, ULONG *error);
    #if (BSP_MMU == YES)
        UCHAR *gGsBlkArea;          /* Start address of the GS block area */
        ULONG  gGsBlkAreaSize = 0;  /* Size of the allocated region */
    #endif
#endif
extern UCHAR *BspSetup(unsigned char *freeMemPtr);

/*******************************************************************/
/*    CheckSum: Calculate the checksum for a STORAGE structure     */
/*                                                                 */
/*      INPUTS: StructPtr - ptr to structure to checksum           */
/*              StructSize - size of structure in bytes            */
/*     RETURNS: Checksum for the structure                         */
/*        NOTE: We consider the "checksum" to be simply the sum of */
/*              the individual bytes in the structure              */
/*                                                                 */
/*******************************************************************/
ULONG CheckSum(void *StructPtr, int StructSize)
{
	UCHAR *p = (UCHAR *)StructPtr;
	USHORT tot = 0;

	while(StructSize--)
		tot += *p++ & 0xFF;
	return tot;
}

/***********************************************************************/
/* BuildConfigTables: Build the component configuration tables, using  */
/*                    information from the system variables (SysVars). */
/*                                                                     */
/*       INPUT: FreeMemPtr - Pointer to first byte of available memory */
/*                                                                     */
/***********************************************************************/
static UCHAR *BuildConfigTables(UCHAR *FreeMemPtr)
{
char * freemem_p;
/*---------------------------------------------------------------------*/
/* Perform any BSP specific configuration functions.                   */
/* This should be done prior to calling PnaSetup & PnetSetup.          */
/*---------------------------------------------------------------------*/
	freemem_p=FreeMemPtr;
	freemem_p = (UCHAR *)ALIGN((ULONG)freemem_p, 4);
	freemem_p = (UCHAR *)BspSetup(freemem_p);
	return(freemem_p);
}


/***********************************************************************/
/*     SysInit: Initialize system variables, conduct startup dialog    */
/*              if configured, and set up component configuration      */
/*              tables.                                                */
/*                                                                     */
/*        NOTE: Interrupts are assumed to be disabled upon entry to    */
/*              this routine.                                          */
/*                                                                     */
/***********************************************************************/
extern char *dram;
char * SysInit(char * freemem_p)
{
	ULONG csum, magic, size, rc;
	ULONG storage_update=FALSE, error_flag;
	UCHAR *FreeMemPtr, *LastByte;

#if BSP_NEW_SERIAL
    int i;
#endif
#if 1
	StorageRead(sizeof(NVVars), 0, &NVVars);

	magic = NVVars.magic;
	csum = NVVars.SysVars_CheckSum;
	if ((csum != CheckSum(&SysVars, sizeof(SysVars))) || (magic != MAGIC))
    {
		storage_update = TRUE;
		SysVars = SysVarsDefaults;
    }

#if 0
#if SC_APP_PARMS
    csum = NVVars.AppVars_CheckSum;
    if ((csum != CheckSum(AppVars, SC_APP_PARMS)) || (magic != MAGIC))
    {
        storage_update = TRUE;
        AppGetdefaults(AppVars);
    }
#endif
#endif

if ((storage_update == TRUE))
    {
        /*-------------------------------------------------------------*/
        /* Save changed system variables in parameter storage area     */
        /*-------------------------------------------------------------*/
        NVVars.magic = MAGIC;
        NVVars.SysVars_CheckSum = CheckSum(&SysVars, sizeof(SysVars));

        #if SC_APP_PARMS
            NVVars.AppVars_CheckSum = CheckSum(&AppVars, sizeof(AppVars));
        #endif

        StorageWrite(sizeof(NVVars), 0, &NVVars);
    }
#endif
	FreeMemStart = freemem_p;
/*---------------------------------------------------------------------*/
/* The memory starting at "FreeMemStart" is available for allocation.  */
/* Call any high-level drivers that are configured so they can grab    */
/* some of this memory if they need it.  This technique allows us to   */
/* build systems in which the drivers use different numbers of buffers */
/* without having to re-compile the drivers.                           */
/*---------------------------------------------------------------------*/
	FreeMemPtr = freemem_p;
	FreeMemPtr = (UCHAR *)ALIGN((ULONG)FreeMemPtr, 4);
    LastByte = (UCHAR *)(RamSize() + (ULONG)BSP_RAM_BASE - 1UL);

#if 1
	FreeMemPtr = (UCHAR *)ALIGN((ULONG)FreeMemPtr, 4);
	FreeMemPtr = FlashConfig(FreeMemPtr);	/*flash size and base not get yet*/
#endif

	FreeMemPtr = (UCHAR *)ALIGN((ULONG)FreeMemPtr, 4);
    FreeMemPtr = GSblkSetup(FreeMemPtr, (ULONG)LastByte, &error_flag);

	FreeMemPtr = (UCHAR *)ALIGN((ULONG)FreeMemPtr, 4);
    
    /*FreeMemPtr = (UCHAR *)ALIGN((ULONG)FreeMemPtr, PAGE_SIZE);
	*/
    /*-----------------------------------------------------------------*/
    /* Get the size of the GS block area allocated                     */
    /* Note: The two global variables, gGsBlkArea and gGsBlkAreaSize   */
    /*       are used by the MMU module to non-cache this region.      */
    /*-----------------------------------------------------------------*/
#if (BSP_MMU == YES)
    gGsBlkAreaSize = (ULONG)(FreeMemPtr - gGsBlkArea);
#endif    
	/*fanghao(7200)(A)*/
	SerialInit();
	
#if 1

/*---------------------------------------------------------------------*/
/* The parameters are now set - so do the following:                   */
/*    * Call BSP to advise it of VME base address (if appropriate)     */
/*    * Advise BSP and application of "final" values of their          */
/*      parameters (if appropriate)                                    */
/*---------------------------------------------------------------------*/
#if SC_APP_PARMS
    AppUse(AppVars);
#endif
#endif

#if 0
    BspUse(BspVars);
#endif

/*---------------------------------------------------------------------*/
/* Check that the parameters make sense, then build the component      */
/* configuration tables                                                */
/*---------------------------------------------------------------------*/
	FreeMemPtr = BuildConfigTables(FreeMemPtr);
/*---------------------------------------------------------------------*/
/* Check FreeMemPtr to make sure it has not over run memory!           */
/* NOTE: If pSOS+ has been configured into the system, the FreeMemPtr  */
/*       is now part of pSOS+ region zero!  So it can't be used to     */
/*       allocate any more memory after this.                          */
/*---------------------------------------------------------------------*/

	if (FreeMemPtr > LastByte)
		SysInitFail(MemErrMsg);

	dram = (char*)(BoardInfoDramSize() + BSP_RAM_BASE - SC_DRAM_SIZE);

return FreeMemPtr;
}

/*****************************************/
#if SC_APP_PARMS
#include <boot/convert.h>
static void AppGetdefaults(void *vp)
{
	APP_INFO	*info;
	EPPROM_INFO	*rom_info;
	ULONG		l;

	rom_info=(EPPROM_INFO*)BoardInfoEpromInfoBase();

	info=(APP_INFO*)vp;

	info->FlashType=rom_info->FlashType;
	info->FlashDataWide=rom_info->FlashDataWide;
	info->ram_size=rom_info->ram_size;
	info->rom_version=rom_info->rom_version;
	info->hw_version=rom_info->hw_version;
	info->serialnum=rom_info->serialnum;
	memcpy(info->hwaddr,rom_info->hwaddr,6);

	info->entry=0x200004;				/*SW entry pointer*/
	info->version=0;
	info->year=2000;
	info->month=3;	
	info->day=19;
	info->hour=20;
	info->min=9;	
	info->second=0;
	strncpy(info->name,"router.bin",APP_INFO_NAME_LEN-1);

}


/***************************************************/
/* set some para to bsp_parm,according the app_parm*/
/***************************************************/
void AppUse(void *ParmStruct)
{
	/*This function will not be called if SC_PROBE is set*/
	APP_INFO	*app_info;
	app_info=(APP_INFO	*)ParmStruct;
	/*In this case, this is a boot program(bin).*/
#if 0
	app_info->hwaddr[0]=0;
	app_info->hwaddr[1]=0xe0;
	app_info->hwaddr[2]=0x0f;
	app_info->hwaddr[3]=0x88;
	app_info->hwaddr[4]=0x00;
	app_info->hwaddr[5]=0x00;
#endif
	SetBoardInfoEtherBase(app_info->hwaddr);
	SetBoardInfoFreeEtherAddr(app_info->hwaddr);
}
#endif 

#ifdef __cplusplus
}
#endif

⌨️ 快捷键说明

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