// Coldfire Initial C Source File #include "xstdsys.h" #define SECTOR_SIZE 512 #define SECTORS_NUMBER 22 #define CYLINDERS_NUMBER 1011 #define HEADS_NUMBER 15 // registradores para selecao de chip select 2 unsigned int *CSAR2 = (unsigned int *)(MBAR + 0x98); unsigned int *CSMR2 = (unsigned int *)(MBAR + 0x9c); unsigned short *CSCR2 = (unsigned short *)(MBAR + 0xa2); // registradores para configuracao de IDE unsigned int *IDECONFIG1 = (unsigned int *)(MBAR2 + 0x18c); unsigned int *IDECONFIG2 = (unsigned int *)(MBAR2 + 0x190); unsigned int *GPIOFUNCTION = (unsigned int *)(MBAR2 + 0x00c); unsigned int *GPIOEN = (unsigned int *)(MBAR2 + 0x008); unsigned int *GPIOOUT = (unsigned int *)(MBAR2 + 0x004); // IDE data register unsigned short *IDE_DR; // IDE command and status register unsigned short *IDE_CSR; // IDE sector count unsigned short *IDE_SC; // IDE start sector unsigned short *IDE_SS; // IDE cylinder low bits unsigned short *IDE_CL; // IDE cylinder high bits unsigned short *IDE_CH; // IDE head/device unsigned short *IDE_HD; // IDE error unsigned short *IDE_ER; // IDE interrupt status register unsigned short *IDE_ISR; // registradores da serial unsigned char *umr1 = (unsigned char *)(MBAR + 0x200); unsigned char *usr1 = (unsigned char *)(MBAR + 0x204); // Leitura unsigned char *ucsr1 = (unsigned char *)(MBAR + 0x204); // Escrita unsigned char *ubg1 = (unsigned char *)(MBAR + 0x218); unsigned char *ubg2 = (unsigned char *)(MBAR + 0x21c); unsigned char *urb1 = (unsigned char *)(MBAR + 0x20c); // Receber unsigned char *utb1 = (unsigned char *)(MBAR + 0x20c); // Transmitir void configSerial() { // configura a serial para 9600bps *umr1 = 0x13; // *umr1 = 0xC7; // Remote loopback *umr1 = 0x07; // Normal *ucsr1 = 0xDD; *ubg1 = 0x00; // Divisor de freqüencia = + Sig *ubg2 = 0xD4; // Divisor de freqüencia = - Sig } /* * Aguarda ate que o bit DRQ fique alto * indicando que IDE_DR pode ser lido ou * gravado. */ void waitForDRQ() { // wait for DRQ (bit 3) 0000 1000 while ( ! ((*IDE_ISR) & 0x0008) ); } /* * Aguarda ate que o bit RDY fique alto * indicando que a inicializacao do disco * foi completada. */ void waitForRDY() { // wait for RDY (bit 6) 0100 0000 = 64 = 0x0040 while ( ! ((*IDE_ISR) & 0x0040) ); } void setupIDE() { /* Registradores do ColdFire */ // alocar memoria para periferico // e configurar forma de funcionamento *CSAR2 = 0x50000000; *CSMR2 = 0x00000001; *CSCR2 = 0x0080; *IDECONFIG1 = 0x00107000; *IDECONFIG2 = 0x000C0800; // Resetar o disco para permitir leitura/escrita // 00080000h - 00000000000010000000000000000000b *GPIOFUNCTION |= 0x00080000; *GPIOEN |= 0x00080000; *GPIOOUT |= 0x00080000; /* Registradores da IDE */ // IDE data register IDE_DR = (unsigned short *)(*CSAR2 + 0x20); // IDE command and status register IDE_CSR = (unsigned short *)(*CSAR2 + 0x2E); // IDE sector count IDE_SC = (unsigned short *)(*CSAR2 + 0x24); // IDE start sector IDE_SS = (unsigned short *)(*CSAR2 + 0x26); // IDE cylinder low bits IDE_CL = (unsigned short *)(*CSAR2 + 0x28); // IDE cylinder high bits IDE_CH = (unsigned short *)(*CSAR2 + 0x2A); // IDE head/device IDE_HD = (unsigned short *)(*CSAR2 + 0x2C); // IDE error IDE_ER = (unsigned short *)(*CSAR2 + 0x22); // IDE interrupt and status register IDE_ISR = (unsigned short *)(*CSAR2 + 0x1C); waitForRDY(); } /* * * cyl - 10bits, sendo 8 da parte baixa e 2 na parte alta, * totalizando um maximo de 1024 cilindros. * hd - 8bits, sendo * 0..3: numero da cabeca * 4 : master (0) ou slave (1) * 5..7: fixo em 101 * sec - 8bits, sendo 0x01 o primeiro, 0x02 o segundo, etc e * 0x00 o último (256). */ void setPosition(unsigned char hd, unsigned short cyl, unsigned char sec) { /* Pegar somente parte baixa do cilindro 0000 0010 1010 1110 00FF 0000 0000 1111 1111 0000 0000 1010 1110 Pegar somente parte alta do cilindro 0000 0010 1010 1110 FF00 1111 1111 0000 0000 0000 0010 0000 0000 Deslocar 8 bits para direita */ // pegar parte baixa do cilindro *IDE_CL = (unsigned short)(cyl & 0x00FF); // IDE cylinder high bits *IDE_CH = (unsigned short)((cyl & 0xFF00) >> 8); // IDE head/device *IDE_HD = (unsigned short)(0xA0 + hd); // ler um setor por vez *IDE_SC = 0x01; // IDE start sector *IDE_SS = (unsigned short)(sec+1); //waitForRDY(); } unsigned char getByte(unsigned int offset) { unsigned char hd = 0; unsigned short cyl = 0; unsigned char sec = 0; unsigned int pos; int i; unsigned short buff; unsigned char ret; while ( offset >= SECTOR_SIZE ) { sec++; if ( sec >= SECTORS_NUMBER ) { sec = 0; cyl++; if ( cyl >= CYLINDERS_NUMBER ) { cyl = 0; hd++; } } offset -= SECTOR_SIZE; } setPosition(hd,cyl,sec); // comando de leitura *IDE_CSR = 0x0020; // aguardar ate que o data esteja ok waitForDRQ(); if ( offset % 2 != 0 ) { pos = offset + 1; } else { pos = offset + 2; } pos /= 2; for ( i=0; i> 8); } return ret; } /* DEPRECATED */ procuraArq() { unsigned short i; unsigned short c; unsigned char buff[512]; for (i=0; i<256; i++ ) { c = *IDE_DR; buff[i*2] = (char)(c & 0x00FF); buff[i*2+1] = (char)((c & 0xFF00) >> 8); } } void enviaSerial(unsigned char ch) { while ( ! ((*usr1) & 0x04) ); *utb1 = ch; } main() { unsigned char ch; unsigned int pos = 0; configSerial(); setupIDE(); /* for ( pos=623104; pos<623104+(512*5); pos++ ) { //b[pos-623104] = getByte(pos); enviaSerial(getByte(pos)); } */ int i=0; for ( pos=40960*12; pos<40960*20; pos++ ) { ch = getByte(pos); if ( (ch >= ' ' && ch <= '~') ) { enviaSerial(ch); } //else { // enviaSerial('.'); //} } /* setPosition(0, 55, 7); // comando de leitura *IDE_CSR = 0x0020; // aguardar ate que o data esteja ok waitForDRQ(); // Aqui o dado está em IDE_DR procuraArq(); */ //pos = 0+1; // leitura das informacoes // do disco // *IDE_CSR = 0xEC; // waitForDRQ(); /* for ( unsigned char hd=0; hd<15; hd++ ) { for ( unsigned short cyl=0; cyl<1011; cyl++ ) { for ( unsigned char sec=0; sec<22; sec++ ) { waitForRDY(); // leitura de uma posicao do disco setPosition(cyl, hd, sec); // comando de leitura *IDE_CSR = 0x0020; // aguardar ate que o data esteja ok waitForDRQ(); // Aqui o dado está em IDE_DR procuraArq(); } } } */ // 0000 1000 = 0x08 //*IDE_CR = 0x08; // avisa IDE que fara escrita while ( 1 ); }