@@ -42,7 +42,7 @@ static void flash_turnon();
42
42
/**
43
43
* global data structure
44
44
*/
45
- //flash_t flash;
45
+ //flash_t flash;
46
46
47
47
/**
48
48
* @brief Control the flash chip write protect enable/disable
@@ -66,20 +66,19 @@ void flash_write_protect(flash_t *obj, uint32_t protect)
66
66
*/
67
67
void flash_init (flash_t * obj )
68
68
{
69
- //SPIC_INIT_PARA spic_init_para;
69
+ //SPIC_INIT_PARA spic_init_para;
70
70
71
- // Init SPI Flash Controller
72
- // DBG_8195A("Initial Spi Flash Controller\n");
73
- //SPI_FLASH_PIN_FCTRL(ON);
71
+ // Init SPI Flash Controller
72
+ // DBG_8195A("Initial Spi Flash Controller\n");
73
+ //SPI_FLASH_PIN_FCTRL(ON);
74
74
75
- if (!SpicFlashInitRtl8195A (SpicOneBitMode )){
75
+ if (!SpicFlashInitRtl8195A (SpicOneBitMode )){
76
76
77
- DBG_8195A ("SPI Init Fail!!!!!!\n" );
78
- HAL_WRITE32 (SYSTEM_CTRL_BASE , REG_SYS_DSTBY_INFO3 , HAL_READ32 (SYSTEM_CTRL_BASE , REG_SYS_DSTBY_INFO3 )|0xf );
79
- }
80
- else {
81
- isinit = 1 ;
82
- }
77
+ DBG_8195A ("SPI Init Fail!!!!!!\n" );
78
+ HAL_WRITE32 (SYSTEM_CTRL_BASE , REG_SYS_DSTBY_INFO3 , HAL_READ32 (SYSTEM_CTRL_BASE , REG_SYS_DSTBY_INFO3 )|0xf );
79
+ } else {
80
+ isinit = 1 ;
81
+ }
83
82
flashobj .SpicInitPara .flashtype = SpicInitParaAllClk [0 ][0 ].flashtype ;
84
83
85
84
//DBG_8195A("Flash ID is = %x %x %x \n",SpicInitParaAllClk[0][0].id[0],SpicInitParaAllClk[0][0].id[1],SpicInitParaAllClk[0][0].id[2]);
@@ -128,17 +127,17 @@ void flash_erase_block(flash_t *obj, uint32_t address)
128
127
*/
129
128
int flash_read_word (flash_t * obj , uint32_t address , uint32_t * data )
130
129
{
131
-
130
+
132
131
flash_turnon ();
133
132
if (isinit == 0 )
134
133
flash_init (& flashobj );
135
- // Wait flash busy done (wip=0)
136
- SpicWaitWipDoneRefinedRtl8195A (flashobj .SpicInitPara );
134
+ // Wait flash busy done (wip=0)
135
+ SpicWaitWipDoneRefinedRtl8195A (flashobj .SpicInitPara );
137
136
138
- * data = HAL_READ32 (SPI_FLASH_BASE , address );
137
+ * data = HAL_READ32 (SPI_FLASH_BASE , address );
139
138
SpicDisableRtl8195A ();
140
139
141
- return 1 ;
140
+ return 1 ;
142
141
}
143
142
144
143
/**
@@ -159,17 +158,16 @@ int flash_write_word(flash_t *obj, uint32_t address, uint32_t data)
159
158
160
159
flashtype = flashobj .SpicInitPara .flashtype ;
161
160
162
- //Write word
163
- HAL_WRITE32 (SPI_FLASH_BASE , address , data );
161
+ //Write word
162
+ HAL_WRITE32 (SPI_FLASH_BASE , address , data );
164
163
165
- // Wait spic busy done
166
- SpicWaitBusyDoneRtl8195A ();
167
-
168
- // Wait flash busy done (wip=0)
164
+ // Wait spic busy done
165
+ SpicWaitBusyDoneRtl8195A ();
166
+
167
+ // Wait flash busy done (wip=0)
169
168
if (flashtype == FLASH_MICRON ){
170
169
SpicWaitOperationDoneRtl8195A (flashobj .SpicInitPara );
171
- }
172
- else
170
+ } else
173
171
SpicWaitWipDoneRefinedRtl8195A (flashobj .SpicInitPara );
174
172
175
173
SpicDisableRtl8195A ();
@@ -199,7 +197,7 @@ int flash_stream_read(flash_t *obj, uint32_t address, uint32_t len, uint8_t * d
199
197
flash_init (& flashobj );
200
198
201
199
202
- // Wait flash busy done (wip=0)
200
+ // Wait flash busy done (wip=0)
203
201
SpicWaitWipDoneRefinedRtl8195A (flashobj .SpicInitPara );
204
202
205
203
offset_to_align = address & 0x03 ;
@@ -232,8 +230,7 @@ int flash_stream_read(flash_t *obj, uint32_t address, uint32_t len, uint8_t * d
232
230
address += 4 ;
233
231
len -= 4 ;
234
232
}
235
- }
236
- else {
233
+ } else {
237
234
while (len >= 4 ) {
238
235
* ((u32 * )pbuf ) = HAL_READ32 (SPI_FLASH_BASE , address );
239
236
pbuf += 4 ;
@@ -301,8 +298,7 @@ int flash_stream_write(flash_t *obj, uint32_t address, uint32_t len, uint8_t *
301
298
// Wait flash busy done (wip=0)
302
299
if (flashtype == FLASH_MICRON ){
303
300
SpicWaitOperationDoneRtl8195A (flashobj .SpicInitPara );
304
- }
305
- else
301
+ } else
306
302
SpicWaitWipDoneRefinedRtl8195A (flashobj .SpicInitPara );
307
303
308
304
@@ -320,16 +316,14 @@ int flash_stream_write(flash_t *obj, uint32_t address, uint32_t len, uint8_t *
320
316
// Wait flash busy done (wip=0)
321
317
if (flashtype == FLASH_MICRON ){
322
318
SpicWaitOperationDoneRtl8195A (flashobj .SpicInitPara );
323
- }
324
- else
319
+ } else
325
320
SpicWaitWipDoneRefinedRtl8195A (flashobj .SpicInitPara );
326
321
327
322
pbuf += 4 ;
328
323
address += 4 ;
329
324
len -= 4 ;
330
325
}
331
- }
332
- else {
326
+ } else {
333
327
while (len >= 4 ) {
334
328
//Write word
335
329
HAL_WRITE32 (SPI_FLASH_BASE , address , (u32 )* ((u32 * )pbuf ));
@@ -338,8 +332,7 @@ int flash_stream_write(flash_t *obj, uint32_t address, uint32_t len, uint8_t *
338
332
// Wait flash busy done (wip=0)
339
333
if (flashtype == FLASH_MICRON ){
340
334
SpicWaitOperationDoneRtl8195A (flashobj .SpicInitPara );
341
- }
342
- else
335
+ } else
343
336
SpicWaitWipDoneRefinedRtl8195A (flashobj .SpicInitPara );
344
337
345
338
pbuf += 4 ;
@@ -362,8 +355,7 @@ int flash_stream_write(flash_t *obj, uint32_t address, uint32_t len, uint8_t *
362
355
// Wait flash busy done (wip=0)
363
356
if (flashtype == FLASH_MICRON ){
364
357
SpicWaitOperationDoneRtl8195A (flashobj .SpicInitPara );
365
- }
366
- else
358
+ } else
367
359
SpicWaitWipDoneRefinedRtl8195A (flashobj .SpicInitPara );
368
360
369
361
}
@@ -406,10 +398,11 @@ int flash_burst_write(flash_t *obj, uint32_t address ,uint32_t Length, uint8_t *
406
398
flashtype = flashobj .SpicInitPara .flashtype ;
407
399
408
400
OccuSize = address & 0xFF ;
409
- if ((Length >= PageSize ) || ((Length + OccuSize ) >= PageSize ))
401
+ if ((Length >= PageSize ) || ((Length + OccuSize ) >= PageSize )){
410
402
ProgramSize = PageSize - OccuSize ;
411
- else
403
+ } else {
412
404
ProgramSize = Length ;
405
+ }
413
406
414
407
flashobj .Length = Length ;
415
408
while (Length > 0 ){
@@ -420,25 +413,22 @@ int flash_burst_write(flash_t *obj, uint32_t address ,uint32_t Length, uint8_t *
420
413
// Wait flash busy done (wip=0)
421
414
if (flashtype == FLASH_MICRON ){
422
415
SpicWaitOperationDoneRtl8195A (flashobj .SpicInitPara );
423
- }
424
- else
416
+ } else
425
417
SpicWaitWipDoneRefinedRtl8195A (flashobj .SpicInitPara );
426
418
427
419
address += ProgramSize ;
428
420
data += ProgramSize ;
429
421
Length -= ProgramSize ;
430
422
OccuSize = 0 ;
431
- }
432
- else {
423
+ } else {
433
424
while ((flashobj .Length ) >= PageSize ){
434
425
SpicUserProgramRtl8195A (data , flashobj .SpicInitPara , address , & (flashobj .Length ));
435
426
// Wait spic busy done
436
427
SpicWaitBusyDoneRtl8195A ();
437
428
// Wait flash busy done (wip=0)
438
429
if (flashtype == FLASH_MICRON ){
439
430
SpicWaitOperationDoneRtl8195A (flashobj .SpicInitPara );
440
- }
441
- else
431
+ } else
442
432
SpicWaitWipDoneRefinedRtl8195A (flashobj .SpicInitPara );
443
433
444
434
address += PageSize ;
@@ -453,8 +443,7 @@ int flash_burst_write(flash_t *obj, uint32_t address ,uint32_t Length, uint8_t *
453
443
// Wait flash busy done (wip=0)
454
444
if (flashtype == FLASH_MICRON ){
455
445
SpicWaitOperationDoneRtl8195A (flashobj .SpicInitPara );
456
- }
457
- else
446
+ } else
458
447
SpicWaitWipDoneRefinedRtl8195A (flashobj .SpicInitPara );
459
448
460
449
break ;
0 commit comments