1
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
37
38
39
40
41
42
43
48
49
50
51
52
53
54
55
56
57
58
59
60
62
63
64
65
66
67
68
75
76
77
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
122
123
124
125
126
...
#include "lx_stm32_nor_simulator_driver.h"
static UINT lx_nor_simulator_read(ULONG *flash_address, ULONG *destination, ULONG words);
static UINT lx_nor_simulator_write(ULONG *flash_address, ULONG *source, ULONG words);
static UINT lx_nor_simulator_block_erase(ULONG block, ULONG erase_count);
static UINT lx_nor_simulator_block_erased_verify(ULONG block);
#ifndef LX_DIRECT_READ
static ULONG nor_sector_memory[LX_NOR_SIMULATOR_SECTOR_SIZE];
#endif
static ULONG words_per_block = (LX_NOR_SIMULATOR_SECTOR_SIZE * LX_NOR_SIMULATOR_SECTORS_PER_BLOCK) / sizeof(ULONG);
static UINT is_erased = 0;
static void mem_set(void* s, int c, size_t sz)
{
UCHAR *p = (UCHAR*)s;
UCHAR x = c & 0xff;
while (sz--)
*p++ = x;
}{ ... }
UINT lx_stm32_nor_simulator_initialize(LX_NOR_FLASH *nor_flash)
{
nor_flash->lx_nor_flash_base_address = (ULONG *) LX_NOR_SIMULATOR_FLASH_BASE_ADDRESS;
if (is_erased == 0)
{
mem_set(nor_flash->lx_nor_flash_base_address, 0xff, LX_NOR_SIMULATOR_FLASH_SIZE);
is_erased = 1;
}if (is_erased == 0) { ... }
nor_flash->lx_nor_flash_total_blocks = (LX_NOR_SIMULATOR_FLASH_SIZE / (LX_NOR_SIMULATOR_SECTOR_SIZE * LX_NOR_SIMULATOR_SECTORS_PER_BLOCK));
nor_flash->lx_nor_flash_words_per_block = words_per_block;
nor_flash->lx_nor_flash_driver_read = lx_nor_simulator_read;
nor_flash->lx_nor_flash_driver_write = lx_nor_simulator_write;
nor_flash->lx_nor_flash_driver_block_erase = lx_nor_simulator_block_erase;
nor_flash->lx_nor_flash_driver_block_erased_verify = lx_nor_simulator_block_erased_verify;
#ifndef LX_DIRECT_READ
nor_flash->lx_nor_flash_sector_buffer = &nor_sector_memory[0];/* ... */
#endif
return(LX_SUCCESS);
}{ ... }
static UINT lx_nor_simulator_read(ULONG *flash_address, ULONG *destination, ULONG words)
{
memcpy((VOID *)destination, (VOID *)flash_address, words * sizeof(ULONG));
return(LX_SUCCESS);
}{ ... }
static UINT lx_nor_simulator_write(ULONG *flash_address, ULONG *source, ULONG words)
{
memcpy((VOID *)flash_address, (VOID *)source, words * sizeof(ULONG));
return(LX_SUCCESS);
}{ ... }
static UINT lx_nor_simulator_block_erase(ULONG block, ULONG erase_count)
{
ULONG *pointer;
LX_PARAMETER_NOT_USED(erase_count);
pointer = (ULONG *) (LX_NOR_SIMULATOR_FLASH_BASE_ADDRESS + block * (LX_NOR_SIMULATOR_SECTOR_SIZE * LX_NOR_SIMULATOR_SECTORS_PER_BLOCK));
mem_set((VOID *) pointer, 0xff, words_per_block * sizeof(ULONG));
return(LX_SUCCESS);
}{ ... }
static UINT lx_nor_simulator_block_erased_verify(ULONG block)
{
ULONG *word_ptr;
ULONG words;
word_ptr = (ULONG *) (LX_NOR_SIMULATOR_FLASH_BASE_ADDRESS + block * (LX_NOR_SIMULATOR_SECTOR_SIZE * LX_NOR_SIMULATOR_SECTORS_PER_BLOCK));
words = words_per_block;
while (words--)
{
if (*word_ptr++ != 0xFFFFFFFF)
return(LX_ERROR);
}while (words--) { ... }
return(LX_SUCCESS);
}{ ... }