aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/ATSAMA5D2/SDMMC/main.c
diff options
context:
space:
mode:
authorareviu <areviu.info@gmail.com>2018-02-26 19:06:49 +0000
committerareviu <areviu.info@gmail.com>2018-02-26 19:06:49 +0000
commit0c51b431f291b88062f9303a85e4a69f29ff6ac4 (patch)
tree9a03ca06cf37aca239fb9c9e0cada2554a6590a3 /testhal/ATSAMA5D2/SDMMC/main.c
parent70fb3b40569070168d85a65ede1ca8112a9394f8 (diff)
downloadChibiOS-0c51b431f291b88062f9303a85e4a69f29ff6ac4.tar.gz
ChibiOS-0c51b431f291b88062f9303a85e4a69f29ff6ac4.tar.bz2
ChibiOS-0c51b431f291b88062f9303a85e4a69f29ff6ac4.zip
sdmmc driver update, added support for reliance edge fs
git-svn-id: https://svn.code.sf.net/p/chibios/svn2/trunk@11551 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'testhal/ATSAMA5D2/SDMMC/main.c')
-rw-r--r--testhal/ATSAMA5D2/SDMMC/main.c151
1 files changed, 36 insertions, 115 deletions
diff --git a/testhal/ATSAMA5D2/SDMMC/main.c b/testhal/ATSAMA5D2/SDMMC/main.c
index 551b4dd65..b424ce152 100644
--- a/testhal/ATSAMA5D2/SDMMC/main.c
+++ b/testhal/ATSAMA5D2/SDMMC/main.c
@@ -18,7 +18,15 @@
#include "hal.h"
#include "sama_sdmmc_lld.h"
#include "chprintf.h"
+#include "fat32test.h"
+#include "reledgetest.h"
+//----------- DEMO CONFIGURATION ------------------------
+//0 (SLOT0) or 1 (SLOT1)
+#define DEMO_SLOT 0
+//1 for FFLib, 0 for Reliance
+#define DEMO_FAT 1
+//----------------------------------------------------------
#define BLOCK_CNT_MAX 32u
#define DMADL_CNT_MAX 64u
@@ -26,16 +34,13 @@
-const char test_file_path[] = "test.txt";
-
CACHE_ALIGNED uint8_t data_buf[BLOCK_CNT_MAX * 512ul];
CACHE_ALIGNED static uint32_t dma_table[DMADL_CNT_MAX * SDMMC_DMADL_SIZE];
CACHE_ALIGNED uint8_t sdmmcbuffer[ROUND_UP_MULT(SDMMC_BUFFER_SIZE, L1_CACHE_BYTES)];
-static FATFS fs_header;
-static FIL f_header;
+
BaseSequentialStream * ts;
@@ -56,9 +61,17 @@ static THD_FUNCTION(Thread1, arg) {
}
}
-
-
-static const SamaSDMMCConfig sdmmc_slot1_cfg = {
+#if DEMO_SLOT == 0
+static const SamaSDMMCConfig sdmmc_cfg = {
+ SDMMC_SLOT0,
+ sdmmcbuffer,
+ data_buf,
+ sizeof(data_buf),
+ dma_table,
+ DMADL_CNT_MAX
+};
+#else
+static const SamaSDMMCConfig sdmmc_cfg = {
SDMMC_SLOT1,
sdmmcbuffer,
data_buf,
@@ -66,10 +79,8 @@ static const SamaSDMMCConfig sdmmc_slot1_cfg = {
dma_table,
DMADL_CNT_MAX
};
+#endif
-void getdir(SdmmcDriver *sdmmcp);
-void writefile(SdmmcDriver *sdmmcp);
-void readfile(SdmmcDriver *sdmmcp);
/*
* Application entry point.
*/
@@ -98,23 +109,26 @@ int main(void) {
sdmmcInit();
- sdmmcStart(&SDMMCD1, &sdmmc_slot1_cfg);
+ sdmmcStart(&SDMMCD1, &sdmmc_cfg);
if (SDMMCD1.state != MCID_INIT_ERROR) {
- chprintf(ts,"starting MMC Demo\n\r");
+ chprintf(ts,"starting MMC Demo with slot %d\n\r",SDMMCD1.config->slot_id);
if (sdmmcOpenDevice(&SDMMCD1)) {
- //sdmmcShowDeviceInfo(&SDMMCD1);
- if ( sdmmcMountVolume(&SDMMCD1,&fs_header) ) {
- writefile(&SDMMCD1);
- chprintf(ts,"reading dir:\n\r");
- getdir(&SDMMCD1);
- readfile(&SDMMCD1);
+#if DEMO_FAT == 1
+ fat32test_demo();
+#else
+ relianceedge_demo();
+#endif
+ if (SDMMCD1.config->slot_id == SDMMC_SLOT1)
+ {
+ chprintf(ts,"remove card to finish demo\n\r");
+ sdmmcCloseDevice(&SDMMCD1);
}
- sdmmcCloseDevice(&SDMMCD1);
+
}
@@ -140,106 +154,13 @@ int main(void) {
bool sdmmcGetInstance(uint8_t index, SdmmcDriver **sdmmcp)
{
- if (index == SDMMCD1.config->slot_id) {
- *sdmmcp = &SDMMCD1;
- return true;
- }
- return false;
-}
+ (void)index;
-void writefile(SdmmcDriver *sdmmcp)
-{
- const TCHAR drive_path[] = { '0' + sdmmcp->config->slot_id, ':', '\0' };
- TCHAR file_path[sizeof(drive_path) + sizeof(test_file_path)];
- FRESULT res;
- UINT len;
- uint8_t buffer[]={ 0x57,0x65,0x6C,0x63,0x6F,
- 0x6D,0x65,0x20,0x74,0x6F,
- 0x20,0x43,0x68,0x69,0x62,
- 0x69,0x4F,0x53,0x21};
-
-
- strcpy(file_path, drive_path);
- strcat(file_path, test_file_path);
-
- chprintf(ts,"Creating new file ... ");
- res = f_open(&f_header, file_path, FA_WRITE | FA_CREATE_ALWAYS);
- if (res == FR_OK) {
- chprintf(ts,"OK\r\n");
- res = f_write(&f_header, buffer, 19, &len);
- if (res == FR_OK) {
- chprintf(ts,"written %d bytes\n\r", len);
- }
- }
- else
- {
- chprintf(ts,"Failed error %d\n\r", res);
- }
- f_close(&f_header);
+ *sdmmcp = &SDMMCD1;
+ return true;
}
-void readfile(SdmmcDriver *sdmmcp)
-{
- const TCHAR drive_path[] = { '0' + sdmmcp->config->slot_id, ':', '\0' };
- TCHAR file_path[sizeof(drive_path) + sizeof(test_file_path)];
- FRESULT res;
- UINT len;
- uint8_t buffer[19];
- UINT i;
-
- strcpy(file_path, drive_path);
- strcat(file_path, test_file_path);
-
- chprintf(ts,"Reading back the new file ... ");
- res = f_open(&f_header, file_path, FA_OPEN_EXISTING | FA_READ);
- if (res == FR_OK) {
- chprintf(ts,"OK\r\n");
- res = f_read(&f_header, buffer, 19, &len);
- if (res == FR_OK) {
- chprintf(ts,"read %d bytes\n\r", len);
- for (i=0;i<len;i++) {
- chprintf(ts,"%c", buffer[i]);
- }
- }
- }
- else
- {
- chprintf(ts,"Failed error %d\n\r", res);
- }
- f_close(&f_header);
-
-}
-
-void getdir(SdmmcDriver *sdmmcp)
-{
- const TCHAR drive_path[] = { '0' + sdmmcp->config->slot_id, ':', '\0' };
- DIR dir = { .sect = 0 };
- FILINFO fno = { 0 };
- FRESULT res;
- bool is_dir;
-
- res = f_opendir(&dir, drive_path);
- if (res != FR_OK) {
- chprintf(ts,"Failed to open dir, error %d\n\r", res);
- return;
- }
- chprintf(ts,"files in the root directory:\n\r");
- for (;;) {
- res = f_readdir(&dir, &fno);
- if (res != FR_OK) {
- chprintf(ts,"cannot read dir, error (%d)\n\r", res);
- break;
- }
- if (fno.fname[0] == '\0')
- break;
- is_dir = fno.fattrib & AM_DIR ? true : false;
- chprintf(ts," %s%s%c\n\r", is_dir ? "[" : "", fno.fname,
- is_dir ? ']' : ' ');
- }
-
- res = f_closedir(&dir);
-}