18
18
#include "mbed_critical.h"
19
19
#include "tmpm46b_fc.h"
20
20
21
- #define PROGRAM_WIRTE_MAX 16U /* Page program could be written 16 bytes/4 words once */
22
- #define SECTOR_SIZE 0x8000 /* (512 * 8) sectors */
23
- #define PAGE_SIZE 16U /* Page program size is 16 bytes */
21
+ #define PROGRAM_WIRTE_MAX 16U // Page program could be written 16 bytes/4 words once
22
+ #define SECTOR_SIZE 0x8000 // (512 * 8) sectors
23
+ #define PAGE_SIZE 16U // Page program size is 16 bytes
24
24
25
- #if defined ( __ICCARM__ ) /* IAR Compiler */
25
+ #if defined ( __ICCARM__ ) // IAR Compiler
26
26
#define FLASH_API_ROM ((uint32_t *)__section_begin("FLASH_CODE_ROM"))
27
27
#define SIZE_FLASH_API ((uint32_t)__section_size("FLASH_CODE_ROM"))
28
28
#define FLASH_API_RAM ((uint32_t *)__section_begin("FLASH_CODE_RAM"))
29
29
#pragma section = "FLASH_CODE_RAM"
30
30
#pragma section = "FLASH_CODE_ROM"
31
31
#endif
32
32
33
- #if defined ( __ICCARM__ ) /* IAR Compiler */
34
- static void Copy_Routine (uint32_t * dest , uint32_t * source , uint32_t size )
33
+ #if defined ( __ICCARM__ ) // IAR Compiler
34
+ static void Copy_Routine (uint32_t * dest , uint32_t * source , uint32_t size )
35
35
{
36
36
uint32_t * dest_addr , * source_addr , tmpsize ;
37
37
uint32_t i , tmps , tmpd , mask ;
38
38
39
- dest_addr = dest ;
39
+ dest_addr = dest ;
40
40
source_addr = source ;
41
41
42
42
tmpsize = size >> 2U ;
43
- for (i = 0U ; i < tmpsize ; i ++ ) { /* 32bits copy */
43
+ for (i = 0U ; i < tmpsize ; i ++ ) { // 32bits copy
44
44
* dest_addr = * source_addr ;
45
45
dest_addr ++ ;
46
46
source_addr ++ ;
47
47
}
48
- if (size & 0x00000003U ) { /* if the last data size is not 0(maybe 1,2 or 3), copy the last data */
48
+ if (size & 0x00000003U ) { // if the last data size is not 0(maybe 1,2 or 3), copy the last data
49
49
mask = 0xFFFFFF00U ;
50
50
i = size & 0x00000003U ;
51
51
tmps = * source_addr ;
@@ -56,9 +56,9 @@ static void Copy_Routine(uint32_t * dest, uint32_t * source, uint32_t size)
56
56
}
57
57
tmps = tmps & (~mask );
58
58
tmpd = tmpd & (mask );
59
- * dest_addr = tmps + tmpd ; /* 32bits copy, but only change the bytes need to be changed */
59
+ * dest_addr = tmps + tmpd ; // 32bits copy, but only change the bytes need to be changed
60
60
} else {
61
- /* Do nothing */
61
+ // Do nothing
62
62
}
63
63
}
64
64
#endif
@@ -69,7 +69,7 @@ int32_t flash_init(flash_t *obj)
69
69
TSB_FC -> PROGCR = 0x00000001U ;
70
70
TSB_FC -> ERASECR = 0x00000007U ;
71
71
TSB_FC -> AREASEL = 0x00000000U ;
72
- #if defined ( __ICCARM__ ) /* IAR Compiler */
72
+ #if defined ( __ICCARM__ ) // IAR Compiler
73
73
Copy_Routine (FLASH_API_RAM , FLASH_API_ROM , SIZE_FLASH_API );
74
74
#endif
75
75
return 0 ;
@@ -80,36 +80,36 @@ int32_t flash_free(flash_t *obj)
80
80
return 0 ;
81
81
}
82
82
83
- #if defined ( __ICCARM__ ) /* IAR Compiler */
83
+ #if defined ( __ICCARM__ ) // IAR Compiler
84
84
#pragma location = "FLASH_ROM"
85
85
#endif
86
86
int32_t flash_erase_sector (flash_t * obj , uint32_t address )
87
87
{
88
88
int status = FAIL ;
89
- /* We need to prevent flash accesses during erase operation */
89
+ // We need to prevent flash accesses during erase operation
90
90
core_util_critical_section_enter ();
91
91
92
92
if (FC_SUCCESS == FC_EraseBlock (address )) {
93
93
status = SUCCESS ;
94
94
} else {
95
- /* Do nothing */
95
+ // Do nothing
96
96
}
97
97
core_util_critical_section_exit ();
98
98
return status ;
99
99
}
100
100
101
- #if defined ( __ICCARM__ ) /* IAR Compiler */
101
+ #if defined ( __ICCARM__ ) // IAR Compiler
102
102
#pragma location = "FLASH_ROM"
103
103
#endif
104
104
int32_t flash_program_page (flash_t * obj , uint32_t address , const uint8_t * data , uint32_t size )
105
105
{
106
106
int status = SUCCESS ;
107
107
108
- /* We need to prevent flash accesses during program operation */
108
+ // We need to prevent flash accesses during program operation
109
109
core_util_critical_section_enter ();
110
110
while (size > PROGRAM_WIRTE_MAX ) {
111
- if (FC_SUCCESS == FC_WritePage ((uint32_t )address , (uint32_t * )data )) { /* write one page every time */
112
- /* Do nothing */
111
+ if (FC_SUCCESS == FC_WritePage ((uint32_t )address , (uint32_t * )data )) { // write one page every time
112
+ // Do nothing
113
113
} else {
114
114
status = FAIL ;
115
115
break ;
@@ -118,8 +118,8 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
118
118
address = address + PROGRAM_WIRTE_MAX ;
119
119
data = data + PROGRAM_WIRTE_MAX ;
120
120
}
121
- if (FC_SUCCESS == FC_WritePage ((uint32_t )address , (uint32_t * )data )) { /* write the last data, no more than one page */
122
- /* Do nothing */
121
+ if (FC_SUCCESS == FC_WritePage ((uint32_t )address , (uint32_t * )data )) { // write the last data, no more than one page
122
+ // Do nothing
123
123
} else {
124
124
status = FAIL ;
125
125
}
@@ -128,7 +128,7 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
128
128
return status ;
129
129
}
130
130
131
- #if defined ( __ICCARM__ ) /* IAR Compiler */
131
+ #if defined ( __ICCARM__ ) // IAR Compiler
132
132
#pragma location = "FLASH_ROM"
133
133
#endif
134
134
uint32_t flash_get_sector_size (const flash_t * obj , uint32_t address )
@@ -139,31 +139,31 @@ uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
139
139
return SECTOR_SIZE ;
140
140
}
141
141
142
- #if defined ( __ICCARM__ ) /* IAR Compiler */
142
+ #if defined ( __ICCARM__ ) // IAR Compiler
143
143
#pragma location = "FLASH_ROM"
144
144
#endif
145
145
uint32_t flash_get_page_size (const flash_t * obj )
146
146
{
147
147
return PAGE_SIZE ;
148
148
}
149
149
150
- #if defined ( __ICCARM__ ) /* IAR Compiler */
150
+ #if defined ( __ICCARM__ ) // IAR Compiler
151
151
#pragma location = "FLASH_ROM"
152
152
#endif
153
153
uint32_t flash_get_start_address (const flash_t * obj )
154
154
{
155
155
return FLASH_START_ADDR ;
156
156
}
157
157
158
- #if defined ( __ICCARM__ ) /* IAR Compiler */
158
+ #if defined ( __ICCARM__ ) // IAR Compiler
159
159
#pragma location = "FLASH_ROM"
160
160
#endif
161
161
uint32_t flash_get_size (const flash_t * obj )
162
162
{
163
163
return FLASH_CHIP_SIZE ;
164
164
}
165
165
166
- #if defined ( __ICCARM__ ) /* IAR Compiler */
166
+ #if defined ( __ICCARM__ ) // IAR Compiler
167
167
#pragma location = "FLASH_ROM"
168
168
#endif
169
169
uint8_t flash_get_erase_value (const flash_t * obj )
@@ -172,4 +172,3 @@ uint8_t flash_get_erase_value(const flash_t *obj)
172
172
173
173
return 0xFF ;
174
174
}
175
-
0 commit comments