硬汉嵌入式论坛

 找回密码
 立即注册
查看: 2149|回复: 0
收起左侧

[CMSIS-RTOS] ChaN老师FatFS源码的多任务底层接口函数中都增加了CMSIS-RTOS支持,顺应潮流

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106997
QQ
发表于 2017-10-16 00:45:34 | 显示全部楼层 |阅读模式
看的是0.13a:http://www.armbbs.cn/forum.php?mod=viewthread&tid=45206
  1. /*------------------------------------------------------------------------*/
  2. /* Sample Code of OS Dependent Functions for FatFs                        */
  3. /* (C)ChaN, 2017                                                          */
  4. /*------------------------------------------------------------------------*/
  5. #include "ff.h"
  6. #if FF_USE_LFN == 3    /* Dynamic memory allocation */
  7. /*------------------------------------------------------------------------*/
  8. /* Allocate a memory block                                                */
  9. /*------------------------------------------------------------------------*/
  10. void* ff_memalloc (    /* Returns pointer to the allocated memory block (null on not enough core) */
  11.     UINT msize        /* Number of bytes to allocate */
  12. )
  13. {
  14.     return malloc(msize);    /* Allocate a new memory block with POSIX API */
  15. }
  16. /*------------------------------------------------------------------------*/
  17. /* Free a memory block                                                    */
  18. /*------------------------------------------------------------------------*/
  19. void ff_memfree (
  20.     void* mblock    /* Pointer to the memory block to free (nothing to do for null) */
  21. )
  22. {
  23.     free(mblock);    /* Free the memory block with POSIX API */
  24. }
  25. #endif
  26. #if FF_FS_REENTRANT    /* Mutal exclusion */
  27. /*------------------------------------------------------------------------*/
  28. /* Create a Synchronization Object                                        */
  29. /*------------------------------------------------------------------------*/
  30. /* This function is called in f_mount() function to create a new
  31. /  synchronization object for the volume, such as semaphore and mutex.
  32. /  When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
  33. */
  34. //const osMutexDef_t Mutex[FF_VOLUMES];    /* CMSIS-RTOS */
  35. int ff_cre_syncobj (    /* 1:Function succeeded, 0:Could not create the sync object */
  36.     BYTE vol,            /* Corresponding volume (logical drive number) */
  37.     FF_SYNC_t *sobj        /* Pointer to return the created sync object */
  38. )
  39. {
  40.     /* Win32 */
  41.     *sobj = CreateMutex(NULL, FALSE, NULL);
  42.     return (int)(*sobj != INVALID_HANDLE_VALUE);
  43.     /* uITRON */
  44. //    T_CSEM csem = {TA_TPRI,1,1};
  45. //    *sobj = acre_sem(&csem);
  46. //    return (int)(*sobj > 0);
  47.     /* uC/OS-II */
  48. //    OS_ERR err;
  49. //    *sobj = OSMutexCreate(0, &err);
  50. //    return (int)(err == OS_NO_ERR);
  51.     /* FreeRTOS */
  52. //    *sobj = xSemaphoreCreateMutex();
  53. //    return (int)(*sobj != NULL);
  54.     /* CMSIS-RTOS */
  55. //    *sobj = osMutexCreate(Mutex + vol);
  56. //    return (int)(*sobj != NULL);
  57. }
  58. /*------------------------------------------------------------------------*/
  59. /* Delete a Synchronization Object                                        */
  60. /*------------------------------------------------------------------------*/
  61. /* This function is called in f_mount() function to delete a synchronization
  62. /  object that created with ff_cre_syncobj() function. When a 0 is returned,
  63. /  the f_mount() function fails with FR_INT_ERR.
  64. */
  65. int ff_del_syncobj (    /* 1:Function succeeded, 0:Could not delete due to an error */
  66.     FF_SYNC_t sobj        /* Sync object tied to the logical drive to be deleted */
  67. )
  68. {
  69.     /* Win32 */
  70.     return (int)CloseHandle(sobj);
  71.     /* uITRON */
  72. //    return (int)(del_sem(sobj) == E_OK);
  73.     /* uC/OS-II */
  74. //    OS_ERR err;
  75. //    OSMutexDel(sobj, OS_DEL_ALWAYS, &err);
  76. //    return (int)(err == OS_NO_ERR);
  77.     /* FreeRTOS */
  78. //  vSemaphoreDelete(sobj);
  79. //    return 1;
  80.     /* CMSIS-RTOS */
  81. //    return (int)(osMutexDelete(sobj) == osOK);
  82. }
  83. /*------------------------------------------------------------------------*/
  84. /* Request Grant to Access the Volume                                     */
  85. /*------------------------------------------------------------------------*/
  86. /* This function is called on entering file functions to lock the volume.
  87. /  When a 0 is returned, the file function fails with FR_TIMEOUT.
  88. */
  89. int ff_req_grant (    /* 1:Got a grant to access the volume, 0:Could not get a grant */
  90.     FF_SYNC_t sobj    /* Sync object to wait */
  91. )
  92. {
  93.     /* Win32 */
  94.     return (int)(WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0);
  95.     /* uITRON */
  96. //    return (int)(wai_sem(sobj) == E_OK);
  97.     /* uC/OS-II */
  98. //    OS_ERR err;
  99. //    OSMutexPend(sobj, FF_FS_TIMEOUT, &err));
  100. //    return (int)(err == OS_NO_ERR);
  101.     /* FreeRTOS */
  102. //    return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);
  103.     /* CMSIS-RTOS */
  104. //    return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);
  105. }
  106. /*------------------------------------------------------------------------*/
  107. /* Release Grant to Access the Volume                                     */
  108. /*------------------------------------------------------------------------*/
  109. /* This function is called on leaving file functions to unlock the volume.
  110. */
  111. void ff_rel_grant (
  112.     FF_SYNC_t sobj    /* Sync object to be signaled */
  113. )
  114. {
  115.     /* Win32 */
  116.     ReleaseMutex(sobj);
  117.     /* uITRON */
  118. //    sig_sem(sobj);
  119.     /* uC/OS-II */
  120. //    OSMutexPost(sobj);
  121.     /* FreeRTOS */
  122. //    xSemaphoreGive(sobj);
  123.     /* CMSIS-RTOS */
  124. //    osMutexRelease(sobj);
  125. }
  126. #endif
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-14 02:55 , Processed in 0.137302 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表