📄 sm.lst
字号:
313 2 // Add Read Redundant Area Code Begin
314 2 SmSetFlashAddr(Page); // Prepare Address for sending
315 2
316 2 SmFlashCmd(FLASH_READ_EX); // Combine with SmFlashCmd(FLASH_READ)?
317 2 // Add Read Redundant Area Code End
318 2
319 2 SmSetFlashAddr(Page);
320 2
321 2 if ((SmFlashCmd(FLASH_READ)) != STATUS_SUCCESS)
322 2 {
323 3 RetVal = STATUS_FLASH_ERROR;
324 3 continue;
325 3 }
326 2
327 2 /*
328 2 *********************************************************************************************************
329 2 * ECC Detect Area
330 2 *********************************************************************************************************
331 2 */
332 2
333 2 if (SpareArea[DATA_STS] != VALID_DATA)
334 2 {
335 3 RetVal = STATUS_DATA_ERROR;
336 3 continue;
337 3 }
338 2
339 2 ChunkCounter++;
340 2 return STATUS_SUCCESS;
341 2 }
342 1 return RetVal;
343 1 }
344
345 //----------------------------------------------------------------------------
346 // Description:
347 // Write one page of data from FIFO to SmartMedia
348 //----------------------------------------------------------------------------
349 STATUS SmWritePage (UINT32 Page)
350 {
351 1 BYTE RetryCount;
352 1 STATUS RetVal;
353 1
354 1 for (RetryCount = 0; RetryCount < 3; RetryCount++)
355 1 {
356 2 if (SmNeedSetExtra)
357 2 {
358 3 SmSetBlockExtra(SmSrcBlockLog); // Prepare Redundant Area Data
359 3 }
360 2
361 2 SmSetFlashAddr(Page); // Prepare Address for sending
362 2
363 2 if ((SmFlashCmd(FLASH_PROG)) != STATUS_SUCCESS)
C51 COMPILER V7.50 SM 04/17/2007 10:39:20 PAGE 7
364 2 {
365 3 RetVal = STATUS_FLASH_ERROR;
366 3 continue;
367 3 }
368 2
369 2 /*
370 2 *********************************************************************************************************
371 2 * ECC Generate Area
372 2 *********************************************************************************************************
373 2 */
374 2
375 2 ChunkCounter++;
376 2 return STATUS_SUCCESS;
377 2 }
378 1 return RetVal;
379 1 }
380
381 //----------------------------------------------------------------------------
382 // Description:
383 // Read next 512 bytes of data from the Smart Media device
384 //----------------------------------------------------------------------------
385 STATUS SmReadNextSector (void)
386 {
387 1 STATUS RetVal;
388 1 BYTE RetryCount;
389 1
390 1 for (RetryCount = 0; RetryCount < 3; RetryCount++)
391 1 {
392 2 if ((SmFlashCmd(FLASH_READ_NEXT_DATA)) != STATUS_SUCCESS)
393 2 {
394 3 RetVal = STATUS_FLASH_ERROR;
395 3 continue;
396 3 }
397 2
398 2 /*
399 2 *********************************************************************************************************
400 2 * ECC Detect Area
401 2 *********************************************************************************************************
402 2 */
403 2
404 2 if (ChunkCounter == 3)
405 2 {
406 3 ChunkCounter = 0;
407 3 SectorStart++;
408 3 }
409 2 else
410 2 {
411 3 ChunkCounter++;
412 3 }
413 2
414 2 return STATUS_SUCCESS;
415 2 }
416 1 return RetVal;
417 1 }
418
419 //----------------------------------------------------------------------------
420 // Description:
421 // Write next 512 bytes of data from the Smart Media device
422 //----------------------------------------------------------------------------
423 STATUS SmWriteNextSector (void)
424 {
425 1 STATUS RetVal;
C51 COMPILER V7.50 SM 04/17/2007 10:39:20 PAGE 8
426 1 BYTE RetryCount;
427 1
428 1 for (RetryCount = 0; RetryCount < 3; RetryCount++)
429 1 {
430 2 if ((SmFlashCmd(FLASH_PROG_NEXT_DATA)) != STATUS_SUCCESS)
431 2 {
432 3 RetVal = STATUS_FLASH_ERROR;
433 3 continue;
434 3 }
435 2
436 2 /*
437 2 *********************************************************************************************************
438 2 * ECC Generate Area
439 2 *********************************************************************************************************
440 2 */
441 2 if (ChunkCounter == 3)
442 2 {
443 3 // Add Code For Writing Redundant Area Begin
444 3 SmFlashCmd(FLASH_PROG_EX);
445 3 // Add Code For Writing Redundant Area End
446 3
447 3 SmJustWrite = true;
448 3
449 3 ChunkCounter = 0;
450 3
451 3 RetVal = SmParseStatus(SmReadStatus());
452 3
453 3 if (RetVal == STATUS_SUCCESS)
454 3 {
455 4 SmCleanPage[PageIndex] = true;
456 4 SectorStart++;
457 4 }
458 3 else if (RetVal == STATUS_FLASH_ERROR)
459 3 {
460 4 RetVal = SmRepairBlock();
461 4 }
462 3 break;
463 3 }
464 2 else
465 2 {
466 3 ChunkCounter++;
467 3 return STATUS_SUCCESS;
468 3 }
469 2 }
470 1 return RetVal;
471 1 }
472
473 //----------------------------------------------------------------------------
474 // Description:
475 // Mark one block to be invalid
476 //----------------------------------------------------------------------------
477 void SmMarkInvalidBlock (UINT16 Block)
478 {
479 1 Block = Block;
480 1 // Need Any code for BLOCK_STS and Write Page
481 1 }
482
483 //----------------------------------------------------------------------------
484 // Description:
485 // Erase one block of FLASH
486 //----------------------------------------------------------------------------
487 STATUS SmEraseBlock (UINT16 Block)
C51 COMPILER V7.50 SM 04/17/2007 10:39:20 PAGE 9
488 {
489 1 BYTE RetryCount;
490 1 STATUS RetVal;
491 1 UINT32 Page = (UINT32)Block << SmPage2BlockShift;
492 1
493 1 // Need Any code for CIS Block
494 1
495 1 for (RetryCount = 0; RetryCount < 3; RetryCount++)
496 1 {
497 2 SmSetFlashAddr(Page);
498 2
499 2 if (SmFlashCmd(FLASH_ERASE) != STATUS_SUCCESS)
500 2 {
501 3 RetVal = STATUS_FLASH_ERROR;
502 3 continue;
503 3 }
504 2
505 2 RetVal = SmParseStatus(SmReadStatus());
506 2 if (RetVal == STATUS_SUCCESS)
507 2 {
508 3 return STATUS_SUCCESS;
509 3 }
510 2 else
511 2 {
512 3 continue;
513 3 }
514 2 }
515 1 return RetVal;
516 1 }
517
518 //----------------------------------------------------------------------------
519 // Description:
520 // Translate the logical block to physical block
521 //----------------------------------------------------------------------------
522 UINT16 SmLog2PhyBlock (UINT16 LogBlockSeg)
523 {
524 1 UINT16 TableAddr;
525 1 BYTE Segment = LogBlockSeg >> SmBlock2SegShift;
526 1
527 1 #ifdef SM_FAST
if (Segment == 0)
{
SegmentBase = 0;
TableAddr = LogBlockSeg & SmBlockSegMask;
}
else
{
if (Segment != SmBlockTabSeg)
{
SmReadBlockTab(Segment);
}
else
{
SmSetSegmentBase(Segment);
}
TableAddr = TabSegment1Base + (LogBlockSeg & SmBlockSegMask);
}
#else
546 1 if (Segment != SmBlockTabSeg)
547 1 {
548 2 SmReadBlockTab(Segment);
549 2 }
C51 COMPILER V7.50 SM 04/17/2007 10:39:20 PAGE 10
550 1 TableAddr = LogBlockSeg & SmBlockSegMask;
551 1 #endif
552 1 return ((SmBlockTab[TableAddr]));
553 1 }
554
555 //----------------------------------------------------------------------------
556 // Description:
557 // Update the block table for dedicated block
558 //----------------------------------------------------------------------------
559 void SmUpdateBlockTab (UINT16 LogBlock, UINT16 PhyBlock)
560 {
561 1 UINT16 TableAddr;
562 1 BYTE Segment = LogBlock >> SmBlock2SegShift;
563 1
564 1 #ifdef SM_FAST
if (Segment == 0)
{
TableAddr = LogBlock & SmBlockSegMask;
}
else
{
if (Segment != SmBlockTabSeg)
{
return;
}
TableAddr = TabSegment1Base + (LogBlock & SmBlockSegMask);
}
SmBlockTab[TableAddr] = PhyBlock;
#else
579 1 if (Segment != SmBlockTabSeg)
580 1 {
581 2 return;
582 2 }
583 1 TableAddr = LogBlock & SmBlockSegMask;
584 1 SmBlockTab[TableAddr] = PhyBlock;
585 1 #endif
586 1 }
587
588 //----------------------------------------------------------------------------
589 // Description:
590 // Get one block address from header area
591 //----------------------------------------------------------------------------
592 UINT16 SmGetAddr (void)
593 {
594 1 UINT16 Addr, A1, A2;
595 1 bit Parity1, Parity2;
596 1
597 1 // Get Segment LBA from Spare Area
598 1 ((TDataCast *)&A1)->ucByte[0] = SpareArea[BLOCK_ADDR1_H];
599 1 ((TDataCast *)&A1)->ucByte[1] = SpareArea[BLOCK_ADDR1_L];
600 1 ((TDataCast *)&A2)->ucByte[0] = SpareArea[BLOCK_ADDR2_H];
601 1 ((TDataCast *)&A2)->ucByte[1] = SpareArea[BLOCK_ADDR2_L];
602 1
603 1 Parity1 = EvenParity(A1);
604 1 Parity2 = EvenParity(A2);
605 1
606 1 if (Parity1 && Parity2)
607 1 {
608 2 if (A1 != A2)
609 2 {
610 3 return ERROR_BLOCK;
611 3 }
C51 COMPILER V7.50 SM 04/17/2007 10:39:20 PAGE 11
612 2 else if (A1 == FREE_BLOCK)
613 2 {
614 3 return FREE_BLOCK;
615 3 }
616 2 else
617 2 {
618 3 Addr = A1;
619 3 }
620 2 }
621 1 else if (Parity1 && (!Parity2))
622 1 {
623 2 if (A1 == FREE_BLOCK)
624 2 {
625 3 return FREE_BLOCK;
626 3 }
627 2 else
628 2 {
629 3 Addr = A1;
630 3 }
631 2 }
632 1 else if ((!Parity1) && Parity2)
633 1 {
634 2 if (A2 == FREE_BLOCK)
635 2 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -