From 99e941775219b48619c006eddcbe55a1930bffe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Fr=C3=B6schle?= Date: Thu, 6 Dec 2012 08:00:52 +0000 Subject: [PATCH] crash when linking SD-modules. Static variable initialization? --- SD_CARD/BaS_gcc/Makefile | 2 +- SD_CARD/BaS_gcc/sources/BaS.c | 1 + SD_CARD/BaS_gcc/sources/diskio.h | 53 +++++++++++++++++++++++++++---- SD_CARD/BaS_gcc/sources/ff.c | 17 ++++++++++ SD_CARD/BaS_gcc/sources/mmcbb.c | 3 +- SD_CARD/BaS_gcc/sources/sd_card.c | 6 ++-- 6 files changed, 69 insertions(+), 13 deletions(-) diff --git a/SD_CARD/BaS_gcc/Makefile b/SD_CARD/BaS_gcc/Makefile index 3d3e62c..c0d32f9 100644 --- a/SD_CARD/BaS_gcc/Makefile +++ b/SD_CARD/BaS_gcc/Makefile @@ -10,7 +10,7 @@ # can be either "Y" or "N" (without quotes). "Y" for using the m68k-elf-, "N" for using the m68k-atari-mint # toolchain -COMPILE_ELF=N +COMPILE_ELF=Y ifeq (Y,$(COMPILE_ELF)) TCPREFIX=m68k-elf- diff --git a/SD_CARD/BaS_gcc/sources/BaS.c b/SD_CARD/BaS_gcc/sources/BaS.c index 713a830..5960b58 100644 --- a/SD_CARD/BaS_gcc/sources/BaS.c +++ b/SD_CARD/BaS_gcc/sources/BaS.c @@ -30,6 +30,7 @@ #include "bas_printf.h" #include "bas_types.h" #include "sd_card.h" +#include "ff.h" /* imported routines */ extern int mmu_init(); diff --git a/SD_CARD/BaS_gcc/sources/diskio.h b/SD_CARD/BaS_gcc/sources/diskio.h index ee61734..a6a2311 100644 --- a/SD_CARD/BaS_gcc/sources/diskio.h +++ b/SD_CARD/BaS_gcc/sources/diskio.h @@ -1,9 +1,16 @@ /*----------------------------------------------------------------------- -/ Low level disk interface modlue include file (C)ChaN, 2009 +/ Low level disk interface modlue include file (C)ChaN, 2012 /-----------------------------------------------------------------------*/ -#ifndef _DISKIO -#define _DISKIO +#ifndef _DISKIO_DEFINED +#define _DISKIO_DEFINED + +#ifdef __cplusplus +extern "C" { +#endif + +#define _USE_WRITE 1 /* 1: Enable disk_write function */ +#define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */ #include "integer.h" @@ -24,17 +31,17 @@ typedef enum { /*---------------------------------------*/ /* Prototypes for disk control functions */ -int assign_drives (int, int); + DSTATUS disk_initialize (BYTE); DSTATUS disk_status (BYTE); DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE); +#if _READONLY == 0 DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE); +#endif DRESULT disk_ioctl (BYTE, BYTE, 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 */ @@ -42,10 +49,42 @@ DRESULT disk_ioctl (BYTE, BYTE, void*); /* Command code for disk_ioctrl fucntion */ -/* Generic command (mandatory for FatFs) */ +/* Generic command (used by FatFs) */ #define CTRL_SYNC 0 /* Flush disk cache (for write functions) */ #define GET_SECTOR_COUNT 1 /* Get media size (for only f_mkfs()) */ #define GET_SECTOR_SIZE 2 /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */ #define GET_BLOCK_SIZE 3 /* Get erase block size (for only f_mkfs()) */ +#define CTRL_ERASE_SECTOR 4 /* Force erased a block of sectors (for only _USE_ERASE) */ + +/* Generic command (not used by FatFs) */ +#define CTRL_POWER 5 /* Get/Set power status */ +#define CTRL_LOCK 6 /* Lock/Unlock media removal */ +#define CTRL_EJECT 7 /* Eject media */ +#define CTRL_FORMAT 8 /* Create physical format on the media */ + +/* MMC/SDC specific ioctl command */ +#define MMC_GET_TYPE 10 /* Get card type */ +#define MMC_GET_CSD 11 /* Get CSD */ +#define MMC_GET_CID 12 /* Get CID */ +#define MMC_GET_OCR 13 /* Get OCR */ +#define MMC_GET_SDSTAT 14 /* Get SD status */ + +/* ATA/CF specific ioctl command */ +#define ATA_GET_REV 20 /* Get F/W revision */ +#define ATA_GET_MODEL 21 /* Get model name */ +#define ATA_GET_SN 22 /* 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 */ + + +#ifdef __cplusplus +} +#endif #endif diff --git a/SD_CARD/BaS_gcc/sources/ff.c b/SD_CARD/BaS_gcc/sources/ff.c index 2700855..ea93388 100644 --- a/SD_CARD/BaS_gcc/sources/ff.c +++ b/SD_CARD/BaS_gcc/sources/ff.c @@ -348,6 +348,20 @@ typedef struct { #endif +/*---------------------------------------------------------*/ +/* User Provided Timer Function for FatFs module */ +/*---------------------------------------------------------*/ + +DWORD get_fattime (void) +{ + return ((DWORD)(2012 - 1980) << 25) /* Year = 2012 */ + | ((DWORD)1 << 21) /* Month = 1 */ + | ((DWORD)1 << 16) /* Day_m = 1*/ + | ((DWORD)0 << 11) /* Hour = 0 */ + | ((DWORD)0 << 5) /* Min = 0 */ + | ((DWORD)0 >> 1); /* Sec = 0 */ +} + /* Character code support macros */ #define IsUpper(c) (((c)>='A')&&((c)<='Z')) #define IsLower(c) (((c)>='a')&&((c)<='z')) @@ -4135,5 +4149,8 @@ int f_printf ( return (cc == EOF) ? cc : res; } + + + #endif /* !_FS_READONLY */ #endif /* _USE_STRFUNC */ diff --git a/SD_CARD/BaS_gcc/sources/mmcbb.c b/SD_CARD/BaS_gcc/sources/mmcbb.c index 41b317c..4d2a77a 100644 --- a/SD_CARD/BaS_gcc/sources/mmcbb.c +++ b/SD_CARD/BaS_gcc/sources/mmcbb.c @@ -149,8 +149,7 @@ static void rcvr_spi_multi(BYTE *buff, UINT count) */ static void xmit_spi_multi(const BYTE *buff, UINT btx) { - UINT n = 512; - WORD d; + int i; for (i = 0; i < btx; i++) xchg_spi(*buff++); diff --git a/SD_CARD/BaS_gcc/sources/sd_card.c b/SD_CARD/BaS_gcc/sources/sd_card.c index 9cda4b5..b0e9341 100644 --- a/SD_CARD/BaS_gcc/sources/sd_card.c +++ b/SD_CARD/BaS_gcc/sources/sd_card.c @@ -26,7 +26,7 @@ #include #include "bas_printf.h" #include "sd_card.h" - +#include "diskio.h" /* * "standard value" for DSPI module configuration register MCF_DSPC_DMCR @@ -173,8 +173,8 @@ int spi_init(void) wait(10000); - sd_card_idle(); - + //sd_card_idle(); + disk_initialize(0); xprintf("finished\r\n"); return 0;