REVISION
Definition in file hdd.h.
#include "../feature.h"
#include "../MESSAGE/message.h"
#include "../GENERIC/generic.h"
#include "../SYSTEM/sys_cpld.h"
Include dependency graph for hdd.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Data Structures | |
| struct | st_HDD |
| HDD globals structure. More... | |
Enumerations | |
| enum | HDD_POWERMODE |
| HDD power mode enumeration. | |
Functions | |
| BOOL | HDD_flush (void) |
| Function flushes the hard disk and makes all change final. | |
| unsigned long | HDD_format (void) |
| Function will low level format the hard disk. | |
| unsigned long | HDD_mount (void) |
| Function initializes the hard disk interface. | |
| BOOL | HDD_readSec (unsigned long, unsigned short *, BOOL) |
| Function reads back the specified logical sector with disk I/O lock wrapper. | |
| BOOL | HDD_unmount (void) |
| Function unmounts hard disk and releases memory allocated to hard disk. | |
| BOOL | HDD_writeSec (unsigned long, unsigned short *, BOOL) |
| Function writes to the logical sector with disk I/O lock wrapper. | |
| BOOL | HDD__rdSec (unsigned long, unsigned short *, BOOL) |
| Function reads back the specified logical sector, specified by the FAT file system layer. | |
| BOOL | HDD__wrSec (unsigned long, unsigned short *, BOOL) |
| Function writes to the logical sector, which is specified by the FAT file system layer. | |
| BOOL | HDD__flush (void) |
| Function flushes hard disk. | |
| ULONG | HDD__format (BOOL) |
| Function initializes HDD. | |
| short | HDD__readReg (unsigned short) |
| Function reads HDD register. | |
| BOOL | HDD__regBitTest (unsigned short, unsigned char) |
| Function tests bits defined by mask variable in Error register. | |
| void | HDD__writeReg (unsigned short, short) |
| Function writes HDD register. | |
| BOOL | HDD__waitReady (void) |
| Function check HD device 'Alterate Status' register bit BSY and bit RDY. | |
| void | HDD__writeLBA (ULONG) |
| Function reads back the specified page/sector. | |
| void | HDD__setPowerMode (HDD_POWERMODE mode, unsigned short) |
| Function sets the HD device to different power mode with time-out parameter in seconds. | |
Variables | |
| st_HDD | Hdd |
| GLOBAL DATA. | |
|
|
Function initializes HDD.
Definition at line 209 of file hdd.c. References st_HDD::flag, Hdd, HDD__readReg(), HDD__regBitTest(), HDD__waitReady(), HDD__writeLBA(), HDD__writeReg(), st_HDD::nativeMaxAddr, and SYS_die(). Referenced by HDD_format(), and HDD_mount(). 00210 {
00211 Hdd.flag = 0;
00212
00213 // Disable device interrupt.
00214 if( HDD__waitReady() == FALSE) return 0L;
00215
00216 HDD__writeReg(HDD_REG__DEVICE_CTRL, 0x0A );
00217
00218 if( HDD__waitReady() == FALSE) return 0L;
00219
00220 /* Initialize global controls. */
00221
00222 if ( lowLevel == TRUE )
00223 { // hdd low level format, takes 15 mins for 10G hard disk
00224
00225 // must do security prepare command before format unit
00226 HDD__writeReg( HDD_REG__COMMAND, HDD_CMD__SECURITY_ERASE_PREPARE );
00227
00228 // wait until busy signal is cleared
00229 while ( HDD__readReg( HDD_REG__STATUS ) & HDD_MASK__STATUS_BIT_BSY );
00230
00231 /* Low-level format HDD device. It will take about 16 minutes */
00232 HDD__writeReg( HDD_REG__FEATURE, 0x11 );
00233 HDD__writeReg( HDD_REG__COMMAND, HDD_CMD__FORMAT_UNIT );
00234
00235 // wait until busy signal is cleared
00236 while ( HDD__readReg( HDD_REG__STATUS ) & HDD_MASK__STATUS_BIT_BSY );
00237
00238 if ( HDD__regBitTest( HDD_REG__STATUS, HDD_MASK__STATUS_BIT_ERR ) ) SYS_die(HDD__FORMAT);
00239 }
00240
00241 HDD__writeReg( HDD_REG__DEVICE_HEAD, 0xE0 ); /* LBA mode, master device */
00242
00243 // get native max address
00244 HDD__writeReg( HDD_REG__COMMAND, HDD_CMD__READ_NATIVE_MAX_ADDR );
00245
00246 // wait until busy signal is cleared
00247 while ( HDD__readReg( HDD_REG__STATUS ) & HDD_MASK__STATUS_BIT_BSY );
00248
00249 /* Get the native max LBA */
00250 Hdd.nativeMaxAddr = ( (unsigned long)HDD__readReg( HDD_REG__SEC_NUMBER ) & 0x000000FF );
00251 Hdd.nativeMaxAddr |= ( (unsigned long)HDD__readReg( HDD_REG__CYLINDER_LOW ) & 0x000000FF ) << 8;
00252 Hdd.nativeMaxAddr |= ( (unsigned long)HDD__readReg( HDD_REG__CYLINDER_HIGH )& 0x000000FF ) << 16;
00253 Hdd.nativeMaxAddr |= ( (unsigned long)HDD__readReg( HDD_REG__DEVICE_HEAD ) & 0x0000000F ) << 24;
00254
00255 HDD__writeLBA( Hdd.nativeMaxAddr );
00256
00257 // MAX address will be preserved by POR and hard reset.
00258 HDD__writeReg( HDD_REG__SEC_COUNT, 1 );
00259
00260 HDD__writeReg( HDD_REG__COMMAND, HDD_CMD__SET_MAX_ADDR );
00261
00262
00263 // wait until busy signal is cleared
00264 while ( HDD__readReg( HDD_REG__STATUS ) & HDD_MASK__STATUS_BIT_BSY );
00265
00266 // suppose HD's capacity is bigger than 1G
00267 if(Hdd.nativeMaxAddr < 0x200000) return 0L;
00268
00269 return Hdd.nativeMaxAddr;
00270 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Function reads back the specified logical sector, specified by the FAT file system layer.
Definition at line 331 of file hdd.c. References st_HDD::flag, Hdd, HDD__readReg(), HDD__waitReady(), HDD__writeLBA(), HDD__writeReg(), SYS_bkpkType, and SYS_delayMicrosecond(). Referenced by HDD_readSec(). 00332 {
00333 int ii;
00334 unsigned short temp;
00335 int status;
00336 BOOL ret = FALSE;
00337
00338 // Original design that data store in media are big endian. New disign will store
00339 // the data to media using PC formate-little endian. The parameter is legacy from
00340 // original design, to comply with new design, the swap should be treated in opposite way.
00341 if(SYS_bkpkType() == BKPK_HDD20 ) swap = !swap;
00342
00343 Hdd.flag &= ~HF_HDDPOWEROFF_PENDING;
00344 if(Hdd.flag&HF_HDDPOWEROFF) HDD_setPowerMode(HDD_POWERON, 0);
00345 else if(Hdd.flag&HF_HDDSLEPT) HDD_setPowerMode(HDD_SOFTRESET, 0);
00346
00347 if(HDD__waitReady() == TRUE)
00348 {
00349 unsigned long delay;
00350 unsigned short retry = 3;
00351
00352 while(1)
00353 {
00354 HDD__writeReg( HDD_REG__SEC_COUNT, 1 );
00355
00356 /* Parse Sec LBA and write them into corresponding registers */
00357 HDD__writeLBA( sec );
00358 /* send 'Read Sectors' command */
00359 HDD__writeReg( HDD_REG__COMMAND, HDD_CMD__READ_SEC_RETRY );
00360
00361 delay = 50000;
00362 while(delay)
00363 {
00364 status = HDD__readReg( HDD_REG__STATUS );
00365
00366 if( (!(status & HDD_MASK__STATUS_BIT_BSY)) &&
00367 (status & HDD_MASK__STATUS_BIT_DRQ) ) break;
00368 else SYS_delayMicrosecond(100);
00369 delay--;
00370 }
00371
00372 if(delay) break;
00373 else if (0 == retry) return FALSE;
00374 else
00375 {
00376 HDD__waitReady();
00377 retry--;
00378 }
00379 }
00380
00381 // start reading one sector data to hdd
00382 if ( swap )
00383 {
00384 temp = HDD__readReg( HDD_REG__DATA );
00385 *(pBuf++) = (( temp >> 8 )&0x00ff) | (temp << 8);
00386 }
00387 else
00388 {
00389 *(pBuf++) = HDD__readReg( HDD_REG__DATA );
00390 }
00391
00392
00393 if ( swap )
00394 {
00395 for ( ii = 2; ii <=256; ii++ )
00396 {
00397 temp = HDD_CS0;
00398 *(pBuf++) = (( temp >> 8 )&0x00ff) | (temp << 8);
00399 }
00400 }
00401 else
00402 {
00403 for ( ii = 2; ii <=256; ii++ )
00404 *(pBuf++) = HDD_CS0;
00405 }
00406
00407 ret = TRUE;
00408 }
00409
00410 return ret;
00411 }
|
Here is the call graph for this function:

|
|
Function reads HDD register.
Definition at line 689 of file hdd.c. Referenced by HDD__flush(), HDD__format(), HDD__rdSec(), HDD__regBitTest(), HDD__waitReady(), and HDD__wrSec(). 00690 {
00691 int HD_reg = 0xfff8;
00692
00693 HD_reg &= HDD_REGSEL;
00694 HD_reg |= reg;
00695 HDD_REGSEL = HD_reg;
00696
00697 if ( reg & CHIP_SEL1 ) return( HDD_CS1);
00698 else return( HDD_CS0);
00699 }
|
|
||||||||||||
|
Function tests bits defined by mask variable in Error register.
Definition at line 757 of file hdd.c. References HDD__readReg(). Referenced by HDD__flush(), and HDD__format(). 00758 {
00759 short temp;
00760
00761 temp = HDD__readReg( reg );
00762
00763 if ( (temp & mask) == 0 ) return ( FALSE );
00764 else return ( TRUE );
00765 }
|
Here is the call graph for this function:

|
||||||||||||
|
Function sets the HD device to different power mode with time-out parameter in seconds. If seconds < 5 OR is NULL it will be automatically set to 109 min.
Definition at line 425 of file hdd.c. References st_HDD::flag, Hdd, HDD__waitReady(), HDD__writeReg(), SYS_bkpkType, and SYS_delayMicrosecond(). Referenced by HDD_mount(), and HDD_unmount(). 00426 {
00427 int pri;
00428
00429 HDD_lock(&pri, 0);
00430
00431 if(HDD_POWERON == mode)
00432 {
00433 switch(SYS_bkpkType())
00434 {
00435 // power up USB1.0
00436 case BKPK_HDD10:
00437 GPIOSR |= (0x0008);
00438 break;
00439
00440 // power up USB2.0, 1.8 and 2.5
00441 case BKPK_HDD20:
00442 HDD_REGSEL |= (HDD_MASK_POWER + HDD_MASK_ACTIVE);
00443 break;
00444 }
00445
00446 SYS_delayMicrosecond( 5000 );
00447
00448 //for reset
00449 //HDD_REGSEL &= 0xFFEF; // negate RESET-
00450 //SYS_delayMicrosecond( 50 );
00451 //HDD_REGSEL |= 0x0010; // assert RESET- for minimum 25 usec
00452 //SYS_delayMicrosecond( 500 );
00453
00454 Hdd.flag = 0;
00455 }
00456 else if(!(Hdd.flag&HF_HDDPOWEROFF))
00457 {
00458 /* Wait for HD device ready */
00459 if(HDD__waitReady() == TRUE)
00460 {
00461 if(HDD_SOFTRESET == mode)
00462 {
00463 HDD__writeReg(HDD_REG__DEVICE_CTRL, 0x0E );
00464 SYS_delayMicrosecond(10);
00465 HDD__writeReg(HDD_REG__DEVICE_CTRL, 0x0A );
00466 Hdd.flag &= ~HF_HDDSLEPT;
00467 }
00468 else if(HDD_POWEROFF == mode)
00469 {
00470 // do soft reset or standby or standby immediate or sleep
00471 /* LBA mode, master device */
00472 //HDD__writeReg( HDD_REG__DEVICE_HEAD, 0xE0 );
00473 //HDD__writeReg( HDD_REG__COMMAND, HDD_CMD__STANDBY_IMMEDIATE );
00474 DISCONNECT_HDD_POWER();
00475 }
00476 else
00477 {
00478 /* LBA mode, master device */
00479 HDD__writeReg( HDD_REG__DEVICE_HEAD, 0xE0 );
00480
00481 switch ( mode )
00482 {
00483 case HDD_IDLE:
00484 HDD__writeReg( HDD_REG__SEC_COUNT, seconds );
00485 HDD__writeReg( HDD_REG__COMMAND, HDD_CMD__IDLE );
00486 break;
00487
00488 case HDD_IDLE_IMMEDIATE:
00489 HDD__writeReg( HDD_REG__COMMAND, HDD_CMD__IDLE_IMMEDIATE );
00490 break;
00491
00492 case HDD_STANDBY:
00493 HDD__writeReg( HDD_REG__SEC_COUNT, (short) seconds );
00494 HDD__writeReg( HDD_REG__COMMAND, HDD_CMD__STANDBY );
00495 break;
00496
00497 case HDD_STANDBY_IMMEDIATE:
00498 HDD__writeReg( HDD_REG__COMMAND, HDD_CMD__STANDBY_IMMEDIATE );
00499 break;
00500
00501 case HDD_SLEEP:
00502 HDD__writeReg( HDD_REG__COMMAND, HDD_CMD__SLEEP );
00503 Hdd.flag |= HF_HDDSLEPT;
00504 break;
00505 case HDD_NOT_IDLE:
00506 default:
00507 break;
00508 }
00509 }
00510 }
00511 }
00512
00513 HDD_unlock(pri, 0);
00514 }
|
Here is the call graph for this function:

|
|
Function check HD device 'Alterate Status' register bit BSY and bit RDY. If BSY = 0 and RDY = 1, and DRQ = 0 then the device is ready to accept new command, return true.
Definition at line 74 of file hdd.c. References HDD__readReg(), HDD__writeReg(), and SYS_delayMicrosecond(). Referenced by HDD__flush(), HDD__format(), HDD__rdSec(), HDD__setPowerMode(), HDD__shutdown(), and HDD__wrSec(). 00075 {
00076 int status;
00077 long timeout = 0L;
00078 unsigned short retry = 2;
00079
00080 while(1)
00081 {
00082 /*
00083 * Wait till
00084 * 1) NOT busy,
00085 * 2) Ready,
00086 * 3) NOT data request.
00087 * To prevent system deadlock, a counter is added here.
00088 */
00089 while(timeout++ < 100000)
00090 {
00091 status = HDD__readReg( HDD_REG__STATUS );
00092
00093 if ( (!(status & HDD_MASK__STATUS_BIT_BSY)) &&
00094 (status & HDD_MASK__STATUS_BIT_RDY) &&
00095 (!(status & HDD_MASK__STATUS_BIT_DRQ))
00096 )
00097
00098 return TRUE;
00099
00100 else SYS_delayMicrosecond(100);
00101
00102 }
00103
00104 if (0 == retry) break;
00105 else
00106 {
00107 HDD__writeReg(HDD_REG__DEVICE_CTRL, 0x0E );
00108 SYS_delayMicrosecond(5000);
00109 HDD__writeReg(HDD_REG__DEVICE_CTRL, 0x0A );
00110 retry--;
00111 }
00112 }
00113
00114 // error happens
00115 // HDD_assert( FALSE, HDD_WAITREADY );
00116
00117 // Report ERROR to caller.
00118 return FALSE;
00119 }
|
Here is the call graph for this function:

|
|
Function reads back the specified page/sector.
Definition at line 735 of file hdd.c. References HDD__writeReg(). Referenced by HDD__format(), HDD__rdSec(), and HDD__wrSec(). 00736 {
00737 /* Parse Sec LBA and write them into corresponding registers */
00738 HDD__writeReg( HDD_REG__SEC_NUMBER, (unsigned char)(Sec & 0x000000FF) );
00739 HDD__writeReg( HDD_REG__CYLINDER_LOW, (unsigned char)((Sec >> 8) & 0x000000FF) );
00740 HDD__writeReg( HDD_REG__CYLINDER_HIGH, (unsigned char)((Sec >> 16) & 0x000000FF) );
00741 HDD__writeReg( HDD_REG__DEVICE_HEAD, (unsigned char)(0xE0 | ((Sec >> 24) & 0x0000000F) ) );
00742 }
|
Here is the call graph for this function:

|
||||||||||||
|
Function writes HDD register.
Definition at line 710 of file hdd.c. Referenced by HDD__flush(), HDD__format(), HDD__rdSec(), HDD__setPowerMode(), HDD__shutdown(), HDD__waitReady(), HDD__writeLBA(), and HDD__wrSec(). 00711 {
00712 int HD_reg = 0xfff8;
00713 HD_reg &= HDD_REGSEL;
00714 HD_reg |= reg;
00715 HDD_REGSEL = HD_reg;
00716
00717
00718 if ( reg & CHIP_SEL1)
00719 {
00720 HDD_CS1 = val;
00721 }
00722 else
00723 {
00724 HDD_CS0 = val;
00725 }
00726 }
|
|
||||||||||||||||
|
Function writes to the logical sector, which is specified by the FAT file system layer.
Definition at line 600 of file hdd.c. References st_HDD::flag, Hdd, HDD__readReg(), HDD__waitReady(), HDD__writeLBA(), HDD__writeReg(), SYS_bkpkType, and SYS_delayMicrosecond(). Referenced by HDD_writeSec(). 00601 {
00602 int ii;
00603 int status;
00604 BOOL ret = FALSE;
00605
00606 // Original design that data store in media are big endian. New disign will store
00607 // the data to media using PC formate-little endian. The parameter is legacy from
00608 // original design, to comply with new design, the swap should be treated in opposite way.
00609 if(SYS_bkpkType() == BKPK_HDD20 ) swap = !swap;
00610
00611 Hdd.flag &= ~HF_HDDPOWEROFF_PENDING;
00612 if(Hdd.flag&HF_HDDPOWEROFF) HDD_setPowerMode(HDD_POWERON, 0);
00613 else if(Hdd.flag&HF_HDDSLEPT) HDD_setPowerMode(HDD_SOFTRESET, 0);
00614
00615 if(HDD__waitReady() == TRUE)
00616 {
00617 unsigned long delay;
00618 unsigned short retry = 3;
00619
00620 while(1)
00621 {
00622 HDD__writeReg( HDD_REG__SEC_COUNT, 1 );
00623
00624 /* Parse Sec LBA and write them into corresponding registers */
00625 HDD__writeLBA( sec );
00626
00627 /* send 'Write Sectors' command */
00628 HDD__writeReg( HDD_REG__COMMAND, HDD_CMD__WRITE_SEC_RETRY );
00629
00630 delay = 50000;
00631 while(delay)
00632 {
00633 status = HDD__readReg( HDD_REG__STATUS );
00634
00635 if( (!(status & HDD_MASK__STATUS_BIT_BSY)) &&
00636 (status & HDD_MASK__STATUS_BIT_DRQ) ) break;
00637 else SYS_delayMicrosecond(100);
00638 delay--;
00639 }
00640
00641 if(delay) break;
00642 else if (0 == retry) return FALSE;
00643 else
00644 {
00645 HDD__waitReady();
00646 retry--;
00647 }
00648 }
00649
00650 // start writing one sector data to hdd
00651 if ( swap )
00652 {
00653 HDD__writeReg( HDD_REG__DATA, (( *pBuf >> 8 )&0x00ff) | (*pBuf << 8) );
00654 pBuf ++;
00655 }
00656 else
00657 {
00658 HDD__writeReg( HDD_REG__DATA, *(pBuf++) );
00659 }
00660
00661 if ( swap )
00662 {
00663 for ( ii = 2; ii <=256; ii++ )
00664 {
00665 HDD_CS0 = (( *pBuf >> 8 )&0x00ff) | ( *pBuf << 8);
00666 pBuf++;
00667 }
00668 }
00669 else
00670 {
00671 for ( ii = 2; ii <=256; ii++ )
00672 HDD_CS0 = *(pBuf++);
00673 }
00674
00675 ret = TRUE;
00676 }
00677
00678 return ret;
00679 }
|
Here is the call graph for this function:

|
|
Function flushes the hard disk and makes all change final.
Definition at line 151 of file hdd.c. References HDD__flush(). Referenced by FAT_flushDisk(). 00152 {
00153 BOOL ret;
00154 int pri;
00155
00156 HDD_lock(&pri, 0);
00157 ret= HDD__flush();
00158 HDD_unlock(pri, 0);
00159
00160 return ret;
00161 }
|
Here is the call graph for this function:

|
|
Function will low level format the hard disk.
Definition at line 196 of file hdd.c. References HDD__format(). Referenced by FAT__format(). 00197 {
00198 return HDD__format(TRUE);
00199 }
|
Here is the call graph for this function:

|
|
Function initializes the hard disk interface.
Definition at line 279 of file hdd.c. References HDD__format(), and HDD__setPowerMode(). Referenced by FAT__format(), and FAT_mountDisk(). 00280 {
00281 // Turn on the power of HDD.
00282 HDD__setPowerMode(HDD_POWERON, 0);
00283
00284 // when pass in FALSE to HDD_format, it will just return a max address
00285 // it does NOT format hdd.
00286 return HDD__format( FALSE );
00287 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Function reads back the specified logical sector with disk I/O lock wrapper.
Definition at line 303 of file hdd.c. References HDD__rdSec(). 00304 {
00305 BOOL ret;
00306 int pri;
00307
00308 HDD_lock(&pri, 0);
00309 ret = HDD__rdSec(sec, pBuf, swap);
00310 HDD_unlock(pri, 0);
00311
00312 return ret;
00313 }
|
Here is the call graph for this function:

|
|
Function unmounts hard disk and releases memory allocated to hard disk.
Definition at line 551 of file hdd.c. References HDD__flush(), and HDD__setPowerMode(). Referenced by FAT__unmountDisk(). 00552 {
00553 HDD__flush();
00554 HDD__setPowerMode(HDD_POWEROFF, 0);
00555 return( TRUE );
00556 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Function writes to the logical sector with disk I/O lock wrapper.
Definition at line 572 of file hdd.c. References HDD__wrSec(). 00573 {
00574 BOOL ret;
00575 int pri;
00576
00577 HDD_lock(&pri, 0);
00578 ret = HDD__wrSec(sec, pBuf, swap);
00579 HDD_unlock(pri, 0);
00580
00581 return ret;
00582 }
|
Here is the call graph for this function:

1.3.9.1