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

📄 pc_locks.c

📁 基于nucleus操作系统的GPRS无线数据传输终端全套源文件。包括支持ARM7的BSP,操作系统
💻 C
📖 第 1 页 / 共 4 页
字号:
*       task should run until it is unlocked or it yields.              
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi
*                                                                       
* INPUTS                                                                
*                                                                       
*       None.                                                           
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       A BOOLEAN that will be passed to FS_UNLOCK_TASK when RTFS       
*       releases. If the  kernel function supports pushing/pooping of   
*       the lock state this INT is irrelevent. Otherwise use it to      
*       decide what action if any to take in FS_UNLOCK_TASK             
*                                                                       
*************************************************************************/
INT fs_lock_task(VOID)
{
    /* This sample code asks if the task is already locked. If not it 
       locks the task. It then returns YES if the task was already locked.
       This flag will be passed to fs_unlock_task() later. fs_unlock_task()
       will then restore the task state. 
     
       Note: If your kernel has a nested lock/unlock call you may just use it. In
             this case you may simply return a constant value an ignore it.
    */
OPTION      preempt_status;


    preempt_status = NU_Change_Preemption(NU_NO_PREEMPT);
    return((INT) preempt_status);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       fs_unlock_task                                                  
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       This is called by RTFS preemption is safe again. The kernel     
*       should restore the lock state to what it was before FS_LOCK_TASK
*       was called.                                                     
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi
*                                                                       
* INPUTS                                                                
*                                                                       
*       state_var                           Not used                    
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID fs_unlock_task(INT state_var)
{

    /* This sample code complents the code in pc_lock_task()
        
       Note: If your kernel has a nested lock/unlock call you may just use it. In
             this case you may simply return a constant value an ignore it.
      */
    state_var = state_var;
    NU_Change_Preemption((OPTION)state_var);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       fs_release                                                      
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       This is called by RTFS before it blocks on a resource. The      
*       resource may be either an IO event in a device driver, or a     
*       locked data object such as the fat or a directory that is open  
*       for write. It releases the RTFS semaphore.                      
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi
*                                                                       
* INPUTS                                                                
*                                                                       
*       None.                                                           
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID fs_release(VOID)
{

    /* Note in a single threaded OS kernel this is not needed */
    /* Note: If you can you should try not to cause a context switch here.
             The routine calling fs_release() is going to yield momentarilly.
             If you do cause a switch here no harm is done, however. */

    NU_Release_Semaphore(&NUF_FILE_SYSTEM_MUTEX);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       fs_reclaim                                                      
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       This is called by RTFS after it  returns from a resource block. 
*       It reclaims RTFS resources that were released in ps_release     
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi
*                                                                       
* INPUTS                                                                
*                                                                       
*       None.                                                           
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       None.                                                           
*                                                                       
*************************************************************************/
VOID fs_reclaim(VOID)
{

    /* Note in a single threaded OS kernel this is not needed */
    NU_Obtain_Semaphore(&NUF_FILE_SYSTEM_MUTEX, NU_SUSPEND);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_alloc_lock                                                   
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       This routine is called repeatedly by pc_memory_init() to        
*       allocate all of the event handles needed by RTFS.               
*                                                                       
*       It returns an event handle. This handle will be used to block   
*       and wake as resources are needed/finished.                      
*                                                                       
*       The handle type returned may be one of two types.               
*        1. A mutex semaphore for which only one task awakes from       
*           pc_wait_lock() when signaled from pc_wake_lock(). If this   
*           method is used there will be a slight performance           
*           degradation in some cases since all resource accesses will  
*           be exclusive.                                               
*        2. An event handle for which all tasks awake from pc_wait_lock()
*           when signaled from pc_wake_lock(). If this method is used   
*           RTFS will arbitrate for the resource after wait has returned.
*           This is the preferred method because it allows RTFS to      
*           differentiate between exclusive and shared access to a      
*           resource.                                                   
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi
*                                                                       
* INPUTS                                                                
*                                                                       
*       None.                                                           
*                                                                       
* OUTPUTS                                                               
*                                                                       
*       A handle of type WAIT_HANDLE_TYPE. This is defined by you in    
*       pcdisk.h and is the native handle type of your kernel           
*       environment.                                                    
*                                                                       
*************************************************************************/
WAIT_HANDLE_TYPE pc_alloc_lock(VOID)                            /*__fn__*/
{
WAIT_HANDLE_TYPE h;
static WAIT_HANDLE_TYPE current_h = 0;


    if (current_h < NUF_FIRST_EVENT_NUMBER)
        current_h = NUF_FIRST_EVENT_NUMBER;
    h = current_h;
    current_h += 1;
    return(h);
}


/************************************************************************
* FUNCTION                                                              
*                                                                       
*       pc_wait_lock                                                    
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*       The file system code needs to block on handle. Wait for a wakeup
*       on the channel.                                                 
*                                                                       
* AUTHOR                                                                
*                                                                       
*       Takahiro Takahashi
*                                                                       
* INPUTS                                                                
*                                                                       
*       wait_handle                         Event group number          

⌨️ 快捷键说明

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