??? 05/16/06 14:18 Read: times |
#116304 - atapi |
Hi, I'm interfacing a microcontroller with an ATAPI-cdrom through some transceivers (74HC245). When I issue a 'normal' ATA-command, all goes well. But from the moment I try to issue a packet command, nothing happens. The commands I want to use are basic: eject, play audio, pause etc...
I don't know what the problem is, as other simple non-packet commands work. I've seen the atapi-example on this site, but I don't see what I'm doing wrong. Does anyone know what kind of mistake I make? I use C to program: /* Ports: Port 0 : data LSB db0 - 7 Port 2 : data MSB db8 - 15 Port 1 : command lines : A0, A1, A2: 0,1,2 /iow : 3 /ior : 4 direction transceivers at P0 & P2 : 5 CS1Fx: 7 Port 3 has some led's attached */ #include<at89c5131.h> #include<intrins.h> #define cs P1_7 #define dir P1_5 #define ior P1_4 #define iow P1_3 void wacht(){ unsigned int i; for(i=0;i<10;i++){ // 3,75 µsec delay _nop_(); } } void wacht_pakket(){ unsigned int j; for(j=0;j<300;j++){ _nop_(); } } unsigned char read_status(){ unsigned char c; P1=0x9F; //address 1F7,dir==>>mcu dir=0; // dir ==>> mcu _nop_(); cs=0; _nop_(); ior=0; wacht(); c=P0; _nop_(); ior=1; cs=1; dir=1; _nop_(); return c; } void check_status(){ // checks BSY-flag unsigned char c; unsigned char d; unsigned char e; e=0x80; do{ _nop_(); _nop_(); _nop_(); _nop_(); c=read_status(); d=0x80; d=(d & c); }while(e == d); //as long as bsy-flag = 1 } void select_master(){ _nop_(); check_status(); P0=0xA0; // master selected P1=0xBE; // address 1F6 & dir ==>>cdrom dir=1; cs=0; _nop_(); _nop_(); iow=0; // write wacht(); iow=1; cs=1; wacht(); check_status(); _nop_(); } void set_cylH(){ P1=0xBD; //address 1F5,dir ==>>cdrom dir=1; _nop_(); cs=0; _nop_(); iow=0; wacht(); iow=1; cs=1; _nop_(); } void set_cylL(){ P1=0xBC; //address 1F4,dir ==>>cdrom dir=1; _nop_(); cs=0; _nop_(); iow=0; wacht(); iow=1; cs=1; _nop_(); } void set_Byte_count_packet(){ P0=0x00; set_cylH(); P0=0x0C; set_cylL(); } void set_cmdreg(){ P1=0xBF; // address 1F7, ior=1, iow=1, dir=1, cs=1 _nop_(); cs=0; _nop_(); iow=0; wacht(); iow=1; cs=1; _nop_(); } void set_feature_for_pack(){ _nop_(); P0=0x02; // overlap: yes ; DMA: no P1=0xB9; // address 1F1 ; dir==>>cdrom _nop_(); cs=0; _nop_(); iow=0; wacht_pakket(); iow=1; cs=1; _nop_(); check_status(); _nop_(); } void do_packet(){ select_master(); check_status(); _nop_(); set_feature_for_pack(); set_Byte_count_packet(); _nop_(); P0=0xA0; set_cmdreg(); check_status(); _nop_(); } void eject_tray(){ unsigned char c; unsigned char d; unsigned char e; _nop_(); check_status(); do_packet(); _nop_(); P3_3=1; P3_6=1; P3_5=1; //c=read_status(); dir=1; P3_7=0; // LED on P2=0xFF; P0=0x1B; _nop_(); P1=0xB8; //address 1F0 _nop_(); cs=0; _nop_(); iow=0; // 1st word wacht_pakket(); iow=1; cs=1; P0=0x00; cs=0; _nop_(); iow=0; // 2nd word wacht_pakket(); iow=1; cs=1; P0=0x02; cs=0; wacht_pakket(); iow=0; // 3rd word wacht_pakket(); iow=1; cs=1; _nop_(); // all other words are reserved cs=0; P0=0x00; iow=0; // 4th word wacht_pakket(); iow=1; cs=1; _nop_(); cs=0; wacht_pakket(); iow=0; // 5th word wacht_pakket(); iow=1; cs=1; _nop_(); cs=0; _nop_(); iow=0; // 6th word wacht_pakket(); iow=1; cs=1; P2=0xAA; P0=0xAA; wacht(); check_status(); c=read_status(); e=0xFF; d=0xF7; d=(c | d); if(e!=d){P3_5=0;} //different = OK! _nop_(); } |
Topic | Author | Date |
atapi | 01/01/70 00:00 | |
a guess and a suggestion![]() | 01/01/70 00:00 |