原创 FreeRTOS上移植uC/FS (原创)

2008-9-2 22:19 7211 8 8 分类: MCU/ 嵌入式

由于uCOS-II提供的功能,FreeRTOS一般都有,所以可以很方便地把uC/FS移植以freertos的平台上,


我们直接告诉uc/fs,我们用的平台为ucos-ii就好了,


然后更改一下"Fs_x_ucos_ii.c"文件,更改后如下:


static  xSemaphoreHandle  FS_SemFileHandle;
static  xSemaphoreHandle  FS_SemFileOps;
static  xSemaphoreHandle  FS_SemMemManager;
static  xSemaphoreHandle  FS_SemDeviceOps;


#if    FS_POSIX_DIR_SUPPORT
static xSemaphoreHandle   FS_SemDirHandle;
static xSemaphoreHandle   FS_SemDirOps;
#endif


void  FS_X_OS_LockFileHandle (void)
{
    xQueueTakeMutexRecursive(FS_SemFileHandle,(portTickType)10);
}
void  FS_X_OS_UnlockFileHandle (void)
{
    xQueueGiveMutexRecursive(FS_SemFileHandle);
}
void  FS_X_OS_LockFileOp (FS_FILE *pFile)
{
    xQueueTakeMutexRecursive(FS_SemFileOps,(portTickType)10);
}


void  FS_X_OS_UnlockFileOp (FS_FILE *pFile)
{
    xQueueGiveMutexRecursive(FS_SemFileOps);
}


void  FS_X_OS_LockMem (void)
{
    xQueueTakeMutexRecursive(FS_SemMemManager,(portTickType)10);
}


void  FS_X_OS_UnlockMem (void)
{
    xQueueGiveMutexRecursive(FS_SemMemManager);
}


void  FS_X_OS_LockDeviceOp (const FS_DEVICE * pDevice)
{
    xQueueTakeMutexRecursive(FS_SemDeviceOps,(portTickType)10);
}


void  FS_X_OS_UnlockDeviceOp (const FS_DEVICE *pDevice)
{
    xQueueGiveMutexRecursive(FS_SemDeviceOps);
}


#if  FS_POSIX_DIR_SUPPORT
void FS_X_OS_LockDirHandle (void)
{
    xQueueTakeMutexRecursive(FS_SemDirHandle,(portTickType)10);
}
#endif


#if  FS_POSIX_DIR_SUPPORT
void FS_X_OS_UnlockDirHandle (void)
{
    xQueueGiveMutexRecursive(FS_SemDirHandle);
}
#endif


#if  FS_POSIX_DIR_SUPPORT
void FS_X_OS_LockDirOp (FS_DIR *pDir)
{
    xQueueTakeMutexRecursive(FS_SemDirOps,(portTickType)10);
}
#endif


#if  FS_POSIX_DIR_SUPPORT
void FS_X_OS_UnlockDirOp (FS_DIR *pDir)
{
    xQueueGiveMutexRecursive(FS_SemDirOps);
}
#endif


FS_U16  FS_X_OS_GetDate (void)
{
  FS_U16 r;
  FS_U16 Day, Month, Year;


  Day   = FS_X_GET_DAY();
  Month = FS_X_GET_MONTH();
  Year  = FS_X_GET_YEAR();


  r  = Day + (Month << 5) + (Year  << 9);
  return r;
}


FS_U16  FS_X_OS_GetTime (void)
{
  FS_U16 r;
  FS_U16 Sec, Min, Hour;


  Sec   = FS_X_GET_SECOND();
  Min   = FS_X_GET_MINUTE();
  Hour  = FS_X_GET_HOUR();


  r  = Sec / 2 + (Min << 5) + (Hour  << 11);
  return r;
}


int  FS_X_OS_Init (void)
{
    FS_SemFileHandle = xSemaphoreCreateMutex();
    FS_SemFileOps    = xSemaphoreCreateMutex();
    FS_SemMemManager = xSemaphoreCreateMutex();
    FS_SemDeviceOps  = xSemaphoreCreateMutex();


#if FS_POSIX_DIR_SUPPORT   
    FS_SemDirHandle  = xSemaphoreCreateMutex();
    FS_SemDirOps     = xSemaphoreCreateMutex();
#endif


    return (0);
}


int  FS_X_OS_Exit (void)
{
    vQueueDelete(FS_SemFileHandle);
    vQueueDelete(FS_SemFileOps);
    vQueueDelete(FS_SemMemManager);
    vQueueDelete(FS_SemDeviceOps);
   
#if FS_POSIX_DIR_SUPPORT   
    vQueueDelete(FS_SemDirHandle);
    vQueueDelete(FS_SemDirOps);
#endif
    return (0);
}


不过别忘更改头文件包含噢,  呵呵,


更改完了就编译吧,

文章评论0条评论)

登录后参与讨论
我要评论
0
8
关闭 站长推荐上一条 /2 下一条