revision 251:3c5953d944e0
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 251:3c5953d944e0 |
parent | 250:84e056e12a19 |
child | 252:cfd0ec3bfeec |
author | nkeynes |
date | Wed Dec 20 11:24:16 2006 +0000 (16 years ago) |
Tidy up the core IDE test case - now passes (usually) on the real thing. Main
surprise was that it seems to always fail the first packet command after a
reset with code 06,29 (drive reset), no matter how long its been since the
reset.
surprise was that it seems to always fail the first packet command after a
reset with code 06,29 (drive reset), no matter how long its been since the
reset.
![]() | test/ide.c | view | annotate | diff | log | |
![]() | test/ide.h | view | annotate | diff | log | |
![]() | test/testide.c | view | annotate | diff | log |
1.1 --- a/test/ide.c Tue Dec 19 11:58:12 2006 +00001.2 +++ b/test/ide.c Wed Dec 20 11:24:16 2006 +00001.3 @@ -124,10 +124,10 @@1.4 int i;1.5 for( i=0; i<MAX_WAIT; i++ ) {1.6 status = byte_read(IDE_ALTSTATUS);1.7 - if( (status & 0x80) != 0x80 )1.8 + if( (status & 0x80) == 0 )1.9 return 0;1.10 }1.11 - printf( "Timeout waiting for IDE to become ready\n" );1.12 + printf( "Timeout waiting for IDE to become ready (status = 0x%02X)\n", status );1.13 ide_dump_registers();1.14 return 1;1.15 }1.16 @@ -164,20 +164,14 @@1.17 byte_write( IDE_DEVICE, 0 );1.18 byte_write( IDE_COMMAND, IDE_CMD_PACKET );1.19 status = byte_read(IDE_ALTSTATUS); /* delay 1 PIO cycle as per spec */1.20 - printf( "After writing PACKET command byte:\n" );1.21 - ide_dump_registers();1.22 /* Wait until device is ready to accept command */1.23 if( ide_wait_ready() )1.24 return 1;1.25 - printf( "Device ready to receive packet:\n" );1.26 - ide_dump_registers();1.28 /* Write the command */1.29 for( i=0; i<6; i++ ) {1.30 word_write( IDE_DATA, spkt[i] );1.31 }1.32 - printf( "After writing command packet:\n" );1.33 - ide_dump_registers();1.34 }1.36 int ide_read_pio( char *buf, int buflen ) {1.37 @@ -334,6 +328,17 @@1.38 return ide_do_packet_command_pio( cmd, buf, 10 );1.39 }1.41 +int ide_get_sense_code()1.42 +{1.43 + char buf[10];1.44 + int len = ide_sense_error( buf );1.45 + if( len != 10 ) {1.46 + printf( "ERROR: Sense request failed!\n" );1.47 + return -1;1.48 + }1.49 + return ((int)buf[8] << 8) | buf[2];1.50 +}1.51 +1.52 void ide_print_sense_error()1.53 {1.54 char buf[10];1.55 @@ -428,10 +433,11 @@1.56 return 0;1.57 }1.59 -int ide_read_status( char *buf, int length )1.60 +int ide_read_status( char *buf, int length, int type )1.61 {1.62 char cmd[12] = { 0x40,0,0,0, 0xFF,0,0,0, 0,0,0,0 };1.64 + cmd[1] = type;1.65 return ide_do_packet_command_pio( cmd, buf, length );1.66 }
2.1 --- a/test/ide.h Tue Dec 19 11:58:12 2006 +00002.2 +++ b/test/ide.h Wed Dec 20 11:24:16 2006 +00002.3 @@ -22,6 +22,8 @@2.5 int ide_sense_error( char *buf );2.7 +int ide_get_sense_code();2.8 +2.9 /**2.10 * Retrieve session information. If session == 0, returns the2.11 * end-of-disc information instead.
3.1 --- a/test/testide.c Tue Dec 19 11:58:12 2006 +00003.2 +++ b/test/testide.c Wed Dec 20 11:24:16 2006 +00003.3 @@ -1,5 +1,5 @@3.4 /**3.5 - * $Id: testide.c,v 1.2 2006-12-19 11:53:39 nkeynes Exp $3.6 + * $Id: testide.c,v 1.3 2006-12-20 11:24:16 nkeynes Exp $3.7 *3.8 * IDE interface test cases. Covers all (known) IDE registers in the3.9 * 5F7000 - 5F74FF range including DMA, but does not cover any GD-Rom3.10 @@ -99,6 +99,95 @@3.12 #define CHECK_REGS( r ) if( check_regs(r, __FILE__, __LINE__, __func__) != 0 ) { return -1; }3.14 +3.15 +uint32_t post_packet_ready_regs[] =3.16 + { IDE_ALTSTATUS, 0x58,3.17 + IDE_COUNT, 0x01,3.18 + IDE_LBA1, 8,3.19 + IDE_LBA2, 0,3.20 + IDE_DEVICE, 0,3.21 + IDE_STATUS, 0x58, 0, 0 };3.22 +3.23 +uint32_t post_packet_cmd_regs[] =3.24 + { IDE_ALTSTATUS, 0xD0,3.25 + IDE_ERROR, 0x00,3.26 + IDE_COUNT, 0x01,3.27 + IDE_LBA1, 8,3.28 + IDE_LBA2, 0,3.29 + IDE_DEVICE, 0,3.30 + IDE_STATUS, 0xD0, 0, 0 };3.31 +3.32 +uint32_t packet_cmd_error6_regs[] =3.33 + { IDE_ALTSTATUS, 0x51,3.34 + IDE_ERROR, 0x60,3.35 + IDE_COUNT, 0x03,3.36 + IDE_LBA1, 8,3.37 + IDE_LBA2, 0,3.38 + IDE_DEVICE, 0,3.39 + IDE_STATUS, 0x51, 0, 0 };3.40 +3.41 +uint32_t packet_data_ready_regs[] =3.42 + { IDE_ALTSTATUS, 0x58,3.43 + IDE_ERROR, 0x00,3.44 + IDE_COUNT, 0x02,3.45 + IDE_LBA0, 0x00,3.46 + IDE_LBA1, 0x0C,3.47 + IDE_LBA2, 0,3.48 + IDE_DEVICE, 0,3.49 + IDE_STATUS, 0x58, 0, 0 };3.50 +3.51 +3.52 +uint32_t post_packet_data_regs[] =3.53 + { IDE_ALTSTATUS, 0xD0,3.54 + IDE_ERROR, 0x00,3.55 + IDE_COUNT, 0x02,3.56 + IDE_LBA0, 0x00,3.57 + IDE_LBA1, 0x0C,3.58 + IDE_LBA2, 0,3.59 + IDE_DEVICE, 0,3.60 + IDE_STATUS, 0xD0, 0, 0 };3.61 +3.62 +uint32_t packet_complete_regs[] =3.63 + { IDE_ALTSTATUS, 0x50,3.64 + IDE_ERROR, 0x00,3.65 + IDE_COUNT, 0x03,3.66 + IDE_LBA1, 0x0C,3.67 + IDE_LBA2, 0,3.68 + IDE_DEVICE, 0,3.69 + IDE_STATUS, 0x50, 0, 0 };3.70 +3.71 +int send_packet_command( char *cmd )3.72 +{3.73 + unsigned short *spkt = (unsigned short *)cmd;3.74 + int i;3.75 +3.76 + EXPECT_READY();3.77 + byte_write( IDE_FEATURE, 0 );3.78 + byte_write( IDE_COUNT, 0 );3.79 + byte_write( IDE_LBA0, 0 );3.80 + byte_write( IDE_LBA1, 8 );3.81 + byte_write( IDE_LBA2, 0 );3.82 + byte_write( IDE_DEVICE, 0 );3.83 + byte_write( IDE_COMMAND, 0xA0 );3.84 + byte_read(IDE_ALTSTATUS); /* delay 1 PIO cycle */3.85 + EXPECT_READY(); /* Wait until device is ready to accept command (usually immediate) */3.86 + CHECK_INTRQ_CLEAR();3.87 + CHECK_REGS( post_packet_ready_regs );3.88 +3.89 + /* Write the command */3.90 + for( i=0; i<6; i++ ) {3.91 + word_write( IDE_DATA, spkt[i] );3.92 + }3.93 +3.94 + byte_read(IDE_ALTSTATUS);3.95 +3.96 + // CHECK_REGS( post_packet_cmd_regs );3.97 + EXPECT_INTRQ();3.98 + EXPECT_READY();3.99 + return 0;3.100 +}3.101 +3.102 +3.103 uint32_t abort_regs[] = {3.104 IDE_ALTSTATUS, 0x51,3.105 IDE_ERROR, 0x04,3.106 @@ -183,6 +272,18 @@3.107 return 0;3.108 }3.110 +3.111 +uint32_t drive_ready_regs[] = {3.112 + IDE_ALTSTATUS, 0x50,3.113 + IDE_ERROR, 0x00,3.114 + IDE_COUNT, 0x03,3.115 + IDE_LBA1, 0x08,3.116 + IDE_LBA2, 0x00,3.117 + IDE_DEVICE, 0,3.118 + IDE_DATA, 0xFFFF,3.119 + IDE_STATUS, 0x50,3.120 + 0, 0 };3.121 +3.122 /**3.123 * Test the reset command3.124 */3.125 @@ -211,69 +312,25 @@3.126 CHECK_INTRQ_CLEAR();3.127 CHECK_REGS( post_set_feature2_regs );3.129 + char test_ready_cmd[12] = { 0,0,0,0, 0,0,0,0, 0,0,0,0 };3.130 + if( send_packet_command(test_ready_cmd) != 0 ) {3.131 + return -1;3.132 + }3.133 +3.134 + CHECK_REGS( packet_cmd_error6_regs );3.135 + int sense = ide_get_sense_code();3.136 + CHECK_IEQUALS( 0x2906, sense );3.137 +3.138 + if( send_packet_command(test_ready_cmd) != 0 ) {3.139 + return -1;3.140 + }3.141 + CHECK_REGS( drive_ready_regs );3.142 return 0;3.143 }3.145 -uint32_t post_packet_ready_regs[] =3.146 - { IDE_ALTSTATUS, 0x58,3.147 - IDE_ERROR, 0x00,3.148 - IDE_COUNT, 0x01,3.149 - IDE_LBA0, 0x00,3.150 - IDE_LBA1, 8,3.151 - IDE_LBA2, 0,3.152 - IDE_DEVICE, 0,3.153 - IDE_STATUS, 0x58, 0, 0 };3.154 -3.155 -uint32_t post_packet_cmd_regs[] =3.156 - { IDE_ALTSTATUS, 0xD0,3.157 - IDE_ERROR, 0x00,3.158 - IDE_COUNT, 0x01,3.159 - IDE_LBA1, 8,3.160 - IDE_LBA2, 0,3.161 - IDE_DEVICE, 0,3.162 - IDE_STATUS, 0xD0, 0, 0 };3.163 -3.164 -uint32_t packet_cmd_error6_regs[] =3.165 - { IDE_ALTSTATUS, 0x51,3.166 - IDE_ERROR, 0x60,3.167 - IDE_COUNT, 0x03,3.168 - IDE_LBA1, 8,3.169 - IDE_LBA2, 0,3.170 - IDE_DEVICE, 0,3.171 - IDE_STATUS, 0x51, 0, 0 };3.172 -3.173 -uint32_t packet_data_ready_regs[] =3.174 - { IDE_ALTSTATUS, 0x58,3.175 - IDE_ERROR, 0x00,3.176 - IDE_COUNT, 0x02,3.177 - IDE_LBA0, 0x00,3.178 - IDE_LBA1, 0x0C,3.179 - IDE_LBA2, 0,3.180 - IDE_DEVICE, 0,3.181 - IDE_STATUS, 0x58, 0, 0 };3.182 -3.183 -3.184 -uint32_t post_packet_data_regs[] =3.185 - { IDE_ALTSTATUS, 0xD0,3.186 - IDE_ERROR, 0x00,3.187 - IDE_COUNT, 0x02,3.188 - IDE_LBA0, 0x00,3.189 - IDE_LBA1, 0x0C,3.190 - IDE_LBA2, 0,3.191 - IDE_DEVICE, 0,3.192 - IDE_STATUS, 0xD0, 0, 0 };3.193 -3.194 -uint32_t packet_complete_regs[] =3.195 - { IDE_ALTSTATUS, 0x50,3.196 - IDE_ERROR, 0x00,3.197 - IDE_COUNT, 0x03,3.198 - IDE_LBA1, 0x0C,3.199 - IDE_LBA2, 0,3.200 - IDE_DEVICE, 0,3.201 - IDE_STATUS, 0x50, 0, 0 };3.202 -3.203 char expect_ident[] = { 0x00, 0xb4, 0x19, 0x00,3.204 0x00, 0x08, 0x53, 0x45, 0x20, 0x20, 0x20, 0x20 };3.205 +3.206 /**3.207 * Test the PACKET command (using the Inquiry command)3.208 */3.209 @@ -282,35 +339,11 @@3.210 int i;3.211 char cmd[12] = { 0x11, 0, 4, 0, 12, 0, 0, 0, 0, 0, 0, 0 };3.212 // char cmd[12] = { 0x00,0,0,0, 0,0,0,0, 0,0,0,0 };3.213 - unsigned short *spkt = (unsigned short *)cmd;3.214 + unsigned short *spkt;3.215 char result[12];3.217 - ide_print_sense_error();3.218 - EXPECT_READY();3.219 - byte_write( IDE_FEATURE, 0 );3.220 - byte_write( IDE_COUNT, 0 );3.221 - byte_write( IDE_LBA0, 0 );3.222 - byte_write( IDE_LBA1, 8 );3.223 - byte_write( IDE_LBA2, 0 );3.224 - byte_write( IDE_DEVICE, 0 );3.225 - byte_write( IDE_COMMAND, 0xA0 );3.226 - byte_read(IDE_ALTSTATUS); /* delay 1 PIO cycle */3.227 - EXPECT_READY(); /* Wait until device is ready to accept command (usually immediate) */3.228 - CHECK_INTRQ_CLEAR();3.229 - CHECK_REGS( post_packet_ready_regs );3.230 -3.231 - /* Write the command */3.232 - for( i=0; i<6; i++ ) {3.233 - word_write( IDE_DATA, spkt[i] );3.234 - }3.235 -3.236 - byte_read(IDE_ALTSTATUS);3.237 -3.238 - CHECK_REGS( post_packet_cmd_regs );3.239 - EXPECT_INTRQ();3.240 - EXPECT_READY();3.241 + send_packet_command( cmd );3.242 CHECK_REGS( packet_data_ready_regs );3.243 -3.244 spkt = (unsigned short *)result;3.245 *spkt++ = word_read(IDE_DATA);3.246 *spkt++ = word_read(IDE_DATA);3.247 @@ -321,8 +354,9 @@3.248 *spkt++ = word_read(IDE_DATA);3.249 CHECK_REGS( post_packet_data_regs );3.250 EXPECT_READY();3.251 - CHECK_INTRQ_CLEAR();3.252 + EXPECT_INTRQ();3.253 CHECK_REGS( packet_complete_regs );3.254 +3.255 if( memcmp( result, expect_ident, 12 ) != 0 ) {3.256 fwrite_diff( stderr, expect_ident, 12, result, 12 );3.257 }3.258 @@ -355,7 +389,7 @@3.260 typedef int (*test_func_t)();3.262 -test_func_t test_fns[] = { test_packet, test_enable, test_reset,3.263 +test_func_t test_fns[] = { test_enable, test_reset, test_packet,3.264 test_dma, test_dma_abort, NULL };3.266 int main()
.