|
65 | 65 |
|
66 | 66 | #include "io/beeper.h" |
67 | 67 | #include "io/gps.h" |
| 68 | +#include "io/asyncfatfs/asyncfatfs.h" |
| 69 | + |
68 | 70 |
|
69 | 71 | #include "navigation/navigation.h" |
70 | 72 |
|
@@ -198,6 +200,54 @@ typedef struct blackboxDeltaFieldDefinition_s { |
198 | 200 | uint8_t condition; // Decide whether this field should appear in the log |
199 | 201 | } blackboxDeltaFieldDefinition_t; |
200 | 202 |
|
| 203 | +static bool canUseBlackboxWithCurrentConfiguration(void) |
| 204 | +{ |
| 205 | + return feature(FEATURE_BLACKBOX); |
| 206 | +} |
| 207 | + |
| 208 | +#ifdef USE_TERRAIN |
| 209 | +//state machine to get access to other device, it's designed only for one other device, in this case for terrain |
| 210 | +//if you would like to have more devices, some queue must be implemented |
| 211 | +static struct blackboxSDCardAccessStatus_s { |
| 212 | + bool blackboxAccessToSDGrantedToOtherDevice; |
| 213 | + bool requestToSdCardAccessState; |
| 214 | + |
| 215 | +} blackboxSDCardAccessStatus = { |
| 216 | + .blackboxAccessToSDGrantedToOtherDevice = false, |
| 217 | + .requestToSdCardAccessState = false |
| 218 | +}; |
| 219 | + |
| 220 | + |
| 221 | +/** |
| 222 | + * request access from terrain subsystem |
| 223 | + * @return |
| 224 | + */ |
| 225 | +bool requestToSdCardAccess(void) |
| 226 | +{ |
| 227 | + if(blackboxConfig()->device != BLACKBOX_DEVICE_SDCARD || !canUseBlackboxWithCurrentConfiguration()){ |
| 228 | + return true; |
| 229 | + } |
| 230 | + |
| 231 | + if(blackboxSDCardAccessStatus.blackboxAccessToSDGrantedToOtherDevice){ |
| 232 | + return true; |
| 233 | + } |
| 234 | + |
| 235 | + blackboxSDCardAccessStatus.requestToSdCardAccessState = true; |
| 236 | + return false; |
| 237 | +} |
| 238 | + |
| 239 | +/** |
| 240 | + * release access from terrain subsystem |
| 241 | + * @return |
| 242 | + */ |
| 243 | +void releaseSdCardAccess(void) |
| 244 | +{ |
| 245 | + blackboxSDCardAccessStatus.blackboxAccessToSDGrantedToOtherDevice = false; |
| 246 | + blackboxSDCardAccessStatus.requestToSdCardAccessState = false; |
| 247 | +} |
| 248 | +#endif |
| 249 | + |
| 250 | + |
201 | 251 | /** |
202 | 252 | * Description of the blackbox fields we are writing in our main intra (I) and inter (P) frames. This description is |
203 | 253 | * written into the flight log header so the log can be properly interpreted (but these definitions don't actually cause |
@@ -2178,6 +2228,24 @@ static void blackboxLogIteration(timeUs_t currentTimeUs) |
2178 | 2228 | */ |
2179 | 2229 | void blackboxUpdate(timeUs_t currentTimeUs) |
2180 | 2230 | { |
| 2231 | +#ifdef USE_TERRAIN |
| 2232 | + if(blackboxConfig()->device == BLACKBOX_DEVICE_SDCARD){ |
| 2233 | + //access to SD card is given to other device |
| 2234 | + if(blackboxSDCardAccessStatus.blackboxAccessToSDGrantedToOtherDevice){ |
| 2235 | + return; |
| 2236 | + } |
| 2237 | + |
| 2238 | + //incooming request to get access to SD card |
| 2239 | + if(blackboxSDCardAccessStatus.requestToSdCardAccessState && (blackboxState == BLACKBOX_STATE_RUNNING || blackboxState == BLACKBOX_STATE_STOPPED)){ |
| 2240 | + //we have to be sure that all writes are already processed and SD card is in idle |
| 2241 | + if(afatfs_isIdle()){ |
| 2242 | + blackboxSDCardAccessStatus.requestToSdCardAccessState = false; |
| 2243 | + blackboxSDCardAccessStatus.blackboxAccessToSDGrantedToOtherDevice = true; |
| 2244 | + } |
| 2245 | + } |
| 2246 | + } |
| 2247 | +#endif |
| 2248 | + |
2181 | 2249 | if (blackboxState >= BLACKBOX_FIRST_HEADER_SENDING_STATE && blackboxState <= BLACKBOX_LAST_HEADER_SENDING_STATE) { |
2182 | 2250 | blackboxReplenishHeaderBudget(); |
2183 | 2251 | } |
@@ -2308,15 +2376,6 @@ void blackboxUpdate(timeUs_t currentTimeUs) |
2308 | 2376 | } |
2309 | 2377 | } |
2310 | 2378 |
|
2311 | | -static bool canUseBlackboxWithCurrentConfiguration(void) |
2312 | | -{ |
2313 | | - return feature(FEATURE_BLACKBOX) |
2314 | | -#ifdef USE_TERRAIN |
2315 | | - && terrainConfig()->terrainEnabled == false && blackboxConfig()->device == BLACKBOX_DEVICE_SDCARD |
2316 | | -#endif |
2317 | | - ; |
2318 | | -} |
2319 | | - |
2320 | 2379 | BlackboxState getBlackboxState(void) |
2321 | 2380 | { |
2322 | 2381 | return blackboxState; |
|
0 commit comments