aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/SAMA/LLD/SDMMCv1
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/ports/SAMA/LLD/SDMMCv1')
-rw-r--r--os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc.c2
-rw-r--r--os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc.h2
-rw-r--r--os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_cmds.c4
-rw-r--r--os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_device.c60
-rw-r--r--os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_macros.h11
-rw-r--r--os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_mmc.c2
-rw-r--r--os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sama5d2.h18
-rw-r--r--os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sd.c2
-rw-r--r--os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sdio.c2
-rw-r--r--os/hal/ports/SAMA/LLD/SDMMCv1/driver.mk10
-rw-r--r--os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_lld.c4
-rw-r--r--os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_lld.h8
12 files changed, 68 insertions, 57 deletions
diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc.c b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc.c
index a337ee6d7..d019da05a 100644
--- a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc.c
+++ b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc.c
@@ -1,7 +1,7 @@
#include <string.h>
#include "hal.h"
-#if (HAL_USE_SDMMC == TRUE)
+#if (SAMA_USE_SDMMC == TRUE)
#include "sama_sdmmc_lld.h"
#include "ch_sdmmc_device.h"
diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc.h b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc.h
index 29f1119da..2370d36a9 100644
--- a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc.h
+++ b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc.h
@@ -99,7 +99,7 @@ typedef struct _SdmmcCommand {
/** Command index */
uint8_t bCmd;
/** Command return status */
- uint8_t bStatus;
+ volatile uint8_t bStatus;
} sSdmmcCommand;
diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_cmds.c b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_cmds.c
index 4323b5876..dbfa8bd7a 100644
--- a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_cmds.c
+++ b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_cmds.c
@@ -1,7 +1,7 @@
#include <string.h>
#include "hal.h"
-#if (HAL_USE_SDMMC == TRUE)
+#if (SAMA_USE_SDMMC == TRUE)
#include "sama_sdmmc_lld.h"
#include "ch_sdmmc_device.h"
@@ -145,7 +145,7 @@ uint8_t Cmd1(SdmmcDriver *drv, bool * hc)
/* Tell the MMC device which voltage the host supplies to the VDD line
* (MMC card) or VCC line (e.MMC device).
* TODO get this board-specific value from platform code. On the
- * SAMA5D2-XULT board, VDD is 3.3V ± 1%. */
+ * SAMA5D2-XULT board, VDD is 3.3V � 1%. */
arg |= SD_OCR_VDD_32_33 | SD_OCR_VDD_33_34;
/* Fill command */
diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_device.c b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_device.c
index 5861508b2..7bdd136e0 100644
--- a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_device.c
+++ b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_device.c
@@ -1,7 +1,7 @@
#include <string.h>
#include "hal.h"
-#if (HAL_USE_SDMMC == TRUE)
+#if (SAMA_USE_SDMMC == TRUE)
#include "sama_sdmmc_lld.h"
#include "ch_sdmmc_device.h"
@@ -148,29 +148,7 @@ uint8_t sdmmc_device_lowlevelcfg(SdmmcDriver *driver)
break;
}
-
- if (res) {
- //check res
- res = IS_CACHE_ALIGNED(driver->config->data_buf);
- TRACE_DEBUG_2("check data buf %d %08x\r\n", res, driver->config->data_buf);
- res &= IS_CACHE_ALIGNED(driver->config->data_buf_size);
- TRACE_DEBUG_2("check data_buf_size %d %08x\r\n", res,
- driver->config->data_buf_size);
- res &= IS_CACHE_ALIGNED(driver->card.EXT);
- TRACE_DEBUG_2("check libExt %d %08x\r\n", res, driver->card.EXT);
-
-
- if (!res) {
- TRACE_WARNING("WARNING: buffers are not aligned on data cache lines. Please fix this before enabling DMA.\n\r");
- driver->use_polling = true;
- } else {
- driver->use_polling = false;
- }
-
- }
-
return res;
-
}
bool sdmmc_device_initialize(SdmmcDriver *driver)
@@ -890,8 +868,12 @@ void sdmmc_device_deInit(SdmmcDriver *drv)
* anticipated reading had to be supported, the data
* cache lines would need to be invalidated twice: both
* now and upon Transfer Complete. */
- cacheInvalidateRegion(driver->cmd.pData, len);
-
+ if(((uint32_t) driver->cmd.pData & (L1_CACHE_BYTES - 1)) || (len & (L1_CACHE_BYTES - 1))) {
+ cacheCleanInvalidateRegion(driver->cmd.pData, len);
+ }
+ else {
+ cacheInvalidateRegion(driver->cmd.pData, len);
+ }
}
}
@@ -1310,7 +1292,7 @@ void sdmmc_device_deInit(SdmmcDriver *drv)
do {
- now = chVTTimeElapsedSinceX(time);
+ now = chVTGetSystemTimeX(); /* chVTTimeElapsedSinceX(time) */
if (now >= end) {
f = 1;
@@ -1328,18 +1310,18 @@ void sdmmc_device_deInit(SdmmcDriver *drv)
}
}
- void sdmmc_device_checkTimeCount(SdmmcDriver *driver)
- {
- if (driver->timeout_elapsed != -1) {
+void sdmmc_device_checkTimeCount(SdmmcDriver *driver)
+{
+ if (driver->timeout_elapsed != -1) {
- driver->timeout_elapsed = 0;
- driver->now = chVTTimeElapsedSinceX( driver->time);
- if (driver->now >= driver->timeout_ticks ) {
- driver->timeout_elapsed = 1;
- }
+ driver->timeout_elapsed = 0;
+ driver->now = chVTTimeElapsedSinceX(driver->time);
+ if (driver->now >= driver->timeout_ticks ) {
+ driver->timeout_elapsed = 1;
+ }
- }
- }
+ }
+}
static void calibrate_zout(Sdmmc * regs)
{
@@ -1575,12 +1557,6 @@ static uint8_t sdmmc_build_dma_table( SdmmcDriver *driver )
line[1], line[0] & SDMMC_DMA0DL_ATTR_END ? '.' : ' ');
#endif
}
- /* Clean the underlying cache lines, to ensure the DMA gets our table
- * when it reads from RAM.
- * CPU access to the table is write-only, peripheral/DMA access is read-
- * only, hence there is no need to invalidate. */
- cacheCleanRegion(driver->config->dma_table, (uint32_t)line - (uint32_t)driver->config->dma_table);
-
return rc;
}
diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_macros.h b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_macros.h
index 52f82fd03..c973d1e4a 100644
--- a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_macros.h
+++ b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_macros.h
@@ -2,12 +2,21 @@
#define CH_SDMMC_MACROS_H_
-
+#if !defined(CACHE_ALIGNED)
#define CACHE_ALIGNED __attribute__((aligned(L1_CACHE_BYTES)))
+#endif
+/*
+ * @brief NO CACHE attribute
+ */
+#if !defined(NO_CACHE)
+#define NO_CACHE __attribute__((section (".nocache")))
+#endif
#define IS_CACHE_ALIGNED(x) ((((uint32_t)(x)) & (L1_CACHE_BYTES - 1)) == 0)
+#if !defined(ROUND_INT_DIV)
#define ROUND_INT_DIV(n,d) (((n) + ((d)-1)) / (d))
+#endif
#define ROUND_UP_MULT(x,m) (((x) + ((m)-1)) & ~((m)-1))
#define CEIL_INT_DIV(n,d) (((n) + (d) - 1) / (d))
#define ABS_DIFF(a,b) ((a) < (b) ? (b) - (a) : (a) - (b))
diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_mmc.c b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_mmc.c
index 5ddbdaed9..7720b4ba3 100644
--- a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_mmc.c
+++ b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_mmc.c
@@ -1,7 +1,7 @@
#include <string.h>
#include "hal.h"
-#if (HAL_USE_SDMMC == TRUE)
+#if (SAMA_USE_SDMMC == TRUE)
#include "sama_sdmmc_lld.h"
#include "ch_sdmmc_device.h"
diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sama5d2.h b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sama5d2.h
index adbd63a41..8c71753f3 100644
--- a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sama5d2.h
+++ b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sama5d2.h
@@ -20,7 +20,24 @@ typedef enum
#define CAPS0_MASK (SDMMC_CA0R_V33VSUP | SDMMC_CA0R_V30VSUP | \
SDMMC_CA0R_V18VSUP | SDMMC_CA0R_SLTYPE_Msk | \
SDMMC_CA0R_ED8SUP)
+/* SOM1 */
+#if defined(BOARD_ATSAM5D27_SOM1)
+#define BOARD_SDMMC0_CAPS0 (SDMMC_CA0R_V33VSUP | \
+ SDMMC_CA0R_V18VSUP | \
+ SDMMC_CA0R_SLTYPE_REMOVABLECARD | \
+ SDMMC_CA0R_ED8SUP)
+
+#define BOARD_SDMMC1_CAPS0 (SDMMC_CA0R_V33VSUP | \
+ SDMMC_CA0R_SLTYPE_REMOVABLECARD)
+#elif defined(BOARD_ATSAM5D2_XULT)
+#define BOARD_SDMMC0_CAPS0 (SDMMC_CA0R_V33VSUP | \
+ SDMMC_CA0R_V18VSUP | \
+ SDMMC_CA0R_SLTYPE_EMBEDDED | \
+ SDMMC_CA0R_ED8SUP)
+#define BOARD_SDMMC1_CAPS0 (SDMMC_CA0R_V33VSUP | \
+ SDMMC_CA0R_SLTYPE_REMOVABLECARD)
+#else
#define BOARD_SDMMC0_CAPS0 (SDMMC_CA0R_V33VSUP | \
SDMMC_CA0R_V18VSUP | \
SDMMC_CA0R_SLTYPE_EMBEDDED | \
@@ -28,5 +45,6 @@ typedef enum
#define BOARD_SDMMC1_CAPS0 (SDMMC_CA0R_V33VSUP | \
SDMMC_CA0R_SLTYPE_REMOVABLECARD)
+#endif
#endif /* CH_SDMMC_SAMA5D2_H_ */
diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sd.c b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sd.c
index ed2286bbc..d1e0f4532 100644
--- a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sd.c
+++ b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sd.c
@@ -1,7 +1,7 @@
#include <string.h>
#include "hal.h"
-#if (HAL_USE_SDMMC == TRUE)
+#if (SAMA_USE_SDMMC == TRUE)
#include "sama_sdmmc_lld.h"
#include "ch_sdmmc_device.h"
#include "ch_sdmmc_cmds.h"
diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sdio.c b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sdio.c
index c9916620a..a7cd77a15 100644
--- a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sdio.c
+++ b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sdio.c
@@ -1,6 +1,6 @@
#include "hal.h"
-#if (HAL_USE_SDMMC == TRUE)
+#if (SAMA_USE_SDMMC == TRUE)
#include "sama_sdmmc_lld.h"
#include "ch_sdmmc_device.h"
diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/driver.mk b/os/hal/ports/SAMA/LLD/SDMMCv1/driver.mk
index 32695db51..49c64f5fc 100644
--- a/os/hal/ports/SAMA/LLD/SDMMCv1/driver.mk
+++ b/os/hal/ports/SAMA/LLD/SDMMCv1/driver.mk
@@ -1,3 +1,12 @@
+# Configuration files directory
+ifeq ($(CONFDIR),)
+ CONFDIR = .
+endif
+
+MCUCONF := $(strip $(shell cat $(CONFDIR)/mcuconf.h | egrep -e "\#define"))
+
+ifneq ($(findstring SAMA_USE_SDMMC TRUE,$(MCUCONF)),)
+
PLATFORMSRC += $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_lld.c \
$(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_device.c \
$(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sdio.c \
@@ -8,3 +17,4 @@ PLATFORMSRC += $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_lld.c \
PLATFORMINC += $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1
+endif
diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_lld.c b/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_lld.c
index 8ea88a347..725d52415 100644
--- a/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_lld.c
+++ b/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_lld.c
@@ -25,7 +25,7 @@
#include "hal.h"
#include "ccportab.h"
-#if (HAL_USE_SDMMC == TRUE) || defined(__DOXYGEN__)
+#if (SAMA_USE_SDMMC == TRUE) || defined(__DOXYGEN__)
#include <string.h>
#include "sama_sdmmc_lld.h"
#include "ch_sdmmc_device.h"
@@ -314,6 +314,6 @@ bool CC_WEAK sdmmcGetInstance(uint8_t index, SdmmcDriver **sdmmcp)
return false;
}
-#endif /* HAL_USE_SDMMC == TRUE */
+#endif /* SAMA_USE_SDMMC == TRUE */
/** @} */
diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_lld.h b/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_lld.h
index a340f7786..1526f7ccc 100644
--- a/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_lld.h
+++ b/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_lld.h
@@ -25,7 +25,7 @@
#ifndef SAMA_SDMMC_LLD_H
#define SAMA_SDMMC_LLD_H
-#if (HAL_USE_SDMMC == TRUE) || defined(__DOXYGEN__)
+#if (SAMA_USE_SDMMC == TRUE) || defined(__DOXYGEN__)
#include "ch_sdmmc.h"
@@ -76,8 +76,6 @@ typedef struct {
sdmmcslots_t slot_id;
uint8_t * bp;
- uint8_t * data_buf;
- uint32_t data_buf_size;
uint32_t * dma_table;
uint32_t dma_table_size;
@@ -87,7 +85,7 @@ typedef struct {
struct SamaSDMMCDriver
{
- sdmmcstate_t state;
+ volatile sdmmcstate_t state;
const SamaSDMMCConfig *config;
Sdmmc * regs; /* set of SDMMC hardware registers */
@@ -160,7 +158,7 @@ bool sdmmcGetInstance(uint8_t index, SdmmcDriver **sdmmcp) ;
}
#endif
-#endif /* HAL_USE_SDMMC == TRUE */
+#endif /* SAMA_USE_SDMMC == TRUE */
#endif /* SAMA_SDMMC_LLD_H */