syscall.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*------------------------------------------------------------------------*/
  2. /* Sample code of OS dependent controls for FatFs */
  3. /* (C)ChaN, 2014 */
  4. /* Portions COPYRIGHT 2017 STMicroelectronics */
  5. /* Portions Copyright (C) 2014, ChaN, all right reserved */
  6. /*------------------------------------------------------------------------*/
  7. /**
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * Copyright (c) 2017 STMicroelectronics. All rights reserved.
  12. *
  13. * This software component is licensed by ST under BSD 3-Clause license,
  14. * the "License"; You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. ******************************************************************************
  19. **/
  20. #include "fatfs/ff.h"
  21. #if _FS_REENTRANT
  22. /*------------------------------------------------------------------------*/
  23. /* Create a Synchronization Object */
  24. /*------------------------------------------------------------------------*/
  25. /* This function is called in f_mount() function to create a new
  26. / synchronization object, such as semaphore and mutex. When a 0 is returned,
  27. / the f_mount() function fails with FR_INT_ERR.
  28. */
  29. int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
  30. BYTE vol, /* Corresponding volume (logical drive number) */
  31. _SYNC_t *sobj /* Pointer to return the created sync object */
  32. )
  33. {
  34. int ret;
  35. //osSemaphoreDef(SEM);
  36. //*sobj = osSemaphoreCreate(osSemaphore(SEM), 1);
  37. *sobj = osMutexNew(NULL);
  38. ret = (*sobj != NULL);
  39. return ret;
  40. }
  41. /*------------------------------------------------------------------------*/
  42. /* Delete a Synchronization Object */
  43. /*------------------------------------------------------------------------*/
  44. /* This function is called in f_mount() function to delete a synchronization
  45. / object that created with ff_cre_syncobj() function. When a 0 is returned,
  46. / the f_mount() function fails with FR_INT_ERR.
  47. */
  48. int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any error */
  49. _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
  50. )
  51. {
  52. osMutexDelete(sobj);
  53. return 1;
  54. }
  55. /*------------------------------------------------------------------------*/
  56. /* Request Grant to Access the Volume */
  57. /*------------------------------------------------------------------------*/
  58. /* This function is called on entering file functions to lock the volume.
  59. / When a 0 is returned, the file function fails with FR_TIMEOUT.
  60. */
  61. int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
  62. _SYNC_t sobj /* Sync object to wait */
  63. )
  64. {
  65. int ret = 0;
  66. if(osMutexAcquire(sobj, _FS_TIMEOUT) == osOK) {
  67. ret = 1;
  68. }
  69. return ret;
  70. }
  71. /*------------------------------------------------------------------------*/
  72. /* Release Grant to Access the Volume */
  73. /*------------------------------------------------------------------------*/
  74. /* This function is called on leaving file functions to unlock the volume.
  75. */
  76. void ff_rel_grant (
  77. _SYNC_t sobj /* Sync object to be signaled */
  78. )
  79. {
  80. osMutexRelease(sobj);
  81. }
  82. #endif
  83. #if _USE_LFN == 3 /* LFN with a working buffer on the heap */
  84. /*------------------------------------------------------------------------*/
  85. /* Allocate a memory block */
  86. /*------------------------------------------------------------------------*/
  87. /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.
  88. */
  89. void* ff_memalloc ( /* Returns pointer to the allocated memory block */
  90. UINT msize /* Number of bytes to allocate */
  91. )
  92. {
  93. return ff_malloc(msize); /* Allocate a new memory block with POSIX API */
  94. }
  95. /*------------------------------------------------------------------------*/
  96. /* Free a memory block */
  97. /*------------------------------------------------------------------------*/
  98. void ff_memfree (
  99. void* mblock /* Pointer to the memory block to free */
  100. )
  101. {
  102. ff_free(mblock); /* Discard the memory block with POSIX API */
  103. }
  104. #endif