Subdirectory provided by Embedded Artists
Dependencies: DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos mbed-src
Dependents: lpc4088_displaymodule_hello_world_Sept_2018
Fork of DMSupport by
FileSystems/ff_rtos_helpers.cpp@41:ac490f69398f, 2018-10-04 (annotated)
- Committer:
- jmitc91516
- Date:
- Thu Oct 04 08:30:19 2018 +0000
- Revision:
- 41:ac490f69398f
- Parent:
- 2:887c6b45e7fa
To demonstrate a problem with the dm_board_config.h file - the project will not build if it is in its normal place in the root directory, but builds OK if I copy it to the DMSupport subdirectory.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 2:887c6b45e7fa | 1 | /* |
embeddedartists | 2:887c6b45e7fa | 2 | * Copyright 2014 Embedded Artists AB |
embeddedartists | 2:887c6b45e7fa | 3 | * |
embeddedartists | 2:887c6b45e7fa | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 2:887c6b45e7fa | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 2:887c6b45e7fa | 6 | * You may obtain a copy of the License at |
embeddedartists | 2:887c6b45e7fa | 7 | * |
embeddedartists | 2:887c6b45e7fa | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 2:887c6b45e7fa | 9 | * |
embeddedartists | 2:887c6b45e7fa | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 2:887c6b45e7fa | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 2:887c6b45e7fa | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 2:887c6b45e7fa | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 2:887c6b45e7fa | 14 | * limitations under the License. |
embeddedartists | 2:887c6b45e7fa | 15 | */ |
embeddedartists | 2:887c6b45e7fa | 16 | |
embeddedartists | 2:887c6b45e7fa | 17 | /****************************************************************************** |
embeddedartists | 2:887c6b45e7fa | 18 | * Includes |
embeddedartists | 2:887c6b45e7fa | 19 | *****************************************************************************/ |
embeddedartists | 2:887c6b45e7fa | 20 | |
embeddedartists | 2:887c6b45e7fa | 21 | #include "ff.h" |
embeddedartists | 2:887c6b45e7fa | 22 | #include "mbed.h" |
embeddedartists | 2:887c6b45e7fa | 23 | #include "rtos.h" |
embeddedartists | 2:887c6b45e7fa | 24 | |
embeddedartists | 2:887c6b45e7fa | 25 | /****************************************************************************** |
embeddedartists | 2:887c6b45e7fa | 26 | * Defines and typedefs |
embeddedartists | 2:887c6b45e7fa | 27 | *****************************************************************************/ |
embeddedartists | 2:887c6b45e7fa | 28 | |
embeddedartists | 2:887c6b45e7fa | 29 | /****************************************************************************** |
embeddedartists | 2:887c6b45e7fa | 30 | * External global variables |
embeddedartists | 2:887c6b45e7fa | 31 | *****************************************************************************/ |
embeddedartists | 2:887c6b45e7fa | 32 | |
embeddedartists | 2:887c6b45e7fa | 33 | /****************************************************************************** |
embeddedartists | 2:887c6b45e7fa | 34 | * Local variables |
embeddedartists | 2:887c6b45e7fa | 35 | *****************************************************************************/ |
embeddedartists | 2:887c6b45e7fa | 36 | |
embeddedartists | 2:887c6b45e7fa | 37 | /****************************************************************************** |
embeddedartists | 2:887c6b45e7fa | 38 | * Global Functions |
embeddedartists | 2:887c6b45e7fa | 39 | *****************************************************************************/ |
embeddedartists | 2:887c6b45e7fa | 40 | |
embeddedartists | 2:887c6b45e7fa | 41 | #if _FS_REENTRANT |
embeddedartists | 2:887c6b45e7fa | 42 | /*------------------------------------------------------------------------*/ |
embeddedartists | 2:887c6b45e7fa | 43 | /* Create a Synchronization Object */ |
embeddedartists | 2:887c6b45e7fa | 44 | /*------------------------------------------------------------------------*/ |
embeddedartists | 2:887c6b45e7fa | 45 | /* This function is called in f_mount function to create a new |
embeddedartists | 2:887c6b45e7fa | 46 | / synchronization object, such as semaphore and mutex. When a zero is |
embeddedartists | 2:887c6b45e7fa | 47 | / returned, the f_mount function fails with FR_INT_ERR. |
embeddedartists | 2:887c6b45e7fa | 48 | */ |
embeddedartists | 2:887c6b45e7fa | 49 | |
embeddedartists | 2:887c6b45e7fa | 50 | int ff_cre_syncobj ( /* TRUE:Function succeeded, FALSE:Could not create due to any error */ |
embeddedartists | 2:887c6b45e7fa | 51 | BYTE vol, /* Corresponding logical drive being processed */ |
embeddedartists | 2:887c6b45e7fa | 52 | _SYNC_t *sobj /* Pointer to return the created sync object */ |
embeddedartists | 2:887c6b45e7fa | 53 | ) |
embeddedartists | 2:887c6b45e7fa | 54 | { |
embeddedartists | 2:887c6b45e7fa | 55 | int ret; |
embeddedartists | 2:887c6b45e7fa | 56 | |
embeddedartists | 2:887c6b45e7fa | 57 | // *sobj = CreateMutex(NULL, FALSE, NULL); /* Win32 */ |
embeddedartists | 2:887c6b45e7fa | 58 | // ret = (*sobj != INVALID_HANDLE_VALUE); |
embeddedartists | 2:887c6b45e7fa | 59 | |
embeddedartists | 2:887c6b45e7fa | 60 | // *sobj = SyncObjects[vol]; /* uITRON (give a static sync object) */ |
embeddedartists | 2:887c6b45e7fa | 61 | // ret = 1; /* The initial value of the semaphore must be 1. */ |
embeddedartists | 2:887c6b45e7fa | 62 | |
embeddedartists | 2:887c6b45e7fa | 63 | // *sobj = OSMutexCreate(0, &err); /* uC/OS-II */ |
embeddedartists | 2:887c6b45e7fa | 64 | // ret = (err == OS_NO_ERR); |
embeddedartists | 2:887c6b45e7fa | 65 | |
embeddedartists | 2:887c6b45e7fa | 66 | // *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */ |
embeddedartists | 2:887c6b45e7fa | 67 | // ret = (*sobj != NULL); |
embeddedartists | 2:887c6b45e7fa | 68 | |
embeddedartists | 2:887c6b45e7fa | 69 | *sobj = new Mutex(); /* MBED RTOS */ |
embeddedartists | 2:887c6b45e7fa | 70 | // *sobj = new Semaphore(1); /* MBED RTOS */ |
embeddedartists | 2:887c6b45e7fa | 71 | ret = (*sobj != NULL); |
embeddedartists | 2:887c6b45e7fa | 72 | |
embeddedartists | 2:887c6b45e7fa | 73 | return ret; |
embeddedartists | 2:887c6b45e7fa | 74 | } |
embeddedartists | 2:887c6b45e7fa | 75 | |
embeddedartists | 2:887c6b45e7fa | 76 | |
embeddedartists | 2:887c6b45e7fa | 77 | |
embeddedartists | 2:887c6b45e7fa | 78 | /*------------------------------------------------------------------------*/ |
embeddedartists | 2:887c6b45e7fa | 79 | /* Delete a Synchronization Object */ |
embeddedartists | 2:887c6b45e7fa | 80 | /*------------------------------------------------------------------------*/ |
embeddedartists | 2:887c6b45e7fa | 81 | /* This function is called in f_mount function to delete a synchronization |
embeddedartists | 2:887c6b45e7fa | 82 | / object that created with ff_cre_syncobj function. When a zero is |
embeddedartists | 2:887c6b45e7fa | 83 | / returned, the f_mount function fails with FR_INT_ERR. |
embeddedartists | 2:887c6b45e7fa | 84 | */ |
embeddedartists | 2:887c6b45e7fa | 85 | |
embeddedartists | 2:887c6b45e7fa | 86 | int ff_del_syncobj ( /* TRUE:Function succeeded, FALSE:Could not delete due to any error */ |
embeddedartists | 2:887c6b45e7fa | 87 | _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */ |
embeddedartists | 2:887c6b45e7fa | 88 | ) |
embeddedartists | 2:887c6b45e7fa | 89 | { |
embeddedartists | 2:887c6b45e7fa | 90 | BOOL ret; |
embeddedartists | 2:887c6b45e7fa | 91 | |
embeddedartists | 2:887c6b45e7fa | 92 | // ret = CloseHandle(sobj); /* Win32 */ |
embeddedartists | 2:887c6b45e7fa | 93 | |
embeddedartists | 2:887c6b45e7fa | 94 | // ret = 1; /* uITRON (nothing to do) */ |
embeddedartists | 2:887c6b45e7fa | 95 | |
embeddedartists | 2:887c6b45e7fa | 96 | // OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */ |
embeddedartists | 2:887c6b45e7fa | 97 | // ret = (err == OS_NO_ERR); |
embeddedartists | 2:887c6b45e7fa | 98 | |
embeddedartists | 2:887c6b45e7fa | 99 | // ret = 1; /* FreeRTOS (nothing to do) */ |
embeddedartists | 2:887c6b45e7fa | 100 | |
embeddedartists | 2:887c6b45e7fa | 101 | if (sobj != NULL) { /* MBED RTOS */ |
embeddedartists | 2:887c6b45e7fa | 102 | free(sobj); |
embeddedartists | 2:887c6b45e7fa | 103 | } |
embeddedartists | 2:887c6b45e7fa | 104 | ret = 1; |
embeddedartists | 2:887c6b45e7fa | 105 | |
embeddedartists | 2:887c6b45e7fa | 106 | return ret; |
embeddedartists | 2:887c6b45e7fa | 107 | } |
embeddedartists | 2:887c6b45e7fa | 108 | |
embeddedartists | 2:887c6b45e7fa | 109 | |
embeddedartists | 2:887c6b45e7fa | 110 | |
embeddedartists | 2:887c6b45e7fa | 111 | /*------------------------------------------------------------------------*/ |
embeddedartists | 2:887c6b45e7fa | 112 | /* Request Grant to Access the Volume */ |
embeddedartists | 2:887c6b45e7fa | 113 | /*------------------------------------------------------------------------*/ |
embeddedartists | 2:887c6b45e7fa | 114 | /* This function is called on entering file functions to lock the volume. |
embeddedartists | 2:887c6b45e7fa | 115 | / When a zero is returned, the file function fails with FR_TIMEOUT. |
embeddedartists | 2:887c6b45e7fa | 116 | */ |
embeddedartists | 2:887c6b45e7fa | 117 | |
embeddedartists | 2:887c6b45e7fa | 118 | int ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */ |
embeddedartists | 2:887c6b45e7fa | 119 | _SYNC_t sobj /* Sync object to wait */ |
embeddedartists | 2:887c6b45e7fa | 120 | ) |
embeddedartists | 2:887c6b45e7fa | 121 | { |
embeddedartists | 2:887c6b45e7fa | 122 | int ret; |
embeddedartists | 2:887c6b45e7fa | 123 | |
embeddedartists | 2:887c6b45e7fa | 124 | // ret = (WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0); /* Win32 */ |
embeddedartists | 2:887c6b45e7fa | 125 | |
embeddedartists | 2:887c6b45e7fa | 126 | // ret = (wai_sem(sobj) == E_OK); /* uITRON */ |
embeddedartists | 2:887c6b45e7fa | 127 | |
embeddedartists | 2:887c6b45e7fa | 128 | // OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */ |
embeddedartists | 2:887c6b45e7fa | 129 | // ret = (err == OS_NO_ERR); |
embeddedartists | 2:887c6b45e7fa | 130 | |
embeddedartists | 2:887c6b45e7fa | 131 | // ret = (xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); /* FreeRTOS */ |
embeddedartists | 2:887c6b45e7fa | 132 | |
embeddedartists | 2:887c6b45e7fa | 133 | ret = ((*((Mutex*)sobj)).lock(_FS_TIMEOUT) == osOK); /* MBED RTOS */ |
embeddedartists | 2:887c6b45e7fa | 134 | // static volatile osThreadId lastid = Thread::gettid(); |
embeddedartists | 2:887c6b45e7fa | 135 | // ret = ((*((Semaphore*)sobj)).wait(_FS_TIMEOUT) == 1); /* MBED RTOS */ |
embeddedartists | 2:887c6b45e7fa | 136 | |
embeddedartists | 2:887c6b45e7fa | 137 | return ret; |
embeddedartists | 2:887c6b45e7fa | 138 | } |
embeddedartists | 2:887c6b45e7fa | 139 | |
embeddedartists | 2:887c6b45e7fa | 140 | |
embeddedartists | 2:887c6b45e7fa | 141 | |
embeddedartists | 2:887c6b45e7fa | 142 | /*------------------------------------------------------------------------*/ |
embeddedartists | 2:887c6b45e7fa | 143 | /* Release Grant to Access the Volume */ |
embeddedartists | 2:887c6b45e7fa | 144 | /*------------------------------------------------------------------------*/ |
embeddedartists | 2:887c6b45e7fa | 145 | /* This function is called on leaving file functions to unlock the volume. |
embeddedartists | 2:887c6b45e7fa | 146 | */ |
embeddedartists | 2:887c6b45e7fa | 147 | |
embeddedartists | 2:887c6b45e7fa | 148 | void ff_rel_grant ( |
embeddedartists | 2:887c6b45e7fa | 149 | _SYNC_t sobj /* Sync object to be signaled */ |
embeddedartists | 2:887c6b45e7fa | 150 | ) |
embeddedartists | 2:887c6b45e7fa | 151 | { |
embeddedartists | 2:887c6b45e7fa | 152 | // ReleaseMutex(sobj); /* Win32 */ |
embeddedartists | 2:887c6b45e7fa | 153 | |
embeddedartists | 2:887c6b45e7fa | 154 | // sig_sem(sobj); /* uITRON */ |
embeddedartists | 2:887c6b45e7fa | 155 | |
embeddedartists | 2:887c6b45e7fa | 156 | // OSMutexPost(sobj); /* uC/OS-II */ |
embeddedartists | 2:887c6b45e7fa | 157 | |
embeddedartists | 2:887c6b45e7fa | 158 | // xSemaphoreGive(sobj); /* FreeRTOS */ |
embeddedartists | 2:887c6b45e7fa | 159 | |
embeddedartists | 2:887c6b45e7fa | 160 | (*((Mutex*)sobj)).unlock(); /* MBED RTOS */ |
embeddedartists | 2:887c6b45e7fa | 161 | // (*((Semaphore*)sobj)).release(); /* MBED RTOS */ |
embeddedartists | 2:887c6b45e7fa | 162 | } |
embeddedartists | 2:887c6b45e7fa | 163 | |
embeddedartists | 2:887c6b45e7fa | 164 | #endif |
embeddedartists | 2:887c6b45e7fa | 165 | |
embeddedartists | 2:887c6b45e7fa | 166 | |
embeddedartists | 2:887c6b45e7fa | 167 | |
embeddedartists | 2:887c6b45e7fa | 168 | |
embeddedartists | 2:887c6b45e7fa | 169 | #if _USE_LFN == 3 /* LFN with a working buffer on the heap */ |
embeddedartists | 2:887c6b45e7fa | 170 | /*------------------------------------------------------------------------*/ |
embeddedartists | 2:887c6b45e7fa | 171 | /* Allocate a memory block */ |
embeddedartists | 2:887c6b45e7fa | 172 | /*------------------------------------------------------------------------*/ |
embeddedartists | 2:887c6b45e7fa | 173 | /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE. |
embeddedartists | 2:887c6b45e7fa | 174 | */ |
embeddedartists | 2:887c6b45e7fa | 175 | |
embeddedartists | 2:887c6b45e7fa | 176 | void* ff_memalloc ( /* Returns pointer to the allocated memory block */ |
embeddedartists | 2:887c6b45e7fa | 177 | UINT size /* Number of bytes to allocate */ |
embeddedartists | 2:887c6b45e7fa | 178 | ) |
embeddedartists | 2:887c6b45e7fa | 179 | { |
embeddedartists | 2:887c6b45e7fa | 180 | return malloc(size); |
embeddedartists | 2:887c6b45e7fa | 181 | } |
embeddedartists | 2:887c6b45e7fa | 182 | |
embeddedartists | 2:887c6b45e7fa | 183 | |
embeddedartists | 2:887c6b45e7fa | 184 | /*------------------------------------------------------------------------*/ |
embeddedartists | 2:887c6b45e7fa | 185 | /* Free a memory block */ |
embeddedartists | 2:887c6b45e7fa | 186 | /*------------------------------------------------------------------------*/ |
embeddedartists | 2:887c6b45e7fa | 187 | |
embeddedartists | 2:887c6b45e7fa | 188 | void ff_memfree( |
embeddedartists | 2:887c6b45e7fa | 189 | void* mblock /* Pointer to the memory block to free */ |
embeddedartists | 2:887c6b45e7fa | 190 | ) |
embeddedartists | 2:887c6b45e7fa | 191 | { |
embeddedartists | 2:887c6b45e7fa | 192 | free(mblock); |
embeddedartists | 2:887c6b45e7fa | 193 | } |
embeddedartists | 2:887c6b45e7fa | 194 | |
embeddedartists | 2:887c6b45e7fa | 195 | #endif |
embeddedartists | 2:887c6b45e7fa | 196 | |
embeddedartists | 2:887c6b45e7fa | 197 |