1
2
11
14
15
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
56
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
107
117
118
119
120
123
124
125
126
127
128
129
134
135
136
137
138
139
140
141
142
143
144
145
146
147
150
151
152
153
154
155
156
157
158
159
160
161
167
168
...
...
...
#include "fx_stm32_sram_driver.h"
static UINT is_initialized = 0;
VOID fx_stm32_sram_driver(FX_MEDIA *media_ptr)
{
UCHAR *source_buffer;
UCHAR *destination_buffer;
UINT bytes_per_sector;
switch (media_ptr->fx_media_driver_request)
{
case FX_DRIVER_INIT:
{
/* ... */
if (is_initialized == 0)
{
_fx_utility_memory_set((UCHAR *)FX_SRAM_DISK_BASE_ADDRESS, '\0', FX_SRAM_DISK_SIZE);
is_initialized = 1;
}if (is_initialized == 0) { ... }
media_ptr -> fx_media_driver_status = FX_SUCCESS;
break;
...}
case FX_DRIVER_INIT:
case FX_DRIVER_UNINIT:
{
/* ... */
media_ptr -> fx_media_driver_status = FX_SUCCESS;
break;
...}
case FX_DRIVER_UNINIT:
case FX_DRIVER_READ:
{
source_buffer = ((UCHAR *)FX_SRAM_DISK_BASE_ADDRESS) +
((media_ptr->fx_media_driver_logical_sector + media_ptr->fx_media_hidden_sectors) * media_ptr->fx_media_bytes_per_sector);
_fx_utility_memory_copy(source_buffer, media_ptr -> fx_media_driver_buffer,
media_ptr->fx_media_driver_sectors * media_ptr->fx_media_bytes_per_sector);
media_ptr->fx_media_driver_status = FX_SUCCESS;
break;
...}
case FX_DRIVER_READ:
case FX_DRIVER_WRITE:
{
destination_buffer = (UCHAR *)FX_SRAM_DISK_BASE_ADDRESS +
((media_ptr->fx_media_driver_logical_sector + media_ptr->fx_media_hidden_sectors) * media_ptr->fx_media_bytes_per_sector);
_fx_utility_memory_copy(media_ptr->fx_media_driver_buffer, destination_buffer,
media_ptr->fx_media_driver_sectors * media_ptr->fx_media_bytes_per_sector);
media_ptr -> fx_media_driver_status = FX_SUCCESS;
break;
...}
case FX_DRIVER_WRITE:
case FX_DRIVER_FLUSH:
{
/* ... */
media_ptr->fx_media_driver_status = FX_SUCCESS;
break;
...}
case FX_DRIVER_FLUSH:
case FX_DRIVER_ABORT:
{
/* ... */
media_ptr->fx_media_driver_status = FX_SUCCESS;
break;
...}
case FX_DRIVER_ABORT:
case FX_DRIVER_BOOT_READ:
{
/* ... */
source_buffer = (UCHAR *)FX_SRAM_DISK_BASE_ADDRESS;
bytes_per_sector = _fx_utility_16_unsigned_read(&source_buffer[FX_BYTES_SECTOR]);
if (bytes_per_sector > media_ptr->fx_media_memory_size)
{
media_ptr->fx_media_driver_status = FX_BUFFER_ERROR;
break;
}if (bytes_per_sector > media_ptr->fx_media_memory_size) { ... }
_fx_utility_memory_copy(source_buffer, media_ptr -> fx_media_driver_buffer,
bytes_per_sector);
media_ptr -> fx_media_driver_status = FX_SUCCESS;
break;
...}
case FX_DRIVER_BOOT_READ:
case FX_DRIVER_BOOT_WRITE:
{
/* ... */
destination_buffer = (UCHAR *)FX_SRAM_DISK_BASE_ADDRESS;
_fx_utility_memory_copy(media_ptr->fx_media_driver_buffer, destination_buffer,
media_ptr->fx_media_bytes_per_sector);
media_ptr -> fx_media_driver_status = FX_SUCCESS;
break;
...}
case FX_DRIVER_BOOT_WRITE:
default:
{
media_ptr -> fx_media_driver_status = FX_IO_ERROR;
break;
...}default
}switch (media_ptr->fx_media_driver_request) { ... }
}{ ... }