Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-----------------------------------------------------------------------*/
- /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2016 */
- /*-----------------------------------------------------------------------*/
- /* If a working storage control module is available, it should be */
- /* attached to the FatFs via a glue function rather than modifying it. */
- /* This is an example of glue functions to attach various exsisting */
- /* storage control modules to the FatFs module with a defined API. */
- /*-----------------------------------------------------------------------*/
- #include "fatfs/ff.h" /* Obtains integer types */
- #include "fatfs/diskio.h" /* Declarations of disk functions */
- #include <Intrz80.h>
- #include <oscalls.h>
- // RESERV RESERV DEV_ATMIDE DEV_DIVIDE
- DSTATUS disks_stat[4]={STA_NOINIT, STA_NOINIT, STA_NOINIT, STA_NOINIT};
- extern unsigned char tmpbuf[512];
- #define IDE_MASTER 0xe0
- #define IDE_SLAVE 0xf0
- #define NEMO_DATA 0x10
- #define NEMO_COUNT 0x50
- #define NEMO_LBA0 0x70
- #define NEMO_LBA1 0x90
- #define NEMO_LBA2 0xB0
- #define NEMO_LBA3 0xD0
- #define NEMO_MS 0xD0
- #define NEMO_CMD 0xF0
- #define NEMO_STAT 0xF0
- #define ATM_DATA_LOW 0x000f
- #define ATM_DATA_HI 0x010f
- #define ATM_COUNT 0x004f
- #define ATM_LBA0 0x006f
- #define ATM_LBA1 0x008f
- #define ATM_LBA2 0x00af
- #define ATM_LBA3 0x00cf
- #define ATM_MS 0x00cf
- #define ATM_CMD 0x00ef
- #define ATM_STAT 0x00ef
- #define ATA_STAT_ERR 0x01
- #define ATA_STAT_IDX 0x02
- #define ATA_STAT_CORR 0x04
- #define ATA_STAT_DRQ 0x08
- #define ATA_STAT_DSC 0x10
- #define ATA_STAT_DWF 0x20
- #define ATA_STAT_DRDY 0x40
- #define ATA_STAT_BSY 0x80
- #define ATA_CMD_READ_SECTORS 0x20
- #define ATA_CMD_WRITE_SECTORS 0x30
- #define ATA_CMD_INIT_DRIVE_PARAM 0x91
- #define ATA_CMD_IDENTIFY_DRIVE 0xec
- /*-----------------------------------------------------------------------*/
- /* Get Drive Status */
- /*-----------------------------------------------------------------------*/
- DSTATUS disk_status (
- BYTE pdrv /* Physical drive nmuber to identify the drive */
- )
- {
- return disks_stat[pdrv];
- }
- /*-----------------------------------------------------------------------*/
- /* Inidialize a Drive */
- /*-----------------------------------------------------------------------*/
- DSTATUS disk_initialize (
- BYTE pdrv /* Physical drive nmuber to identify the drive */
- )
- {
- unsigned int i = 26;
- unsigned char d;
- if(disks_stat[pdrv] == RES_OK) return RES_OK;
- if(DEV_NEMO_M == (pdrv & 0xfe)){
- output8(NEMO_MS, (pdrv & 0x01) ? IDE_SLAVE : IDE_MASTER);
- while(--i){
- YIELD();
- d=input8(NEMO_STAT);
- if((d & ATA_STAT_BSY) == 0x00) break;
- }
- if(i == 0x00) return STA_NODISK;
- if(d == 0x00) return STA_NODISK;
- //if(d == 0xff) return STA_NODISK;
- output8(NEMO_LBA2, 0x00);
- output8(NEMO_LBA1, 0x00);
- output8(NEMO_CMD, ATA_CMD_IDENTIFY_DRIVE);
- while(1){
- d = input8(NEMO_STAT);
- if(d == 0x00 || d == 0xff) return STA_NODISK;
- if(d & ATA_STAT_ERR) break;
- if((d & (ATA_STAT_BSY | ATA_STAT_DRQ)) == ATA_STAT_DRQ) break;
- }
- if(input8(NEMO_LBA2) | input8(NEMO_LBA1)) return STA_NODISK; //is CD-ROM
- input_block_inc(NEMO_DATA, tmpbuf, 256);
- input_block_inc(NEMO_DATA, tmpbuf+256, 256);
- if((tmpbuf[49*2+1] & 0x02) == 0x00) return STA_NODISK; //no LBA
- // \/Number of sectors per track
- output8(NEMO_COUNT,tmpbuf[12]);
- d = (tmpbuf[6] - 1) | IDE_MASTER;
- if(pdrv & 0x01) d |= DEV_MS_BIT;
- output8(NEMO_MS,tmpbuf[6]);
- output8(NEMO_CMD, ATA_CMD_INIT_DRIVE_PARAM);
- i = 1000;
- while(--i){
- if(input8(NEMO_STAT) & ATA_STAT_BSY) continue;
- disks_stat[pdrv] = RES_OK;
- break;
- }
- }else if(DEV_ATM_M == (pdrv & 0xfe)){
- output(ATM_MS, (pdrv & 0x01) ? IDE_SLAVE : IDE_MASTER);
- while(--i){
- YIELD();
- d=input(ATM_STAT);
- if((d & ATA_STAT_BSY) == 0x00) break;
- }
- if(i == 0x00) return STA_NODISK;
- if(d == 0x00) return STA_NODISK;
- //if(d == 0xff) return STA_NODISK;
- output(ATM_LBA2, 0x00);
- output(ATM_LBA1, 0x00);
- output(ATM_CMD, ATA_CMD_IDENTIFY_DRIVE);
- while(1){
- d = input(ATM_STAT);
- if(d == 0x00 || d == 0xff) return STA_NODISK;
- if(d & ATA_STAT_ERR) break;
- if((d & (ATA_STAT_BSY | ATA_STAT_DRQ)) == ATA_STAT_DRQ) break;
- }
- if(input(ATM_LBA2) | input(ATM_LBA1)) return STA_NODISK; //is CD-ROM
- input_block_inc(ATM_DATA_LOW, tmpbuf, 256);
- input_block_inc(ATM_DATA_LOW, tmpbuf+256, 256);
- if((tmpbuf[49*2+1] & 0x02) == 0x00) return STA_NODISK; //no LBA
- // \/Number of sectors per track
- output(ATM_COUNT,tmpbuf[12]);
- d = (tmpbuf[6] - 1) | IDE_MASTER;
- if(pdrv & 0x01) d |= DEV_MS_BIT;
- output(ATM_MS,tmpbuf[6]);
- output(ATM_CMD, ATA_CMD_INIT_DRIVE_PARAM);
- i = 1000;
- while(--i){
- if(input(ATM_STAT) & ATA_STAT_BSY) continue;
- disks_stat[pdrv] = RES_OK;
- break;
- }
- }
- return disks_stat[pdrv];
- }
- /*-----------------------------------------------------------------------*/
- /* Read Sector(s) */
- /*-----------------------------------------------------------------------*/
- DRESULT disk_read (
- BYTE pdrv, /* Physical drive nmuber to identify the drive */
- BYTE *buff, /* Data buffer to store read data */
- DWORD sector, /* Start sector in LBA */
- UINT count /* Number of sectors to read */
- )
- {
- unsigned char c = count;
- if(DEV_NEMO_M == (pdrv & 0xfe)){
- if(pdrv & 0x01)
- output8(NEMO_LBA3,((unsigned char*)§or)[3] | IDE_SLAVE);
- else
- output8(NEMO_LBA3,((unsigned char*)§or)[3] | IDE_MASTER);
- while((input8(NEMO_STAT) & ATA_STAT_BSY) != 0);
- output8(NEMO_LBA2,((unsigned char*)§or)[2]);
- output8(NEMO_LBA1,((unsigned char*)§or)[1]);
- output8(NEMO_LBA0,((unsigned char*)§or)[0]);
- output8(NEMO_COUNT,c);
- output8(NEMO_CMD, ATA_CMD_READ_SECTORS);
- while((input8(NEMO_STAT) & (ATA_STAT_BSY | ATA_STAT_DRQ)) != 8);
- while(c--){
- //unsigned int i = 512;
- input_block_inc(NEMO_DATA, buff, 256);
- buff += 256;
- input_block_inc(NEMO_DATA, buff, 256);
- buff += 256;
- //while(i--){
- // *buff = input8(NEMO_DATA);
- // buff++;
- //}
- while((input8(NEMO_STAT) & ATA_STAT_BSY) != 0);
- }
- return RES_OK;
- }else if(DEV_ATM_M == (pdrv & 0xfe)){
- if(pdrv & 0x01)
- output(ATM_LBA3,((unsigned char*)§or)[3] | IDE_SLAVE);
- else
- output(ATM_LBA3,((unsigned char*)§or)[3] | IDE_MASTER);
- while((input(ATM_STAT) & ATA_STAT_BSY) != 0);
- output(ATM_LBA2,((unsigned char*)§or)[2]);
- output(ATM_LBA1,((unsigned char*)§or)[1]);
- output(ATM_LBA0,((unsigned char*)§or)[0]);
- output(ATM_COUNT,c);
- output(ATM_CMD, ATA_CMD_READ_SECTORS);
- while((input(ATM_STAT) & (ATA_STAT_BSY | ATA_STAT_DRQ)) != 8);
- while(c--){
- //unsigned int i = 512;
- input_block_inc(ATM_DATA_LOW, buff, 256);
- buff += 256;
- input_block_inc(ATM_DATA_LOW, buff, 256);
- buff += 256;
- //while(i--){
- // *buff = input8(NEMO_DATA);
- // buff++;
- //}
- while((input(ATM_STAT) & ATA_STAT_BSY) != 0);
- }
- return RES_OK;
- }
- return RES_PARERR;
- }
- /*-----------------------------------------------------------------------*/
- /* Write Sector(s) */
- /*-----------------------------------------------------------------------*/
- #if FF_FS_READONLY == 0
- DRESULT disk_write (
- BYTE pdrv, /* Physical drive nmuber to identify the drive */
- const BYTE *buff, /* Data to be written */
- DWORD sector, /* Start sector in LBA */
- UINT count /* Number of sectors to write */
- )
- {
- unsigned char c = count;
- if(DEV_NEMO_M == (pdrv & 0xfe)){
- if(pdrv & 0x01)
- output8(NEMO_LBA3,((unsigned char*)§or)[3] | IDE_SLAVE);
- else
- output8(NEMO_LBA3,((unsigned char*)§or)[3] | IDE_MASTER);
- while((input8(NEMO_STAT) & ATA_STAT_BSY) != 0);
- output8(NEMO_LBA2,((unsigned char*)§or)[2]);
- output8(NEMO_LBA1,((unsigned char*)§or)[1]);
- output8(NEMO_LBA0,((unsigned char*)§or)[0]);
- output8(NEMO_COUNT,c);
- output8(NEMO_CMD, ATA_CMD_WRITE_SECTORS);
- while((input8(NEMO_STAT) & (ATA_STAT_BSY | ATA_STAT_DRQ)) != 8);
- while(c--){
- output_block_inc(NEMO_DATA, (void*)buff, 256);
- buff += 256;
- output_block_inc(NEMO_DATA, (void*)buff, 256);
- buff += 256;
- /*
- unsigned int i = 512;
- while(i--){
- output8(NEMO_DATA,*buff);
- buff++;
- }
- */
- while((input8(NEMO_STAT) & ATA_STAT_BSY) != 0);
- }
- return RES_OK;
- }else if(DEV_ATM_M == (pdrv & 0xfe)){
- if(pdrv & 0x01)
- output(ATM_LBA3,((unsigned char*)§or)[3] | IDE_SLAVE);
- else
- output(ATM_LBA3,((unsigned char*)§or)[3] | IDE_MASTER);
- while((input(ATM_STAT) & ATA_STAT_BSY) != 0);
- output(ATM_LBA2,((unsigned char*)§or)[2]);
- output(ATM_LBA1,((unsigned char*)§or)[1]);
- output(ATM_LBA0,((unsigned char*)§or)[0]);
- output(ATM_COUNT,c);
- output(ATM_CMD, ATA_CMD_WRITE_SECTORS);
- while((input(ATM_STAT) & (ATA_STAT_BSY | ATA_STAT_DRQ)) != 8);
- while(c--){
- BYTE * i = (BYTE *)buff + 512;
- while(buff != i){
- output(ATM_DATA_HI, buff[1]);
- output(ATM_DATA_LOW, buff[0]);
- buff += 2;
- }
- while((input(ATM_STAT) & ATA_STAT_BSY) != 0);
- }
- return RES_OK;
- }
- return RES_PARERR;
- }
- #endif
- /*-----------------------------------------------------------------------*/
- /* Miscellaneous Functions */
- /*-----------------------------------------------------------------------*/
- DRESULT disk_ioctl (
- BYTE pdrv, /* Physical drive nmuber (0..) */
- BYTE cmd, /* Control code */
- void *buff /* Buffer to send/receive control data */
- )
- {
- if((pdrv == DEV_NEMO_M) && (cmd == GET_SECTOR_COUNT)){
- if(pdrv == DEV_NEMO_M){
- output8(NEMO_LBA3,0xe0);
- output8(NEMO_CMD, ATA_CMD_IDENTIFY_DRIVE);
- while((input8(NEMO_STAT) & (ATA_STAT_BSY | ATA_STAT_DRQ)) != 8);
- input_block_inc(NEMO_DATA, tmpbuf, 256);
- input_block_inc(NEMO_DATA, tmpbuf+256, 256);
- while((input8(NEMO_STAT) & ATA_STAT_BSY) != 0);
- *((unsigned long*)buff)=*((unsigned long*)(tmpbuf+120));
- return RES_OK;
- }else if(pdrv == DEV_ATM_M){
- BYTE * i = (BYTE *)tmpbuf;
- output(ATM_LBA3,0xe0);
- output(ATM_CMD, ATA_CMD_IDENTIFY_DRIVE);
- while((input(ATM_STAT) & (ATA_STAT_BSY | ATA_STAT_DRQ)) != 8);
- {
- while((tmpbuf+512) != i){
- output(ATM_DATA_HI, i[1]);
- output(ATM_DATA_LOW, i[0]);
- i += 2;
- }
- }
- while((input(ATM_STAT) & ATA_STAT_BSY) != 0);
- *((unsigned long*)buff)=*((unsigned long*)(i+120));
- return RES_OK;
- }
- return RES_PARERR;
- }else if(CTRL_SYNC == cmd){
- return RES_OK;
- }
- return RES_PARERR;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement