rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Typedefs | Functions | Variables
flash_int.cpp File Reference

Typedefs

typedef uint32_t flashdata_t
 

Functions

bool flashUnlock (void)
 
bool flashLock (void)
 
static int alignToWord (int v)
 
static __attribute__ ((optimize("O0"))) int flashSectorEraseAtAddress(volatile uint32_t sectorStart)
 
 for (i=0;i< numSectors;i++)
 
int intFlashWrite (flashaddr_t address, const char *buffer, size_t size)
 Copy data from a buffer to the flash memory.
 
bool intFlashIsErased (flashaddr_t address, size_t size)
 Check if the size bytes of flash memory starting at address are erased.
 
bool intFlashCompare (flashaddr_t address, const char *buffer, size_t size)
 Check if the data in buffer are identical to the one in flash memory.
 
int intFlashRead (flashaddr_t source, char *destination, size_t size)
 Copy data from the flash memory to a destination.
 

Variables

static volatile uint32_t mainFlashMap []
 
int size_t size
 
volatile int numSectors = (sizeof(mainFlashMap) / sizeof(mainFlashMap[0])) - 1
 
return FLASH_RETURN_SUCCESS
 

Typedef Documentation

◆ flashdata_t

typedef uint32_t flashdata_t

Definition at line 20 of file flash_int.cpp.

Function Documentation

◆ __attribute__()

static __attribute__ ( (optimize("O0"))  ) volatile
static

Definition at line 47 of file flash_int.cpp.

47 {
48 return MFlash_SectorErase((uint16_t*)sectorStart) != Ok ? FLASH_RETURN_BAD_FLASH : FLASH_RETURN_SUCCESS;
49}
return FLASH_RETURN_SUCCESS
Definition flash_int.cpp:80

◆ alignToWord()

static int alignToWord ( int  v)
static

Definition at line 43 of file flash_int.cpp.

43 {
44 return (v + CYPRESS_FLASH_WORD_ALIGNMENT - 1) & ~(CYPRESS_FLASH_WORD_ALIGNMENT - 1);
45}

Referenced by intFlashErase(), and intFlashWrite().

Here is the caller graph for this function:

◆ flashLock()

bool flashLock ( void  )

Definition at line 37 of file flash_int.cpp.

37 {
38 return true;
39}

Referenced by intFlashErase(), and intFlashWrite().

Here is the caller graph for this function:

◆ flashUnlock()

bool flashUnlock ( void  )

Definition at line 33 of file flash_int.cpp.

33 {
34 return true;
35}

Referenced by intFlashErase(), and intFlashWrite().

Here is the caller graph for this function:

◆ for()

for ( )

Definition at line 63 of file flash_int.cpp.

63 {
64 volatile uint32_t sectorStart = mainFlashMap[i];
65 volatile uint32_t sectorEnd = mainFlashMap[i + 1] - 1;
66 // if the sector overlaps the address range
67 if (sectorStart < (address + size) && sectorEnd >= address) {
68 if (flashSectorEraseAtAddress(sectorStart) != FLASH_RETURN_SUCCESS) {
69 return FLASH_RETURN_BAD_FLASH;
70 }
71 // check if erased
72 size_t sectorSize = sectorEnd - sectorStart + 1;
73 if (flashIsErased(sectorStart, sectorSize) == FALSE)
74 return FLASH_RETURN_BAD_FLASH; /* Sector is not empty despite the erase cycle! */
75
76 }
77 }
int size_t size
Definition flash_int.cpp:51
static volatile uint32_t mainFlashMap[]
Definition flash_int.cpp:22

◆ intFlashCompare()

bool intFlashCompare ( flashaddr_t  address,
const char buffer,
size_t  size 
)

Check if the data in buffer are identical to the one in flash memory.

Parameters
addressFirst address in flash memory to be checked.
bufferBuffer containing the data to compare.
sizeSize of buffer in bytes.
Returns
TRUE if the flash memory and the buffer contain identical data.
FALSE if the flash memory and the buffer don't contain identical data.

Definition at line 109 of file flash_int.cpp.

109 {
110 /* For efficiency, compare flashdata_t values as much as possible,
111 * then, fallback to byte per byte comparison. */
112 while (size >= sizeof(flashdata_t)) {
113 if (*(volatile flashdata_t*) address != *(flashdata_t*) buffer)
114 return FALSE;
115 address += sizeof(flashdata_t);
116 buffer += sizeof(flashdata_t);
117 size -= sizeof(flashdata_t);
118 }
119 while (size > 0) {
120 if (*(volatile char*) address != *buffer)
121 return FALSE;
122 ++address;
123 ++buffer;
124 --size;
125 }
126
127 return TRUE;
128}
uint32_t flashdata_t
Definition flash_int.cpp:20
uint32_t flashdata_t
Definition flash_int.h:54
static BigBufferHandle buffer

◆ intFlashIsErased()

bool intFlashIsErased ( flashaddr_t  address,
size_t  size 
)

Check if the size bytes of flash memory starting at address are erased.

Note
If the memory is erased, one can write data into it safely.
Parameters
addressFirst address in flash memory to be checked.
sizeSize of the memory space to be checked in bytes.
Returns
TRUE Memory is already erased.
FALSE Memory is not erased.

Definition at line 89 of file flash_int.cpp.

89 {
90 /* Check for default set bits in the flash memory
91 * For efficiency, compare flashdata_t values as much as possible,
92 * then, fallback to byte per byte comparison. */
93 while (size >= sizeof(flashdata_t)) {
94 if (*(volatile flashdata_t*) address != (flashdata_t) (-1)) // flashdata_t being unsigned, -1 is 0xFF..FF
95 return false;
96 address += sizeof(flashdata_t);
97 size -= sizeof(flashdata_t);
98 }
99 while (size > 0) {
100 if (*(char*) address != 0xFF)
101 return false;
102 ++address;
103 --size;
104 }
105
106 return TRUE;
107}

Referenced by intFlashSectorErase().

Here is the caller graph for this function:

◆ intFlashRead()

int intFlashRead ( flashaddr_t  source,
char destination,
size_t  size 
)

Copy data from the flash memory to a destination.

Warning
The destination must be at least size bytes long.
Parameters
sourceFirst address of the flash memory to be copied.
destinationBuffer to copy to.
sizeSize of the data to be copied in bytes.
Returns
FLASH_RETURN_SUCCESS if successfully copied.

Definition at line 130 of file flash_int.cpp.

130 {
131 memcpy(destination, (char*) source, size);
133}

◆ intFlashWrite()

int intFlashWrite ( flashaddr_t  address,
const char buffer,
size_t  size 
)

Copy data from a buffer to the flash memory.

Warning
The flash memory area receiving the data must be erased.
The buffer must be at least size bytes long.
Parameters
addressFirst address in the flash memory where to copy the data to.
bufferBuffer containing the data to copy.
sizeSize of the data to be copied in bytes.
Returns
FLASH_RETURN_SUCCESS No error.
FLASH_RETURN_NO_PERMISSION Access denied.

Definition at line 83 of file flash_int.cpp.

83 {
84 uint32_t sizeInWords = alignToWord(size) >> 1;
85 return MFlash_WriteData16Bit((uint16_t*)address, (uint16_t*)buffer, sizeInWords) == Ok ? FLASH_RETURN_SUCCESS : FLASH_RETURN_BAD_FLASH;
86 //return MFlash_WriteData16Bit_Fm0Type3CrSecureArea((uint16_t*)address, (uint16_t*)buffer, sizeInWords) == Ok ? 0 : -1;
87}
static int alignToWord(int v)
Definition flash_int.cpp:43
Here is the call graph for this function:

Variable Documentation

◆ FLASH_RETURN_SUCCESS

return FLASH_RETURN_SUCCESS

◆ mainFlashMap

volatile uint32_t mainFlashMap[]
static
Initial value:
= {
0x00000000, 0x00002000, 0x00004000, 0x00006000, 0x00008000,
0x00010000, 0x00020000, 0x00030000, 0x00040000, 0x00050000,
0x00060000, 0x00070000, 0x00080000, 0x00090000, 0x000A0000,
0x000B0000, 0x000C0000, 0x000D0000, 0x000E0000, 0x000F0000,
0x00100000, 0x00102000, 0x00104000, 0x00106000, 0x00108000,
0x00110000, 0x00120000, 0x00130000, 0x00140000, 0x00150000,
0x00160000, 0x00170000, 0x00180000,
}

Definition at line 22 of file flash_int.cpp.

22 {
23 0x00000000, 0x00002000, 0x00004000, 0x00006000, 0x00008000,
24 0x00010000, 0x00020000, 0x00030000, 0x00040000, 0x00050000,
25 0x00060000, 0x00070000, 0x00080000, 0x00090000, 0x000A0000,
26 0x000B0000, 0x000C0000, 0x000D0000, 0x000E0000, 0x000F0000,
27 0x00100000, 0x00102000, 0x00104000, 0x00106000, 0x00108000,
28 0x00110000, 0x00120000, 0x00130000, 0x00140000, 0x00150000,
29 0x00160000, 0x00170000, 0x00180000,
30 // todo: add upper 40k flash area
31};

Referenced by for().

◆ numSectors

volatile int numSectors = (sizeof(mainFlashMap) / sizeof(mainFlashMap[0])) - 1

Definition at line 61 of file flash_int.cpp.

◆ size

size
Initial value:
{
if (flashSectorEraseAtAddress(address) != FLASH_RETURN_SUCCESS) {
return FLASH_RETURN_BAD_FLASH;
}
#if 0
volatile int i

Definition at line 51 of file flash_int.cpp.

51 {
52 // todo: this is a temporary hack
53 // todo: why the code below doesn't work with -O2?!
54 if (flashSectorEraseAtAddress(address) != FLASH_RETURN_SUCCESS) {
55 return FLASH_RETURN_BAD_FLASH;
56 }

Referenced by for(), intFlashCompare(), intFlashErase(), intFlashIsErased(), intFlashRead(), and intFlashWrite().

Go to the source code of this file.