summaryrefslogtreecommitdiff
path: root/FreeRTOS-Labs/Source/FreeRTOS-Plus-FAT/portable/avr32_uc3/ff_flush.c
blob: b47e01e1ea00f2296299df8a39d737ad2a1ff52b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
//
//

#define	SD_MMC_SPI_MEM 1

#include "ff_headers.h"

#include "logbuf.h"
#include "secCache.h"

#include "ff_flush.h"

extern BaseType_t FF_SemaphoreTaken( void *pxSemaphore );

FF_Error_t FF_FlushWrites( FF_IOManager_t *pxIOManager, BaseType_t xForced )
{
FF_Error_t xRetValue;

	if( ( pxIOManager == NULL ) || ( cache_dirt_count() == 0 ) )
	{
		xRetValue = FF_ERR_NONE;
	}
	else if( ( pxIOManager->ucPreventFlush != pdFALSE ) && ( xForced == pdFALSE ) )
	{
		xRetValue = FF_ERR_IOMAN_PARTITION_MOUNTED | FF_ERRFLAG;
	}
	else
	{
	BaseType_t rc = 0;
		if( xForced != pdFALSE )
		{
			FF_FlushCache( pxIOManager );
		}

//		if( FF_TrySemaphore( pxIOManager->pvSemaphore, xForced ? 5000 : 0 ) != pdFALSE )
		if( ( xForced != pdFALSE ) || ( FF_SemaphoreTaken( pxIOManager->pvSemaphore ) == pdFALSE ) )
		{
			rc = cache_flush( xForced );
//			FF_ReleaseSemaphore( pxIOManager->pvSemaphore );
		}
		xRetValue = rc;
	}
	return xRetValue;
}

FF_Error_t FF_StopFlush( FF_IOManager_t *pxIOManager, BaseType_t xFlag )
{
FF_Error_t xRetValue;

	if( pxIOManager == NULL )
	{
		xRetValue = 0;
	}
	else
	{
		vTaskSuspendAll();
		{
			xRetValue = pxIOManager->ucPreventFlush;
			if( xFlag != FLUSH_ENABLE )
			{
				xRetValue++;
			}
			else if ( xRetValue > 0 )
			{
				xRetValue--;
			}
			pxIOManager->ucPreventFlush = xRetValue;
		}
		xTaskResumeAll();

	}

	return xRetValue;
}