fatfs_syscall.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /*------------------------------------------------------------------------*/
  14. /* Sample code of OS dependent controls for FatFs */
  15. /* (C)ChaN, 2014 */
  16. /*------------------------------------------------------------------------*/
  17. #include "hal.h"
  18. #include "ff.h"
  19. #include "stdlib.h"
  20. #if FF_FS_REENTRANT
  21. /*------------------------------------------------------------------------*/
  22. /* Static array of Synchronization Objects */
  23. /*------------------------------------------------------------------------*/
  24. static semaphore_t ff_sem[FF_VOLUMES];
  25. /*------------------------------------------------------------------------*/
  26. /* Create a Synchronization Object */
  27. /*------------------------------------------------------------------------*/
  28. int ff_cre_syncobj(BYTE vol, FF_SYNC_t *sobj) {
  29. *sobj = &ff_sem[vol];
  30. chSemObjectInit(*sobj, 1);
  31. return TRUE;
  32. }
  33. /*------------------------------------------------------------------------*/
  34. /* Delete a Synchronization Object */
  35. /*------------------------------------------------------------------------*/
  36. int ff_del_syncobj(FF_SYNC_t sobj) {
  37. chSemReset(sobj, 0);
  38. return TRUE;
  39. }
  40. /*------------------------------------------------------------------------*/
  41. /* Request Grant to Access the Volume */
  42. /*------------------------------------------------------------------------*/
  43. int ff_req_grant(FF_SYNC_t sobj) {
  44. msg_t msg = chSemWaitTimeout(sobj, (systime_t)FF_FS_TIMEOUT);
  45. return msg == MSG_OK;
  46. }
  47. /*------------------------------------------------------------------------*/
  48. /* Release Grant to Access the Volume */
  49. /*------------------------------------------------------------------------*/
  50. void ff_rel_grant(FF_SYNC_t sobj) {
  51. chSemSignal(sobj);
  52. }
  53. #endif /* FF_FS_REENTRANT */
  54. #if FF_USE_LFN == 3 /* LFN with a working buffer on the heap */
  55. /*------------------------------------------------------------------------*/
  56. /* Allocate a memory block */
  57. /*------------------------------------------------------------------------*/
  58. void *ff_memalloc(UINT size) {
  59. return malloc(size);
  60. }
  61. /*------------------------------------------------------------------------*/
  62. /* Free a memory block */
  63. /*------------------------------------------------------------------------*/
  64. void ff_memfree(void *mblock) {
  65. free(mblock);
  66. }
  67. #endif /* FF_USE_LFN == 3 */