1818#include "mbed_critical.h"
1919#include "tmpm46b_fc.h"
2020
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
2424
25- #if defined ( __ICCARM__ ) /* IAR Compiler */
25+ #if defined ( __ICCARM__ ) // IAR Compiler
2626#define FLASH_API_ROM ((uint32_t *)__section_begin("FLASH_CODE_ROM"))
2727#define SIZE_FLASH_API ((uint32_t)__section_size("FLASH_CODE_ROM"))
2828#define FLASH_API_RAM ((uint32_t *)__section_begin("FLASH_CODE_RAM"))
2929#pragma section = "FLASH_CODE_RAM"
3030#pragma section = "FLASH_CODE_ROM"
3131#endif
3232
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 )
3535{
3636 uint32_t * dest_addr , * source_addr , tmpsize ;
3737 uint32_t i , tmps , tmpd , mask ;
3838
39- dest_addr = dest ;
39+ dest_addr = dest ;
4040 source_addr = source ;
4141
4242 tmpsize = size >> 2U ;
43- for (i = 0U ; i < tmpsize ; i ++ ) { /* 32bits copy */
43+ for (i = 0U ; i < tmpsize ; i ++ ) { // 32bits copy
4444 * dest_addr = * source_addr ;
4545 dest_addr ++ ;
4646 source_addr ++ ;
4747 }
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
4949 mask = 0xFFFFFF00U ;
5050 i = size & 0x00000003U ;
5151 tmps = * source_addr ;
@@ -56,9 +56,9 @@ static void Copy_Routine(uint32_t * dest, uint32_t * source, uint32_t size)
5656 }
5757 tmps = tmps & (~mask );
5858 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
6060 } else {
61- /* Do nothing */
61+ // Do nothing
6262 }
6363}
6464#endif
@@ -69,7 +69,7 @@ int32_t flash_init(flash_t *obj)
6969 TSB_FC -> PROGCR = 0x00000001U ;
7070 TSB_FC -> ERASECR = 0x00000007U ;
7171 TSB_FC -> AREASEL = 0x00000000U ;
72- #if defined ( __ICCARM__ ) /* IAR Compiler */
72+ #if defined ( __ICCARM__ ) // IAR Compiler
7373 Copy_Routine (FLASH_API_RAM , FLASH_API_ROM , SIZE_FLASH_API );
7474#endif
7575 return 0 ;
@@ -80,36 +80,36 @@ int32_t flash_free(flash_t *obj)
8080 return 0 ;
8181}
8282
83- #if defined ( __ICCARM__ ) /* IAR Compiler */
83+ #if defined ( __ICCARM__ ) // IAR Compiler
8484#pragma location = "FLASH_ROM"
8585#endif
8686int32_t flash_erase_sector (flash_t * obj , uint32_t address )
8787{
8888 int status = FAIL ;
89- /* We need to prevent flash accesses during erase operation */
89+ // We need to prevent flash accesses during erase operation
9090 core_util_critical_section_enter ();
9191
9292 if (FC_SUCCESS == FC_EraseBlock (address )) {
9393 status = SUCCESS ;
9494 } else {
95- /* Do nothing */
95+ // Do nothing
9696 }
9797 core_util_critical_section_exit ();
9898 return status ;
9999}
100100
101- #if defined ( __ICCARM__ ) /* IAR Compiler */
101+ #if defined ( __ICCARM__ ) // IAR Compiler
102102#pragma location = "FLASH_ROM"
103103#endif
104104int32_t flash_program_page (flash_t * obj , uint32_t address , const uint8_t * data , uint32_t size )
105105{
106106 int status = SUCCESS ;
107107
108- /* We need to prevent flash accesses during program operation */
108+ // We need to prevent flash accesses during program operation
109109 core_util_critical_section_enter ();
110110 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
113113 } else {
114114 status = FAIL ;
115115 break ;
@@ -118,8 +118,8 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
118118 address = address + PROGRAM_WIRTE_MAX ;
119119 data = data + PROGRAM_WIRTE_MAX ;
120120 }
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
123123 } else {
124124 status = FAIL ;
125125 }
@@ -128,7 +128,7 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
128128 return status ;
129129}
130130
131- #if defined ( __ICCARM__ ) /* IAR Compiler */
131+ #if defined ( __ICCARM__ ) // IAR Compiler
132132#pragma location = "FLASH_ROM"
133133#endif
134134uint32_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)
139139 return SECTOR_SIZE ;
140140}
141141
142- #if defined ( __ICCARM__ ) /* IAR Compiler */
142+ #if defined ( __ICCARM__ ) // IAR Compiler
143143#pragma location = "FLASH_ROM"
144144#endif
145145uint32_t flash_get_page_size (const flash_t * obj )
146146{
147147 return PAGE_SIZE ;
148148}
149149
150- #if defined ( __ICCARM__ ) /* IAR Compiler */
150+ #if defined ( __ICCARM__ ) // IAR Compiler
151151#pragma location = "FLASH_ROM"
152152#endif
153153uint32_t flash_get_start_address (const flash_t * obj )
154154{
155155 return FLASH_START_ADDR ;
156156}
157157
158- #if defined ( __ICCARM__ ) /* IAR Compiler */
158+ #if defined ( __ICCARM__ ) // IAR Compiler
159159#pragma location = "FLASH_ROM"
160160#endif
161161uint32_t flash_get_size (const flash_t * obj )
162162{
163163 return FLASH_CHIP_SIZE ;
164164}
165165
166- #if defined ( __ICCARM__ ) /* IAR Compiler */
166+ #if defined ( __ICCARM__ ) // IAR Compiler
167167#pragma location = "FLASH_ROM"
168168#endif
169169uint8_t flash_get_erase_value (const flash_t * obj )
@@ -172,4 +172,3 @@ uint8_t flash_get_erase_value(const flash_t *obj)
172172
173173 return 0xFF ;
174174}
175-
0 commit comments