1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** LevelX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** NOR Flash */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
/**************************************************************************/ |
22 |
|
|
|
23 |
|
|
#define LX_SOURCE_CODE |
24 |
|
|
|
25 |
|
|
|
26 |
|
|
/* Disable ThreadX error checking. */ |
27 |
|
|
|
28 |
|
|
#ifndef LX_DISABLE_ERROR_CHECKING |
29 |
|
|
#define LX_DISABLE_ERROR_CHECKING |
30 |
|
|
#endif |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/* Include necessary system files. */ |
34 |
|
|
|
35 |
|
|
#include "lx_api.h" |
36 |
|
|
|
37 |
|
|
|
38 |
|
|
/**************************************************************************/ |
39 |
|
|
/* */ |
40 |
|
|
/* FUNCTION RELEASE */ |
41 |
|
|
/* */ |
42 |
|
|
/* _lx_nor_flash_driver_write PORTABLE C */ |
43 |
|
|
/* 6.2.1 */ |
44 |
|
|
/* AUTHOR */ |
45 |
|
|
/* */ |
46 |
|
|
/* William E. Lamie, Microsoft Corporation */ |
47 |
|
|
/* */ |
48 |
|
|
/* DESCRIPTION */ |
49 |
|
|
/* */ |
50 |
|
|
/* This function performs a write of the NOR flash memory. */ |
51 |
|
|
/* */ |
52 |
|
|
/* INPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* nor_flash NOR flash instance */ |
55 |
|
|
/* flash_address Address of NOR flash to write */ |
56 |
|
|
/* source Source for the write */ |
57 |
|
|
/* words Number of words to write */ |
58 |
|
|
/* */ |
59 |
|
|
/* OUTPUT */ |
60 |
|
|
/* */ |
61 |
|
|
/* return status */ |
62 |
|
|
/* */ |
63 |
|
|
/* CALLS */ |
64 |
|
|
/* */ |
65 |
|
|
/* (lx_nor_flash_driver_write) Actual driver write */ |
66 |
|
|
/* */ |
67 |
|
|
/* CALLED BY */ |
68 |
|
|
/* */ |
69 |
|
|
/* Application Code */ |
70 |
|
|
/* */ |
71 |
|
|
/**************************************************************************/ |
72 |
|
113510 |
UINT _lx_nor_flash_driver_write(LX_NOR_FLASH *nor_flash, ULONG *flash_address, ULONG *source, ULONG words) |
73 |
|
|
{ |
74 |
|
|
|
75 |
|
|
#ifndef LX_NOR_DISABLE_EXTENDED_CACHE |
76 |
|
|
|
77 |
|
|
UINT status; |
78 |
|
|
UINT i; |
79 |
|
|
ULONG *cache_entry_start; |
80 |
|
|
ULONG *cache_entry_end; |
81 |
|
|
ULONG cache_offset; |
82 |
|
|
|
83 |
|
|
|
84 |
|
|
/* Is the request a whole sector or a partial sector. */ |
85 |
✓✓✓✓
|
113510 |
if ((words == 1) && (nor_flash -> lx_nor_flash_extended_cache_entries)) |
86 |
|
|
{ |
87 |
|
|
|
88 |
|
|
/* One word request, which implies that it is a NOR flash metadata write. */ |
89 |
|
|
|
90 |
|
|
/* Loop through the cache entries to see if there is a sector in cache. */ |
91 |
✓✓ |
147691 |
for (i = 0; i < nor_flash -> lx_nor_flash_extended_cache_entries; i++) |
92 |
|
|
{ |
93 |
|
|
|
94 |
|
|
/* Search through the cache to see if there is a cache entry. */ |
95 |
|
|
|
96 |
|
|
/* Determine the cache entry addresses. */ |
97 |
|
136439 |
cache_entry_start = nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_address; |
98 |
|
136439 |
cache_entry_end = cache_entry_start + LX_NOR_SECTOR_SIZE; |
99 |
|
|
|
100 |
|
|
/* Determine if the flash address in in the cache entry. */ |
101 |
✓✓✓✓ ✓✓ |
136439 |
if ((cache_entry_start) && (flash_address >= cache_entry_start) && (flash_address < cache_entry_end)) |
102 |
|
|
{ |
103 |
|
|
|
104 |
|
|
/* Yes, we found the entry. */ |
105 |
|
|
|
106 |
|
|
/* Calculate the offset into the cache entry. */ |
107 |
|
36678 |
cache_offset = (ULONG)(flash_address - cache_entry_start); |
108 |
|
|
|
109 |
|
|
/* Copy the word into the cache. */ |
110 |
|
36678 |
*(nor_flash -> lx_nor_flash_extended_cache[i].lx_nor_flash_extended_cache_entry_sector_memory + cache_offset) = *source; |
111 |
|
|
|
112 |
|
|
/* Get out of the loop. */ |
113 |
|
36678 |
break; |
114 |
|
|
} |
115 |
|
|
} |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
/* In any case, call the actual driver write function. */ |
119 |
|
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE |
120 |
|
|
status = (nor_flash -> lx_nor_flash_driver_write)(nor_flash, flash_address, source, words); |
121 |
|
|
#else |
122 |
|
113510 |
status = (nor_flash -> lx_nor_flash_driver_write)(flash_address, source, words); |
123 |
|
|
#endif |
124 |
|
|
|
125 |
|
|
/* Return completion status. */ |
126 |
|
113510 |
return(status); |
127 |
|
|
|
128 |
|
|
#else |
129 |
|
|
UINT status; |
130 |
|
|
|
131 |
|
|
|
132 |
|
|
/* Call the actual driver write function. */ |
133 |
|
|
#ifdef LX_NOR_ENABLE_CONTROL_BLOCK_FOR_DRIVER_INTERFACE |
134 |
|
|
status = (nor_flash -> lx_nor_flash_driver_write)(nor_flash, flash_address, source, words); |
135 |
|
|
#else |
136 |
|
|
status = (nor_flash -> lx_nor_flash_driver_write)(flash_address, source, words); |
137 |
|
|
#endif |
138 |
|
|
|
139 |
|
|
/* Return completion status. */ |
140 |
|
|
return(status); |
141 |
|
|
#endif |
142 |
|
|
} |
143 |
|
|
|