]> git.sur5r.net Git - freertos/blob - FreeRTOS-Labs/Source/FreeRTOS-Plus-FAT/portable/avr32_uc3/ff_flush.c
Add the Labs projects provided in the V10.2.1_191129 zip file.
[freertos] / FreeRTOS-Labs / Source / FreeRTOS-Plus-FAT / portable / avr32_uc3 / ff_flush.c
1 //\r
2 //\r
3 //\r
4 \r
5 #define SD_MMC_SPI_MEM 1\r
6 \r
7 #include "ff_headers.h"\r
8 \r
9 #include "logbuf.h"\r
10 #include "secCache.h"\r
11 \r
12 #include "ff_flush.h"\r
13 \r
14 extern BaseType_t FF_SemaphoreTaken( void *pxSemaphore );\r
15 \r
16 FF_Error_t FF_FlushWrites( FF_IOManager_t *pxIOManager, BaseType_t xForced )\r
17 {\r
18 FF_Error_t xRetValue;\r
19 \r
20         if( ( pxIOManager == NULL ) || ( cache_dirt_count() == 0 ) )\r
21         {\r
22                 xRetValue = FF_ERR_NONE;\r
23         }\r
24         else if( ( pxIOManager->ucPreventFlush != pdFALSE ) && ( xForced == pdFALSE ) )\r
25         {\r
26                 xRetValue = FF_ERR_IOMAN_PARTITION_MOUNTED | FF_ERRFLAG;\r
27         }\r
28         else\r
29         {\r
30         BaseType_t rc = 0;\r
31                 if( xForced != pdFALSE )\r
32                 {\r
33                         FF_FlushCache( pxIOManager );\r
34                 }\r
35 \r
36 //              if( FF_TrySemaphore( pxIOManager->pvSemaphore, xForced ? 5000 : 0 ) != pdFALSE )\r
37                 if( ( xForced != pdFALSE ) || ( FF_SemaphoreTaken( pxIOManager->pvSemaphore ) == pdFALSE ) )\r
38                 {\r
39                         rc = cache_flush( xForced );\r
40 //                      FF_ReleaseSemaphore( pxIOManager->pvSemaphore );\r
41                 }\r
42                 xRetValue = rc;\r
43         }\r
44         return xRetValue;\r
45 }\r
46 \r
47 FF_Error_t FF_StopFlush( FF_IOManager_t *pxIOManager, BaseType_t xFlag )\r
48 {\r
49 FF_Error_t xRetValue;\r
50 \r
51         if( pxIOManager == NULL )\r
52         {\r
53                 xRetValue = 0;\r
54         }\r
55         else\r
56         {\r
57                 vTaskSuspendAll();\r
58                 {\r
59                         xRetValue = pxIOManager->ucPreventFlush;\r
60                         if( xFlag != FLUSH_ENABLE )\r
61                         {\r
62                                 xRetValue++;\r
63                         }\r
64                         else if ( xRetValue > 0 )\r
65                         {\r
66                                 xRetValue--;\r
67                         }\r
68                         pxIOManager->ucPreventFlush = xRetValue;\r
69                 }\r
70                 xTaskResumeAll();\r
71 \r
72         }\r
73 \r
74         return xRetValue;\r
75 }\r