Example #1
0
uint8_t ATA_PIO_Identify(uint16_t *result)
{
    //Check if the bus even exists
    if(inb(CMD_REG_STATUS_PORT(curBase)) == 0xFF)return -1;	//The bus doesn't exist

    //IDENTIFY the disk
    outb(SECTOR_COUNT_PORT(curBase), 0);

    //Higher bytes first!
    outb(LBA_HI_PORT(curBase), 0);
    outb(LBA_MID_PORT(curBase), 0);
    outb(LBA_LO_PORT(curBase), 0);

    outb(CMD_REG_STATUS_PORT(curBase), IDENTIFY_DRIVE_CMD);

    uint8_t status = ATA_PIO_ReadStatus(TRUE);
    if(status == 0)return -1;
    while(status & STATUS_BUSY != STATUS_BUSY)status = ATA_PIO_ReadStatus(TRUE);	//Keep polling until the busy bit clears

    uint8_t lba_mid = inb(LBA_MID_PORT(curBase));
    uint8_t lba_hi = inb(LBA_HI_PORT(curBase));

    if(lba_mid != 0 | lba_hi != 0)return -1;

    while(1)
    {
        status = ATA_PIO_ReadStatus(TRUE);
        if(status & STATUS_DRQ == STATUS_DRQ)break;
        if(status & STATUS_ERR == STATUS_ERR)return -1;
    }

    //Read in 256 words and store them into the provided pointer
    for(int i = 0; i < 256; i++)
    {
        result[i] = inl(DATA_PORT(curBase));
    }

    return 0;
}
Example #2
0
//This function writes data on the LCD display
void LCD_Data(unsigned int data){
	unsigned int temp=0;
	EN_LOW();
	DATA_PORT();
	WRITE_DATA();

	temp=data;
	IO1PIN&=0xFC3FFFFF;
	IO1PIN|=(temp & 0xF0) << 18;

	EN_HI();
	DelaymSec(1);
	EN_LOW();

	temp=data & 0x0F;

	IO1PIN&=0xFC3FFFFF;
	IO1PIN|=(temp) << 22;

	EN_HI();
	DelaymSec(1);
	EN_LOW();
}