syscall.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. int ret;
  34. //osSemaphoreDef(SEM);
  35. //*sobj = osSemaphoreCreate(osSemaphore(SEM), 1);
  36. *sobj = furi_mutex_alloc(FuriMutexTypeNormal);
  37. ret = (*sobj != NULL);
  38. return ret;
  39. }
  40. /*------------------------------------------------------------------------*/
  41. /* Delete a Synchronization Object */
  42. /*------------------------------------------------------------------------*/
  43. /* This function is called in f_mount() function to delete a synchronization
  44. / object that created with ff_cre_syncobj() function. When a 0 is returned,
  45. / the f_mount() function fails with FR_INT_ERR.
  46. */
  47. int ff_del_syncobj(/* 1:Function succeeded, 0:Could not delete due to any error */
  48. _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
  49. ) {
  50. furi_mutex_free(sobj);
  51. return 1;
  52. }
  53. /*------------------------------------------------------------------------*/
  54. /* Request Grant to Access the Volume */
  55. /*------------------------------------------------------------------------*/
  56. /* This function is called on entering file functions to lock the volume.
  57. / When a 0 is returned, the file function fails with FR_TIMEOUT.
  58. */
  59. int ff_req_grant(/* 1:Got a grant to access the volume, 0:Could not get a grant */
  60. _SYNC_t sobj /* Sync object to wait */
  61. ) {
  62. int ret = 0;
  63. if(furi_mutex_acquire(sobj, _FS_TIMEOUT) == FuriStatusOk) {
  64. ret = 1;
  65. }
  66. return ret;
  67. }
  68. /*------------------------------------------------------------------------*/
  69. /* Release Grant to Access the Volume */
  70. /*------------------------------------------------------------------------*/
  71. /* This function is called on leaving file functions to unlock the volume.
  72. */
  73. void ff_rel_grant(_SYNC_t sobj /* Sync object to be signaled */
  74. ) {
  75. furi_mutex_release(sobj);
  76. }
  77. #endif
  78. #if _USE_LFN == 3 /* LFN with a working buffer on the heap */
  79. /*------------------------------------------------------------------------*/
  80. /* Allocate a memory block */
  81. /*------------------------------------------------------------------------*/
  82. /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.
  83. */
  84. void* ff_memalloc(/* Returns pointer to the allocated memory block */
  85. UINT msize /* Number of bytes to allocate */
  86. ) {
  87. return ff_malloc(msize); /* Allocate a new memory block with POSIX API */
  88. }
  89. /*------------------------------------------------------------------------*/
  90. /* Free a memory block */
  91. /*------------------------------------------------------------------------*/
  92. void ff_memfree(void* mblock /* Pointer to the memory block to free */
  93. ) {
  94. ff_free(mblock); /* Discard the memory block with POSIX API */
  95. }
  96. #endif