Skip to content

Instantly share code, notes, and snippets.

@jmgrosen
Created October 22, 2012 14:02
Show Gist options
  • Select an option

  • Save jmgrosen/3931647 to your computer and use it in GitHub Desktop.

Select an option

Save jmgrosen/3931647 to your computer and use it in GitHub Desktop.
Help?

I can't figure out why this gives errors... Code:

/*-----------------------------------------------------------------------*/
/* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2012        */
/*-----------------------------------------------------------------------*/
/* 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 module to the FatFs module with a defined API.        */
/*-----------------------------------------------------------------------*/

#include "diskio.h"		/* FatFs lower layer API */

#define STATE_NO_MEDIA 0x0000
#define STATE_READY    0x0001
#define STATE_READY_WP 0x0002

/*-----------------------------------------------------------------------*/
/* Inidialize a Drive                                                    */
/*-----------------------------------------------------------------------*/

DSTATUS disk_initialize (
                         BYTE drv				/* Physical drive nmuber (0..) */
                         )
{
  return disk_status(drv);
}



/*-----------------------------------------------------------------------*/
/* Get Disk Status                                                       */
/*-----------------------------------------------------------------------*/

DSTATUS disk_status (
                     BYTE drv		/* Physical drive nmuber (0..) */
                     )
{
  DSTATUS stat;
  char raw;

  asm ("SET A, 0\n\t"
       "HWI 3"
       : "=B" (raw)
       :
       : "A", "C");

  switch(raw) {
  case STATE_NO_MEDIA:
    return STA_NODISK;
  case STATE_READY_WP:
    return STA_PROTECT;
  default:
    return 0;
  }
}



/*-----------------------------------------------------------------------*/
/* Read Sector(s)                                                        */
/*-----------------------------------------------------------------------*/

DRESULT disk_read (
                   BYTE drv,		/* Physical drive nmuber (0..) */
                   BYTE *buff,		/* Data buffer to store read data */
                   DWORD sector,	/* Sector address (LBA) */
                   BYTE count		/* Number of sectors to read (1..128) */
                   )
{
  char error;
  DWORD initial_sector = sector;

  if (sector + count > 1440) {
    return RES_PARERR;
  }

  for (sector = initial_sector; sector < initial_sector + count; sector++) {
    asm("SET A, 2\n\t"
        "HWI 3\n\t"
        "IFN B, 1\n\t"
        "\tSET PC, disk_read_end\n\t"
        "SET A, 0\n\t"
        ":disk_read_loop\n\t"
        "HWI 3\n\t"
        "IFN C, 1\n\t"
        "\tSET PC, disk_read_end\n\t"
        "SET PC, disk_read_loop"
        ":disk_read_end"
        : "=C" (error)
        : "X" (sector), "Y" (buff)
        : "A");
    if (error != 0) {
      return RES_ERROR;
    }
    buff += sizeof(BYTE);
  }

  return RES_OK;
}



/*-----------------------------------------------------------------------*/
/* Write Sector(s)                                                       */
/*-----------------------------------------------------------------------*/

#if _USE_WRITE
DRESULT disk_write (
                    BYTE drv,			/* Physical drive nmuber (0..) */
                    const BYTE *buff,	/* Data to be written */
                    DWORD sector,		/* Sector address (LBA) */
                    BYTE count			/* Number of sectors to write (1..128) */
                    )
{
  char error;
  DWORD initial_sector = sector;

  if (sector + count > 1440) {
    return RES_PARERR;
  }

  for (sector = initial_sector; sector < initial_sector + count; sector++) {
    asm("SET A, 3\n\t"
        "HWI 3\n\t"
        "IFN B, 1\n\t"
        "\tSET PC, disk_read_end\n\t"
        "SET A, 0\n\t"
        ":disk_read_loop\n\t"
        "HWI 3\n\t"
        "IFN C, 1\n\t"
        "\tSET PC, disk_read_end\n\t"
        "SET PC, disk_read_loop"
        ":disk_read_end"
        : "=C" (error)
        : "X" (sector), "Y" (buff)
        : "A");
    if (error != 0) {
      return RES_ERROR;
    }
    buff += sizeof(BYTE);
  }

  return RES_OK;
}
#endif


/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions                                               */
/*-----------------------------------------------------------------------*/

#if _USE_IOCTL
DRESULT disk_ioctl (
                    BYTE drv,		/* Physical drive nmuber (0..) */
                    BYTE ctrl,		/* Control code */
                    void *buff		/* Buffer to send/receive control data */
                    )
{
  
  if (ctrl == GET_SECTOR_COUNT) {
    *((int*) buff) = 1440;
  }
  return RES_PARERR;
}
#endif

Error:

diskio.c:42:10: error: invalid output constraint '=B' in asm
       : "=B" (raw)
         ^
diskio.c:88:11: error: invalid output constraint '=C' in asm
        : "=C" (error)
          ^
diskio.c:133:11: error: invalid output constraint '=C' in asm
        : "=C" (error)
          ^
3 errors generated.

===HELP!===

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment