summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLeo C2014-11-22 13:07:04 +0100
committerLeo C2014-11-22 13:07:04 +0100
commit7f552300815ccadd45ebb3e7f0ae72a3b2e0c4e5 (patch)
tree1bb9ac83ce7fb1f6a99c6dd3445b2758330dcc95 /include
parent05994bd90cb36f10ff72c6a70d7cecc61b67fb2f (diff)
downloadz180-stamp-7f552300815ccadd45ebb3e7f0ae72a3b2e0c4e5.zip
Integrate fatfs. Add some sd card test commands.
Diffstat (limited to 'include')
-rw-r--r--include/avr/ffconf.h25
-rw-r--r--include/diskio.h86
-rw-r--r--include/ff.h2
-rw-r--r--include/integer.h26
-rw-r--r--include/spi.h54
5 files changed, 193 insertions, 0 deletions
diff --git a/include/avr/ffconf.h b/include/avr/ffconf.h
new file mode 100644
index 0000000..88c53d1
--- /dev/null
+++ b/include/avr/ffconf.h
@@ -0,0 +1,25 @@
+
+#undef _WORD_ACCESS
+
+#define _WORD_ACCESS 0 /* 0 or 1 */
+/* The _WORD_ACCESS option is an only platform dependent option. It defines
+/ which access method is used to the word data on the FAT volume.
+/
+/ 0: Byte-by-byte access. Always compatible with all platforms.
+/ 1: Word access. Do not choose this unless under both the following conditions.
+/
+/ * Address misaligned memory access is always allowed to ALL instructions.
+/ * Byte order on the memory is little-endian.
+/
+/ If it is the case, _WORD_ACCESS can also be set to 1 to reduce code size.
+/ Following table shows allowable settings of some processor types.
+/
+/ ARM7TDMI 0 ColdFire 0 V850E 0
+/ Cortex-M3 0 Z80 0/1 V850ES 0/1
+/ Cortex-M0 0 x86 0/1 TLCS-870 0/1
+/ AVR 0/1 RX600(LE) 0/1 TLCS-900 0/1
+/ AVR32 0 RL78 0 R32C 0
+/ PIC18 0/1 SH-2 0 M16C 0/1
+/ PIC24 0 H8S 0 MSP430 0
+/ PIC32 0 H8/300H 0 8051 0/1
+*/
diff --git a/include/diskio.h b/include/diskio.h
new file mode 100644
index 0000000..f5ba3e0
--- /dev/null
+++ b/include/diskio.h
@@ -0,0 +1,86 @@
+/*-----------------------------------------------------------------------
+/ Low level disk interface modlue include file R0.07 (C)ChaN, 2009
+/-----------------------------------------------------------------------*/
+
+#ifndef _DISKIO_H
+#define _DISKIO_H
+
+#define _USE_WRITE 1 /* 1: Enable disk_write function */
+#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */
+
+#include "integer.h"
+
+
+/* Status of Disk Functions */
+typedef BYTE DSTATUS;
+
+/* Results of Disk Functions */
+typedef enum {
+ RES_OK = 0, /* 0: Successful */
+ RES_ERROR, /* 1: R/W Error */
+ RES_WRPRT, /* 2: Write Protected */
+ RES_NOTRDY, /* 3: Not Ready */
+ RES_PARERR /* 4: Invalid Parameter */
+} DRESULT;
+
+
+/*---------------------------------------*/
+/* Prototypes for disk control functions */
+
+DSTATUS disk_initialize (BYTE drv);
+DSTATUS disk_status (BYTE drv);
+DRESULT disk_read (BYTE drv, BYTE* buff, DWORD sector, UINT count);
+#if _USE_WRITE
+DRESULT disk_write (BYTE drv, const BYTE* buff, DWORD sector, UINT count);
+#endif
+#if _USE_IOCTL
+DRESULT disk_ioctl (BYTE drv, BYTE cmd, void* buff);
+#endif
+void disk_timerproc (void);
+
+
+
+/* Disk Status Bits (DSTATUS) */
+
+#define STA_NOINIT 0x01 /* Drive not initialized */
+#define STA_NODISK 0x02 /* No medium in the drive */
+#define STA_PROTECT 0x04 /* Write protected */
+
+
+/* Command code for disk_ioctrl() */
+
+/* Generic command (Used by FatFs) */
+#define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */
+#define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */
+#define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
+#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */
+#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
+
+/* Generic command (Not used by FatFs) */
+#define CTRL_FORMAT 5 /* Create physical format on the media */
+#define CTRL_POWER_IDLE 6 /* Put the device idle state */
+#define CTRL_POWER_OFF 7 /* Put the device off state */
+#define CTRL_LOCK 8 /* Lock media removal */
+#define CTRL_UNLOCK 9 /* Unlock media removal */
+#define CTRL_EJECT 10 /* Eject media */
+
+/* MMC/SDC specific command (Not used by FatFs) */
+#define MMC_GET_TYPE 50 /* Get card type */
+#define MMC_GET_CSD 51 /* Get CSD */
+#define MMC_GET_CID 52 /* Get CID */
+#define MMC_GET_OCR 53 /* Get OCR */
+#define MMC_GET_SDSTAT 54 /* Get SD status */
+
+/* ATA/CF specific command (Not used by FatFs) */
+#define ATA_GET_REV 60 /* Get F/W revision */
+#define ATA_GET_MODEL 61 /* Get model name */
+#define ATA_GET_SN 62 /* Get serial number */
+
+/* MMC card type flags (MMC_GET_TYPE) */
+#define CT_MMC 0x01 /* MMC ver 3 */
+#define CT_SD1 0x02 /* SD ver 1 */
+#define CT_SD2 0x04 /* SD ver 2 */
+#define CT_SDC (CT_SD1|CT_SD2) /* SD */
+#define CT_BLOCK 0x08 /* Block addressing */
+
+#endif /* _DISKIO_H */
diff --git a/include/ff.h b/include/ff.h
new file mode 100644
index 0000000..c19b7b5
--- /dev/null
+++ b/include/ff.h
@@ -0,0 +1,2 @@
+#include "../fatfs/src/ff.h"
+#include "avr/ffconf.h"
diff --git a/include/integer.h b/include/integer.h
new file mode 100644
index 0000000..a263f7c
--- /dev/null
+++ b/include/integer.h
@@ -0,0 +1,26 @@
+/*-------------------------------------------*/
+/* Integer type definitions for FatFs module */
+/*-------------------------------------------*/
+
+#ifndef _FF_INTEGER
+#define _FF_INTEGER
+
+#include <stdint.h>
+
+/* This type MUST be 8 bit */
+typedef uint8_t BYTE;
+
+/* These types MUST be 16 bit */
+typedef int16_t SHORT;
+typedef uint16_t WORD;
+typedef uint16_t WCHAR;
+
+/* These types MUST be 16 bit or 32 bit */
+typedef int INT;
+typedef unsigned int UINT;
+
+/* These types MUST be 32 bit */
+typedef int32_t LONG;
+typedef uint32_t DWORD;
+
+#endif
diff --git a/include/spi.h b/include/spi.h
new file mode 100644
index 0000000..04ea726
--- /dev/null
+++ b/include/spi.h
@@ -0,0 +1,54 @@
+/*
+ * spi.h
+ *
+ * Created on: 17.04.2009
+ * Author: leo
+ */
+
+#ifndef SPI_H_
+#define SPI_H_
+
+#define SPI_PORT PORTB /* SPI Connection port */
+#define SPI_DDR DDRB /* SPI Direction port */
+#define SPI_SS 0
+#define SPI_SCK 1
+#define SPI_MOSI 2
+#define SPI_MISO 3
+
+
+/* SPI macros */
+
+#define SPI_SET_SPEED_F_2 do {SPCR = (1<<SPE) | (1<<MSTR) | (0<<SPR1) | (0<<SPR0); SPSR = (1<<SPI2X); } while(0)
+#define SPI_SET_SPEED_F_4 do {SPCR = (1<<SPE) | (1<<MSTR) | (0<<SPR1) | (0<<SPR0); SPSR = (0<<SPI2X); } while(0)
+#define SPI_SET_SPEED_F_8 do {SPCR = (1<<SPE) | (1<<MSTR) | (0<<SPR1) | (1<<SPR0); SPSR = (1<<SPI2X); } while(0)
+#define SPI_SET_SPEED_F_16 do {SPCR = (1<<SPE) | (1<<MSTR) | (0<<SPR1) | (1<<SPR0); SPSR = (0<<SPI2X); } while(0)
+#define SPI_SET_SPEED_F_32 do {SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (0<<SPR0); SPSR = (1<<SPI2X); } while(0)
+#define SPI_SET_SPEED_F_64 do {SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (0<<SPR0); SPSR = (0<<SPI2X); } while(0)
+#define SPI_SET_SPEED_F_128 do {SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (1<<SPR0); SPSR = (0<<SPI2X); } while(0)
+
+/** switch to fast SPI Clock */
+#define SPISetFastClock() SPI_SET_SPEED_F_2
+#define SPISetSlowClock() SPI_SET_SPEED_F_8
+#define SPISetMMCInitClock() SPI_SET_SPEED_F_64
+
+
+static inline void spi_wait() {
+ loop_until_bit_is_set(SPSR,SPIF);
+}
+
+static inline void spi_write(uint8_t a) {
+ SPDR = a;
+}
+
+static inline void spi_xmit(uint8_t a){
+ spi_write(a);
+ spi_wait();
+}
+
+static inline uint8_t spi_rcvr(void) {
+ SPDR = 0xFF;
+ spi_wait();
+ return SPDR;
+}
+
+#endif /* SPI_H_ */