📄 fs87synchinterf.c
字号:
#ifdef FSS_FTR/***************************************************************************** ........................................................................ COPYRIGHT (c) Philips Semiconductors Nuremberg 2003 .. All rights are reserved. Reproduction in whole or in part is .. prohibited without the written consent of the copyright owner. . ......................................................................... File name : Fs87SynchInterf.c.. Project : SSYOL3 WAP/MMS.. Module : OSFS.. %version: MMS.1.0.1.1 %.. Compiler name and release:...............:........:..........:............:...............................* *----------------------------------------------------------------------------* * DESCRIPTION * SYNCHRONOUS POSIX API FOR FSS * *----------------------------------------------------------------------------* *----------------------------------------------------------------------------* * FUNCTIONS DEFINED IN THIS FILE *----------------------------------------------------------------------------* * Name | Object *---------------------------------------------------------------------------- * Fs87_01FopenSized | Fopen synchronous interface * with size * Fs87_02Fclose | Fclose synchronous interface * Fs87_03Remove | Remove synchronous interface * Fs87_04Rename | Rename synchronous interface * Fs87_05Setvbuf | Setvbuf synchronous interface * Fs87_06Ftell | Ftell synchronous interface * Fs87_07Fseek | Fseek synchronous interface * Fs87_08Rewind | Rewind synchronous interface * Fs87_09Stat | Stat synchronous interface * Fs87_10Fflush | Fflush synchronous interface * Fs87_11Feof | Feof synchronous interface * Fs87_12Fwrite | Fwrite synchronous interface * Fs87_13Fread | Fread synchronous interface * Fs87_14Mkdir | Mkdir synchronous interface * Fs87_15Rmdir | Rmdir synchronous interface * Fs87_16Chdir | Chdir synchronous interface * Fs87_17Getcwd | Getcwd synchronous interface * Fs87_18Opendir | Opendir synchronous interface * Fs87_19Closedir | Closedir synchronous * interface * Fs87_20Readdir | Readdir synchronous interface * Fs87_21Rewinddir | Rewinddir synchronous * interface * Fs87_22SetSize | Set the size of a file * Fs87_23Fopen | Fopen synchronous interface * Fs87_24GetVolInfo | GetVolInfo synchronous * interface * Fs87_25FormatVol | FormatVol synchronous * interface * * Fs87_30DetermineSem | Determines the semaphore for * calling process * Fs87_31SetErrorCode | Sets the error code for calling process * Fs87_32SetErrorNumber | Returns the error no. * Fs87_33StoreProcessNumber | Store the process id * Fs87_120FwriteNoDelay | Returns an error if erase is * | ongoing * Fs87_130FreadNoDelay | Returns an error if erase is * | ongoing *----------------------------------------------------------------------------* * EVOLUTION *----------------------------------------------------------------------------* * Date | Author | Description *----------------------------------------------------------------------------* * 17.12.02 | L. KEANE | Creation * 20.01.03 | tcmc_sgp | implementation * 31.03.03 | tcmc_sgp | addition of exception handle and commments * 02.05.03 | tcmc_sgp | New msg interface is added for Teleca application *----------------------------------------------------------------------------* *****************************************************************************/#ifdef SYNCHRONOUS_FILE_SYSTEM_FTR#define ACCESS_RIGHTS_INTERNAL_FS#define FS87SYNCHINTERF_C#define MODULE_NUMBER MODULE_OSFS#undef FILE_NUMBER#define FILE_NUMBER 87/*inc - INCLUDE---------------*/#include "Fs.h"/*lc - LOCAL CONSTANTS DECLARATION-----------------------------------*//*lm - LOCAL MACROS DEFINITION------------------------------*/#define MC_FSS_FLASH_SEM_CONSUME(pp_SemId) MC_RTK_SEM_CONSUME( pp_SemId ) #define MC_FSS_FLASH_SEM_PRODUCE(pp_SemId) MC_RTK_SEM_PRODUCE( pp_SemId ) /*ld - LOCAL LITERAL DEFINITION--------------------------------*//*ls - LOCAL STRUCTURE DEFINITION----------------------------------*//*lp - LOCAL PROCEDURES DECLARATION------------------------------------*//*lv - LOCAL VARIABLES DEFINITION---------------------------------*//*S(*************************************************************************** * Semantic name : Fs87_01FopenSized() * Object : Fopen Synchronous POSIX API with size * Finite state machine : * Event : * Transition : *----------------------------------------------------------------------------* * * Input parameters : * ------------------- * pp_FileName * pp_Mode - opening mode for the file * vp_MaxFileSize * * Output parameters : * ------------------- * Return * * * Used variables : * ------------------- * GLOBAL: * * * Used procedures : * ------------------- * -MC_FS_MA_SEND_CMD_MSG_TO_FS *----------------------------------------------------------------------------* *----------------------------------------------------------------------------* * DESCRIPTION * * Synchronous function interface to FSS * -Sends REQ message to FS * -Returns file handle or NULL * *----------------------------------------------------------------------------* **************************************************************************)S*/#undef PROCEDURE_NUMBER#define PROCEDURE_NUMBER 1t_fssFILE* Fs87_01FopenSized(const char *pp_FileName, const char *pp_Mode, t_fss_size_t vp_MaxFileSize){ u8 vl_SemName; s32 vl_ErrCode; t_fssFILE *pl_return; /* Reserve message space */ t_FsCmdFOpen *pl_Fopen = (t_FsCmdFOpen*) MC_FS_GET_MEMORY( sizeof(t_FsCmdFOpen) ); /* tcmc_BRC: consume semaphore to provide exclusive access to the file system. */ MC_FSS_FLASH_SEM_CONSUME(FSS_SEM2); /* Determine the calling process in order to determine what semaphore to consume */ vl_SemName = Fs87_30DetermineSem(); if (vl_SemName == NIL) { MC_FS_STATUS(pl_Fopen) = FS_EINVAL; } else { MC_FS_STATUS(pl_Fopen) = FS_OK; } /* Send message to PROCESS_FSS, if Semaphore is available for calling application process */ if ( MC_FS_STATUS( pl_Fopen ) == FS_OK ) { /* Fill message with input parameters */ pl_Fopen->p_FileName = pp_FileName; pl_Fopen->p_Mode = pp_Mode; pl_Fopen->v_MaxFileSize = vp_MaxFileSize; /* Send message */ /* Synchronous interface do not expect an answer message (but 'produce semaphore') */ MC_FS_MA_SEND_CMD_MSG_TO_FS( FS_NO_ACK, (void*)pl_Fopen, FS_CMD_FOPEN_REQ ); /* Consume Semaphore: now the calling application process is blocked */ /* Till MC_RTK_SEM_PRODUCE(vl_Semaphore) is called: in FSS scheduler */ /* During that time *pl_FopenSized is filled by FSS and lower layer */ MC_RTK_SEM_CONSUME( vl_SemName ); } /* Set the updated err/ok code to corresponding process' global variable */ vl_ErrCode = MC_FS_STATUS(pl_Fopen); Fs87_31SetErrorCode( vl_ErrCode ); /* if the operation is not successful, return an error */ if ( MC_FS_STATUS( pl_Fopen ) != FS_OK ) { pl_return = NULL; } else { pl_return = pl_Fopen->p_Stream; } /* Free message space */ MC_FS_FREE_MEMORY( pl_Fopen ); /* tcmc_BRC: produce sem so that other tasks can get access to FSS */ MC_FSS_FLASH_SEM_PRODUCE(FSS_SEM2); return( pl_return );}/*S(*************************************************************************** * Semantic name : Fs87_02Fclose() * Object : Fclose Synchronous POSIX API * Finite state machine : * Event : * Transition : *----------------------------------------------------------------------------* * * Input parameters : * ------------------- * pp_Stream - file handle * * Output parameters : * ------------------- * Return * * * Used variables : * ------------------- * GLOBAL: * * * Used procedures : * ------------------- * -MC_FS_MA_SEND_CMD_MSG_TO_FS *----------------------------------------------------------------------------* *----------------------------------------------------------------------------* * DESCRIPTION * * Synchronous function interface to FSS * -Sends REQ message to FS * -Returns FS_OK or error code * *----------------------------------------------------------------------------* **************************************************************************)S*/#undef PROCEDURE_NUMBER#define PROCEDURE_NUMBER 2s32 Fs87_02Fclose(t_fssFILE *pp_Stream){ s32 vl_return; s32 vl_ErrCode; u8 vl_SemName; /* Reserve message space */ t_FsCmdFClose * pl_FClose = (t_FsCmdFClose*) MC_FS_GET_MEMORY( sizeof(t_FsCmdFClose) ); /* tcmc_BRC */ MC_FSS_FLASH_SEM_CONSUME(FSS_SEM2); /* Determine the calling process in order to determine what semaphore to consume */ vl_SemName= Fs87_30DetermineSem(); if (vl_SemName == NIL) { MC_FS_STATUS(pl_FClose) = FS_EINVAL; } else { MC_FS_STATUS(pl_FClose) = FS_OK; } /* Send message to PROCESS_FSS */ if ( MC_FS_STATUS( pl_FClose ) == FS_OK ) { /* Fill message with input parameters */ pl_FClose->p_Stream = pp_Stream; /* Send message */ MC_FS_MA_SEND_CMD_MSG_TO_FS( FS_NO_ACK, (void*)pl_FClose, FS_CMD_FCLOSE_REQ ); /* Consume Semaphore */ MC_RTK_SEM_CONSUME( vl_SemName ); } /* Set the updated err/ok code to corresponding process' global variable */ vl_ErrCode = MC_FS_STATUS(pl_FClose); Fs87_31SetErrorCode( vl_ErrCode ); /* if the operation is not successful, return an error */ if ( MC_FS_STATUS( pl_FClose ) != FS_OK ) { vl_return = FS_EOF; } else { vl_return = FS_OK; } /* Free message space */ MC_FS_FREE_MEMORY( pl_FClose ); /* tcmc_BRC */ MC_FSS_FLASH_SEM_PRODUCE(FSS_SEM2); return( vl_return );}/*S(*************************************************************************** * Semantic name : Fs87_03Remove() * Object : FRemove Synchronous POSIX API * Finite state machine : * Event : * Transition : *----------------------------------------------------------------------------* * * Input parameters : * ------------------- * pp_FileName * * Output parameters : * ------------------- * Return * * * Used variables : * ------------------- * GLOBAL: * * * Used procedures : * ------------------- * -MC_FS_MA_SEND_CMD_MSG_TO_FS *----------------------------------------------------------------------------* *----------------------------------------------------------------------------* * DESCRIPTION * * Synchronous function interface to FSS * -Sends REQ message to FS * -Returns FS_OK or error code * *----------------------------------------------------------------------------* **************************************************************************)S*/#undef PROCEDURE_NUMBER#define PROCEDURE_NUMBER 3s32 Fs87_03Remove(const fssPath *pp_FileName){ s32 vl_return; s32 vl_ErrCode; u8 vl_SemName; /* Reserve message space */ t_FsCmdRemove * pl_Remove = (t_FsCmdRemove*) MC_FS_GET_MEMORY( sizeof(t_FsCmdRemove) ); /* tcmc_BRC */ MC_FSS_FLASH_SEM_CONSUME(FSS_SEM2); /* Determine the calling process in order to determine what semaphore to consume */ vl_SemName= Fs87_30DetermineSem(); if (vl_SemName == NIL) { MC_FS_STATUS( pl_Remove ) = FS_EINVAL; } else { MC_FS_STATUS( pl_Remove ) = FS_OK; } /* Send message to PROCESS_FSS */ if ( MC_FS_STATUS( pl_Remove ) == FS_OK ) { /* Fill message with input parameters */ pl_Remove->p_FileName = pp_FileName; /* Send message by setting operation and return command identifier */ MC_FS_MA_SEND_CMD_MSG_TO_FS( FS_NO_ACK, (void*)pl_Remove, FS_CMD_REMOVE_REQ ); /* Consume Semaphore */ MC_RTK_SEM_CONSUME( vl_SemName ); } /* Set the updated err/ok code to corresponding process' global variable */ vl_ErrCode = MC_FS_STATUS( pl_Remove ); Fs87_31SetErrorCode( vl_ErrCode ); /* if the operation is not successful, return an error */ if ( MC_FS_STATUS( pl_Remove ) != FS_OK ) { vl_return = FS_ERROR; } else { vl_return = FS_OK; } /* Free message space */ MC_FS_FREE_MEMORY( pl_Remove ); /* tcmc_BRC */ MC_FSS_FLASH_SEM_PRODUCE(FSS_SEM2); return( vl_return );}/*S(*************************************************************************** * Semantic name : Fs87_04rename() * Object : rename Synchronous POSIX API * Finite state machine : * Event : * Transition : *---------------------------------------------------------------------------- * * Input parameters : * ------------------- * pp_OldName - old file name * pp_NewName - new file name * * Output parameters : * ------------------- * Return * * * Used variables : * ------------------- * GLOBAL: * * * Used procedures : * ------------------- * -MC_FS_MA_SEND_CMD_MSG_TO_FS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -