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

📄 stboot.c

📁 st boot Linux 源码示范程序。 可以移植到其他平台
💻 C
📖 第 1 页 / 共 2 页
字号:
                
        default:
            /* Note: we only range check MemorySize
               if it is required for this platform */
            return ST_ERROR_BAD_PARAMETER;
            break;
    }

#endif /* !ST_5514 !ST_5516 !ST_5517 !ST_5528 !ST_5100 !ST_5101 !ST_7710 !ST_5105 !ST_5700 !ST_5188 !ST_5107 defined ] */
#endif /* !mb295 */

#if defined(mb295) || defined (mb290)
    /* Initialize MPEG backend; 7020 STEM requires reset via I2C,
      so is deferred until STBOOT_Init7020STEM */
      
    ErrorCode = stboot_BackendInit7015(InitParams_p->SDRAMFrequency);
    if ( ErrorCode != ST_NO_ERROR )
    {
        return ErrorCode;
    }
#endif

    return ErrorCode;
#endif /*#ifdef ST_OS20*/

/************************ FOR OS21 ******************************/
#ifdef ST_OS21
    
    /*ICache config for ST200*/
    #ifdef ARCHITECTURE_ST200
    if(InitParams_p->ICacheEnabled == FALSE)
    {
    	return ST_ERROR_FEATURE_NOT_SUPPORTED; /*Icache not to be disabled on ST200 devices*/
    }
    #endif
    
    /*DCache config for ST200*/
    #ifdef ARCHITECTURE_ST200
    #ifdef STBOOT_SPECIFY_HOST_MEMORY_MAP
    ErrorCode = stboot_st200_InitDCache_Specified_Host_Map((STBOOT_InitParams_t *) InitParams_p);
    #else
    ErrorCode = stboot_st200_InitDCache((STBOOT_InitParams_t *) InitParams_p);
    #endif
    if (ErrorCode != ST_NO_ERROR)
    {
        return ErrorCode;
    }
    #endif
    
    /* Initialize & start the OS21 kernel */
    if (kernel_initialize(NULL) != 0)
    {
        return STBOOT_ERROR_KERNEL_INIT;
    }
    else if (kernel_start() != 0)       /* Start the kernel */
    {
        return STBOOT_ERROR_KERNEL_START;
    }
    
    /*ICache config for ST40 */
    #ifdef ARCHITECTURE_ST40
    if(InitParams_p->ICacheEnabled == FALSE)
    {
    	cache_disable_instruction();
    }
    #endif
    
    /*DCache config for ST40 */
    #ifdef ARCHITECTURE_ST40
    if((InitParams_p->DCacheMap == NULL) || (InitParams_p->DCacheEnabled == FALSE))
    {
    	cache_disable_data(1); /*1 means data cache will be flushed before being disabled*/
    }
    #endif
    
    ErrorCode = stboot_BackendInit(NULL);
    if ( ErrorCode != ST_NO_ERROR )
    {
        return ErrorCode;
    }
    
    /*Timeslicing config for OS21, by default gets enabled*/
    if (InitParams_p->TimeslicingEnabled)
    {
    	kernel_timeslice(OS21_TRUE);
    }
    
    #ifdef ARCHITECTURE_ST200
    /*The following calls display the current memory map in a table format, can be enabled for debug*/
    #ifdef STBOOT_DISPLAY_BSP_MEMORY_MAP
    printf("\n\nUser requested dcache configuration retained (post OS21 startup):\n");
    printf("-----------------------------------------------------------------------\n");
    bsp_mmu_dump_TLB_Settings();
    bsp_scu_dump_SCU_Settings();
    printf("-----------------------------------------------------------------------\n\n");
    #endif
    #endif

    return ErrorCode;
#endif /*#ifdef ST_OS21*/
} /* STBOOT_Init() */


/* STBOOT_Init7020STEM - see sti7015/be_7015.c */

/*****************************************************************************
Name: STBOOT_GetBackendInfo()
Description:
    Obtains backend type and cut revision information.
Parameters:
    BackendInfo_p,      pointer to backend information datastructure.
Return Value:
    ST_NO_ERROR,        the operation completed without error.
See Also:
    Global table BackendLUT.
*****************************************************************************/

ST_ErrorCode_t STBOOT_GetBackendInfo(STBOOT_Backend_t *BackendInfo_p)
{
#if defined (ST_OS21)

    /* Assume unrecognised device code */
    BackendInfo_p->DeviceType    = STBOOT_DEVICE_UNKNOWN;
    BackendInfo_p->MajorRevision = STBOOT_REVISION_UNKNOWN;
    BackendInfo_p->MinorRevision = STBOOT_REVISION_UNKNOWN;
#endif

#if defined (ST_OS20)
    {
        int DeviceType;

        /* Use device_id() to obtain info */
        DeviceType = device_id().st.device_code;
    
        /* Workaround for STi5512 - not all revisions
           of 5512 have the same device_code */
        if( (DeviceType == DEVICE_5512_F ) ||
            (DeviceType == DEVICE_5512_G ) )
        {
            DeviceType = (int) STBOOT_DEVICE_5512;
        }

        BackendInfo_p->DeviceType    = (STBOOT_Device_t) DeviceType;
        BackendInfo_p->MajorRevision = device_id().st.revision;
        BackendInfo_p->MinorRevision = STBOOT_REVISION_UNKNOWN;
    }
#endif

    return ST_NO_ERROR;
}

/*****************************************************************************
Name: STBOOT_GetRevision()
Description:
    Returns the driver revision number -- may be called at any time.
Parameters:
    None.
Return Value:
    ST_Revision_t.
See Also:
    Nothing.
*****************************************************************************/

ST_Revision_t STBOOT_GetRevision(void)
{
    return Revision;
} /* STBOOT_GetRevision() */

/*****************************************************************************
Name: STBOOT_Term()
Description:
    Dummy function to comply with ST API
Parameters:
    DeviceName,     device name of boot to terminate.
    TermParams_p,   the termination parameters.
Return Value:
    ST_NO_ERROR,                   No Errors during operation
See Also:
    STBOOT_Init()
*****************************************************************************/

ST_ErrorCode_t STBOOT_Term( const ST_DeviceName_t DeviceName,
                            const STBOOT_TermParams_t *TermParams_p )
{
    return ST_NO_ERROR;
} /* STBOOT_Term() */

/* Debug routines --------------------------------------------------------- */

#ifdef ARCHITECTURE_ST20

#if (OS20_VERSION_MAJOR < 2) || ((OS20_VERSION_MAJOR == 2) && (OS20_VERSION_MINOR <= 8))

/*****************************************************************************
Name: mutex_fn()
Description:
    Function to prevent pre-emption of debug message output.
    As mentioned above, older versions of the compiler had no 2nd parameter.
Parameters:
    op                             mutex operation.
    dummy                          Not used.
Return Value:
    Not used.
See Also:
    init_debugop_protection
*****************************************************************************/

#ifdef OLD_MUTEX_FN
static long int mutex_fn(debugmutexop op)
#else
static long int mutex_fn(debugmutexop op, void *dummy)
#endif
{
    int enables; 
#ifdef C1_CORE 
    const int mask = 0xc000; 
    __asm { ld 0; statusset; st enables; } 
#else 
    const int mask = 255; 
    __asm { ld 0; gintdis; st enables; } 
#endif 

    if (enables != (enables & mask)) { return 0; } 
    if (task_context(NULL, NULL) == task_context_interrupt) { return 0; } 
    
    switch (op)
    {
        case debugmutexop_lock:
            (void) semaphore_wait (&mutex_sem);
            break;
        case debugmutexop_unlock:
            semaphore_signal (&mutex_sem);
            break;
        case debugmutexop_loop:
            task_delay(ST_GetClocksPerSecond()/10000);
            break;
    }
    return 0;
} /* mutex_fn() */

#ifndef OLD_MUTEX_FN
/*****************************************************************************
Name:   mutex_wrapper()
Description:
    Convoluted way to call a function with a static link from one without
    one, without having to put them in different modules. This function has
    no static link. Instead, the static link value is passed in the parameters
    set up in init_debugop_protection(). So we can uses this to call
    mutex_fn() in the correct way. Thus this function just acts as a wrapper
    for mutex_fn().

    This function is not needed with older version of the toolset (see above).

Parameters:
    op                             mutex operation.
    mutex_data
Return Value:
    Not used.
See Also:
    init_debugop_protection
*****************************************************************************/

static long int mutex_wrapper(debugmutexop op, mutex_data_t* mutex_data)
{
    long (*fn)(int*, debugmutexop, void *);
    #pragma ST_nolink(fn)

    fn = (long (*)(int*, debugmutexop, void*))mutex_fn;
    return fn (mutex_data->mutex_data_sl, op, mutex_data->mutex_data_user);
} /* mutex_wrapper() */
#endif

/*****************************************************************************
Name: init_debugop_protection()
Description:
    Function to prevent pre-emption of debug message output
Parameters:
    none
Return Value:
    none
See Also:
    mutex_fn(), mutex_wrapper()
*****************************************************************************/

static void init_debugop_protection(void)
{
    semaphore_init_fifo (&mutex_sem, 1);

#ifdef OLD_MUTEX_FN
    debugsetmutexfn (mutex_fn);
#else
    {
      /* The callback function needs to access static data, but has no
         static link set up. So we need to emulate one, by passing its value
         in the structure mutex_data. This structure also has a field for a
         user data ptr, but this is not used at present. */

      static mutex_data_t mutex_data;
      extern int* _params;

      mutex_data.mutex_data_sl = (int*)_params[1];  /* static link */
      mutex_data.mutex_data_user = NULL;

      debugsetmutexfn((long(*)(debugmutexop, void*))mutex_wrapper, &mutex_data);
    }
#endif
} /* init_debugop_protection() */

#endif /* (OS20_VERSION_MAJOR < 2) || ((OS20_VERSION_MAJOR == 2) && (OS20_VERSION_MINOR <= 8)) */

/*****************************************************************************
Name: InitInterrupts()
Description:
    Function initialise interrupts. Interrupt controller is initialized,
    each interrupt level is then initialised. Upon completion each int
    level is disabled.
Parameters:
    Pointer to IntTriggerMask and IntTriggerTable_p when required
Return Value:
    none
See Also:
    none
*****************************************************************************/

static ST_ErrorCode_t InitInterrupts(const STBOOT_InitParams_t *InitParams_p)
{
    U32     i;
    interrupt_trigger_mode_t trigger_mode;

    /* Initialize interrupts */
    interrupt_init_controller( (void *)INTERRUPT_CONTROLLER_BASE,
                               INTERRUPT_LEVELS,
                               (void *)INTERRUPT_LEVEL_CONTROLLER_BASE,
                               INTERRUPT_NUMBERS,
                               INTERRUPT_INPUTS_OFFSET );

    for (i=0; i < INTERRUPT_LEVELS; i++)
    {
        /* Write known data to all ISR stack areas for debugging */
        InitialiseStack( interrupt_control[i].stack_base,
                         interrupt_control[i].stack_size );

#if defined(STBOOT_CONFIGURABLE_INT_TRIGGER)
        trigger_mode = (((InitParams_p->IntTriggerMask & (1<<i))==0)?
                        (INTERRUPT_TRIGGER_MODE(i)):
                        (InitParams_p->IntTriggerTable_p[i]));
#else
        trigger_mode = INTERRUPT_TRIGGER_MODE(i);
#endif
                
        if (interrupt_init( i,
                            interrupt_control[i].stack_base,
                            interrupt_control[i].stack_size,
                            trigger_mode,
                            interrupt_control[i].flags) )
        {
            return STBOOT_ERROR_INTERRUPT_INIT;
        }

#ifndef STAPI_INTERRUPT_BY_NUMBER /*for GNBvd44968 & GNBvd45179*/
#if defined(ST_5514) || defined(ST_5516) || defined(ST_5517) || defined(ST_5528) || defined(ST_5100) || defined(ST_5101) || defined(ST_7710) || defined(ST_5105) || defined(ST_5700) || defined(ST_5188) || defined(ST_5107)
        /* Devices with ILC-3 have each interrupt level
           disabled for backwards comptibility */
        if (interrupt_disable (i))
        {
            return STBOOT_ERROR_INTERRUPT_INIT;
        }
#endif
#endif
    }

    /* From DCU 1.8.1 (STLite/OS20 2.07) onwards the method for
       enable/disable of global interrupts changed */
#if (OS20_VERSION_MAJOR > 2) || ((OS20_VERSION_MAJOR == 2) && (OS20_VERSION_MINOR >= 7))

    interrupt_enable_global();                 /* void return */
#else
    if( interrupt_enable(INTERRUPT_GLOBAL_ENABLE) != 0 )
    {
        return STBOOT_ERROR_INTERRUPT_ENABLE;
    }
#endif

#ifndef STAPI_INTERRUPT_BY_NUMBER  /*for GNBvd44968 & GNBvd45179*/
#if defined(ST_5514) || defined(ST_5516) || defined(ST_5517) || defined(ST_5528) || defined(ST_5100) || defined(ST_5101) || defined(ST_7710) || defined(ST_5105) || defined(ST_5700) || defined(ST_5188) || defined(ST_5107)
    /* Devices with ILC-3 have each interrupt number enabled
       for backwards compatibility with earlier ILCs */
    for (i=0; i<INTERRUPT_NUMBERS; i++)
    {
        if (interrupt_enable_number(i) != 0)
        {
            return STBOOT_ERROR_INTERRUPT_ENABLE;
        }
    }
#endif
#endif

    return ST_NO_ERROR;
}

#endif /*#ifdef ARCHITECTURE_ST20*/

/* End of stboot.c */

⌨️ 快捷键说明

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