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

📄 sysinit.c

📁 这是单板上DPRAM的驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:

#if (BSP_FPU == YES)
    NodeCfg.cputype |= 0x100;
#else
    NodeCfg.cputype &= ~0x100;
#endif

anchor = &NodeCfg;

#if (SC_BOOT_ROM == YES)
rom_anchor = &NodeCfg;
#endif /* SC_BOOT_ROM */

return(FreeMemPtr);
}


/***********************************************************************/
/*     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.                                          */
/*                                                                     */
/***********************************************************************/
void SysInit(void)
{
ULONG csum, magic, StorageOffset, size, rc;
ULONG storage_update=FALSE, error_flag;
UCHAR *FreeMemPtr, *LastByte;

#if BSP_NEW_SERIAL
    int i;
#endif

#if (SC_SD_PARAMETERS == SYS_CONF)
    UCHAR DebugModeSv;
#endif

/*---------------------------------------------------------------------*/
/*                                                                     */
/*---------------------------------------------------------------------*/
/* Initialize the system variables.  If SC_SD_PARAMETERS is STORAGE,   */
/* we will attempt to read the variables from the parameter storage    */
/* area.  The parameter storage area is formatted as follows:          */
/*                                                                     */
/*     |                           |                                   */
/*     |===========================|  (lowest addr in parameter        */
/*     | "Magic #" (4 bytes)       |   storage area)                   */
/*     |===========================|                                   */
/*     | SysVars checksum (4 bytes)|                                   */
/*     |---------------------------|                                   */
/*     | SysVars                   |                                   */
/*     |===========================|                                   */
/*     | BspVars checksum (4 bytes)|                                   */
/*     |---------------------------|                                   */
/*     | BspVars                   |                                   */
/*     |===========================|                                   */
/*     | AppVars checksum (4 bytes)|                                   */
/*     |---------------------------|                                   */
/*     | AppVars                   |                                   */
/*     |===========================|                                   */
/*     |                           |                                   */
/*                                                                     */
/* BspVars is only present if BSP_PARMS is non-zero (bsp.h)            */
/* AppVars is only present if SC_APP_PARMS is non-zero (sys_conf.h)    */
/*                                                                     */
/*---------------------------------------------------------------------*/

/*---------------------------------------------------------------------*/
/* Check that the parameters will fit.  "60" is the size of SysVars.   */
/*---------------------------------------------------------------------*/
#if ((60 + BSP_PARMS + SC_APP_PARMS + 16) > 256)
    #error "Too many parameters to fit in parameter storage area"
#endif

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 (SC_SD_PARAMETERS == SYS_CONF)
    DebugModeSv = SysVars.DebugMode;
    SysVars = SysVarsDefaults;
    SysVars.DebugMode = DebugModeSv;
#endif

#if (SC_SD_DEBUG_MODE != STORAGE)
    SysVars.DebugMode = SC_SD_DEBUG_MODE;
#endif

if ((SysVars.DebugMode > 4) || (SysVars.DebugMode < 1))
    SysVars.DebugMode = 1;

StorageOffset = (ULONG)(sizeof(SysVars) + 8);

#if BSP_PARMS
    csum = NVVars.BspVars_CheckSum;
    if ((csum != CheckSum(BspVars, BSP_PARMS)) || (magic != MAGIC))
        {
        storage_update = TRUE;
        BspGetdefaults(BspVars);
        }

    #if (SC_SD_PARAMETERS == SYS_CONF)
        BspGetdefaults(BspVars);
    #endif
    StorageOffset += (BSP_PARMS + 4);
#endif

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

    #if (SC_SD_PARAMETERS == SYS_CONF)
        AppGetdefaults(AppVars);
    #endif

#endif

/*---------------------------------------------------------------------*/
/* Initialize the polled serial driver so we can use Print() to print  */
/* messages out.  The polled serial driver will also be needed for the */
/* configuration dialog if it is configured.                           */
/*---------------------------------------------------------------------*/
#if !BSP_NEW_SERIAL
    Delay100ms();
    SerialSetup(SysVars.DefBaud, PROBE_CON_SER_PORT, SC_RBUG_PORT);
    SerialPollInit();
    SerialPollOn();
    Delay100ms();
#else
    SysBaud = SysVars.DefBaud;
    SysConsole = SC_APP_CONSOLE;
#endif

/*---------------------------------------------------------------------*/
/* 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 = FreeMemStart;
FreeMemPtr = (UCHAR *)ALIGN((ULONG)FreeMemPtr, 4);

#if SC_RAM_SIZE
    LastByte = (UCHAR *)(SC_RAM_SIZE + BSP_RAM_BASE - 1);
#else
    LastByte = (UCHAR *)(RamSize() + (ULONG)BSP_RAM_BASE - 1UL);
#endif

#if BSP_NEW_SERIAL

    /*-----------------------------------------------------------------*/
    /* Set the variables ProbeCon and ProbeHst to pe used by dipi      */
    /* driver.                                                         */
    /*-----------------------------------------------------------------*/
    ProbeCon = PROBE_CON_SER_PORT;
    ProbeHst = SC_RBUG_PORT;

    /*-----------------------------------------------------------------*/
    /* Initialize the General Serial Messaage block manager            */
    /*-----------------------------------------------------------------*/
    /* Store the Starting address of the GS block area                 */
    /*-----------------------------------------------------------------*/
    #if (BSP_MMU == YES)
        FreeMemPtr = (UCHAR *)ALIGN((ULONG)FreeMemPtr, 4*1024);
        gGsBlkArea = (UCHAR *)FreeMemPtr;
    #endif                             
    FreeMemPtr = (UCHAR *)ALIGN((ULONG)FreeMemPtr, 4);
    FreeMemPtr = GSblkSetup(FreeMemPtr, (ULONG)LastByte, &error_flag);
    #if (BSP_MMU == YES)
        FreeMemPtr = (UCHAR *)ALIGN((ULONG)FreeMemPtr, 4*1024);
    #endif            
    /*-----------------------------------------------------------------*/
    /* 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                                  
    
    /*-----------------------------------------------------------------*/
    /* Initialize the lower serial driver.                             */
    /*-----------------------------------------------------------------*/
    SerialInit();

    /*-----------------------------------------------------------------*/
    /* Set up the "non pSOS serial ports" variables.                   */
    /*-----------------------------------------------------------------*/
    NumNon_pSOSChan = SC_NumNon_pSOSChan;
    i = 0;
    #if PROBE_CON_SER_PORT != 0
        Non_pSOSChan[i++] = PROBE_CON_SER_PORT;
    #endif
    #if SC_RBUG_PORT != 0
        Non_pSOSChan[i++] = SC_RBUG_PORT;
    #endif
    if (NumNon_pSOSChan < i)
	NumNon_pSOSChan = i;
#endif
     
#if !BSP_NEW_SERIAL && BSP_PARALLEL
    FreeMemPtr = (UCHAR *)ALIGN((ULONG)FreeMemPtr, 4);
    FreeMemPtr = GSblkSetup(FreeMemPtr, (ULONG)LastByte, &error_flag);
#endif
 
#   if BSP_NEW_SERIAL
        ProbeIOInit();
#   endif

#   if (BSP_NEW_SERIAL || BSP_PARALLEL)
    if (error_flag)
      {
       while(1)
          {
    Print("\n\t#############################################################\n");
    Print("\t#                                                           #\n");
    Print("\t# GSblkSetup needs more memory to configure all the MBLK's  #\n");
    Print("\t# configured in gsblk_bufcfg structure.                     #\n");
    Print("\t#                                                           #\n");
    Print("\t# You need to re-configure your GS Blocks according to      #\n");
    Print("\t# Your memory requirements.                                 #\n");
    Print("\t#                                                           #\n");
    Print("\t# Modify GS_BUFS_xx in \"sys_conf.h\" file or configure       #\n");
    Print("\t# more memory for the Board and re-run the application.     #\n");
    Print("\t#                                                           #\n");
    Print("\t#############################################################\n");
        for (rc=0; rc<50; rc++)
          Delay100ms();
          }
        }
#endif

/*---------------------------------------------------------------------*/
/* If interactive dialog is configured, do it now.                     */
/*---------------------------------------------------------------------*/
#if SC_STARTUP_DIALOG
    #if (SC_SD_PARAMETERS == SYS_CONF)
       #error "SC_SD_PARAMETERS must be STORAGE if SC_STARTUP_DIALOG is YES"
    #endif

    if ((Dialog() == YES) || (storage_update == TRUE))
        {
        Print("Updating parameter storage. "
              "This may take a while...");

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

        #if BSP_PARMS
            NVVars.BspVars_CheckSum = CheckSum(&BspVars, sizeof(BspVars));
        #endif

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

        StorageWrite(sizeof(NVVars), 0, &NVVars);
        Print("Done\n");
        }
#endif

/*---------------------------------------------------------------------*/
/* 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 BSP_VME
    SetVmeAddress(SysVars.VmeBaseAddr);
#endif

#if BSP_PARMS
    BspUse(BspVars);
#endif

#if SC_APP_PARMS
    AppUse(AppVars);
#endif

/*---------------------------------------------------------------------*/
/* Check that the parameters make sense, then build the component      */
/* configuration tables                                                */
/*---------------------------------------------------------------------*/
AdjustSysVars();

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);
#if BSP_NEW_SERIAL
    /*-----------------------------------------------------------------*/
    /* Initialize the lower serial driver.                             */
    /*-----------------------------------------------------------------*/
    SysBaud = SysVars.DefBaud;
    SerialInit();
    ProbeIOReinit();
    /*ProbeIOInit(); -- err by szg */
#else
    /*-----------------------------------------------------------------*/
    /* Set up serial driver again (in case baud rate changed).         */
    /*-----------------------------------------------------------------*/
    SerialSetup(SysVars.DefBaud, PROBE_CON_SER_PORT, SC_RBUG_PORT);
    SerialPollInit();
    SerialPollOn();
    Delay100ms();
#endif


/*---------------------------------------------------------------------*/
/* Start pROBE+ running, if it is present.  Otherwise, transfer        */
/* control directly to pSOS+.                                          */
/*---------------------------------------------------------------------*/
#if SC_PROBE
    #if SC_BOOT_ROM
        if(SysVars.DebugMode == DBG_XS)

            Print("pROBE+ is now ready to talk to the host debugger"
                  " over this serial channel...\n");
	    else if (SysVars.DebugMode == DBG_XN)
            Print("pROBE+ is now ready to talk to the host debugger"
                  " over the network...\n");
     #endif
#if (SC_PROBE == USEROM)
    pROBE_tmp = (ULONG(*)(void))((ULONG)(NodeCfg.probect->td_code) +
    ENTRY_START_OFFSET + (ENTRY_LENGTH * PROBE_INIT_OFFSET));
    rc = (*pROBE_tmp)();

#else

    rc = pROBE_Init();
#endif
    while(1)
        {
        Print("pROBE+ Initialization Failed, Error Code 0x%08X\n", rc);
        Delay5sec();
        }

#elif (SC_PSOS || SC_PSOSM)

#if !BSP_NEW_SERIAL
    SerialPollOff();
#else
    ProbeExit();
#endif

#if ((SC_PSOS == USEROM) || (SC_PSOSM == USEROM))
    pSOS_tmp = (ULONG(*)(void))((ULONG)(NodeCfg.psosct->kc_psoscode) +
    ENTRY_START_OFFSET);
    rc = (*pSOS_tmp)();

#else

    PSOS_INIT();
#endif

#else
#if !BSP_NEW_SERIAL
    SerialPollOff();
#else
    ProbeExit();
#endif
    AppCode();   /* Not using pSOS or pROBE */
#endif

}

static void Delay5sec(void)
{
    ULONG i;
 
    for (i=0; i<50; i++)
        Delay100ms();
}
 
#if __cplusplus
}
#endif

⌨️ 快捷键说明

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