From a0c253d44da778e359c507c529a319f3f4d18b25 Mon Sep 17 00:00:00 2001 From: areviu Date: Sun, 6 May 2018 14:49:44 +0000 Subject: moved ff and reliance-edge under binding folder git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12008 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_ff.c | 314 ------------- os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_reledge.c | 64 --- os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_reledge.h | 14 - os/hal/ports/SAMA/LLD/SDMMCv1/driver.mk | 10 +- os/hal/ports/SAMA/LLD/SDMMCv1/osassert.c | 62 --- os/hal/ports/SAMA/LLD/SDMMCv1/osbdev.c | 515 --------------------- os/hal/ports/SAMA/LLD/SDMMCv1/osclock.c | 85 ---- os/hal/ports/SAMA/LLD/SDMMCv1/osmutex.c | 108 ----- os/hal/ports/SAMA/LLD/SDMMCv1/osoutput.c | 76 --- os/hal/ports/SAMA/LLD/SDMMCv1/ostask.c | 68 --- os/hal/ports/SAMA/LLD/SDMMCv1/redosdeviations.h | 245 ---------- os/hal/ports/SAMA/LLD/SDMMCv1/redostypes.h | 42 -- os/hal/ports/SAMA/LLD/SDMMCv1/redtypes.h | 98 ---- os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_conf.h | 8 - os/various/fatfs_bindings/SAMA5D2x/ch_sdmmc_ff.c | 314 +++++++++++++ os/various/fatfs_bindings/SAMA5D2x/fatfs.mk | 12 + os/various/fatfs_bindings/SAMA5D2x/readme.txt | 13 + .../reledge_bindings/SAMA5D2x/ch_sdmmc_reledge.c | 64 +++ .../reledge_bindings/SAMA5D2x/ch_sdmmc_reledge.h | 14 + os/various/reledge_bindings/SAMA5D2x/osassert.c | 62 +++ os/various/reledge_bindings/SAMA5D2x/osbdev.c | 515 +++++++++++++++++++++ os/various/reledge_bindings/SAMA5D2x/osclock.c | 85 ++++ os/various/reledge_bindings/SAMA5D2x/osmutex.c | 108 +++++ os/various/reledge_bindings/SAMA5D2x/osoutput.c | 76 +++ os/various/reledge_bindings/SAMA5D2x/ostask.c | 68 +++ os/various/reledge_bindings/SAMA5D2x/readme.txt | 12 + .../reledge_bindings/SAMA5D2x/redosdeviations.h | 245 ++++++++++ os/various/reledge_bindings/SAMA5D2x/redostypes.h | 42 ++ os/various/reledge_bindings/SAMA5D2x/redtypes.h | 98 ++++ os/various/reledge_bindings/SAMA5D2x/reledge.mk | 41 ++ os/various/reledge_bindings/readme.txt | 12 - os/various/reledge_bindings/reledge.mk | 30 -- testhal/ATSAMA5D2/SDMMC/Makefile | 15 +- testhal/ATSAMA5D2/SDMMC/main.c | 15 +- 34 files changed, 1787 insertions(+), 1763 deletions(-) delete mode 100644 os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_ff.c delete mode 100644 os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_reledge.c delete mode 100644 os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_reledge.h delete mode 100644 os/hal/ports/SAMA/LLD/SDMMCv1/osassert.c delete mode 100644 os/hal/ports/SAMA/LLD/SDMMCv1/osbdev.c delete mode 100644 os/hal/ports/SAMA/LLD/SDMMCv1/osclock.c delete mode 100644 os/hal/ports/SAMA/LLD/SDMMCv1/osmutex.c delete mode 100644 os/hal/ports/SAMA/LLD/SDMMCv1/osoutput.c delete mode 100644 os/hal/ports/SAMA/LLD/SDMMCv1/ostask.c delete mode 100644 os/hal/ports/SAMA/LLD/SDMMCv1/redosdeviations.h delete mode 100644 os/hal/ports/SAMA/LLD/SDMMCv1/redostypes.h delete mode 100644 os/hal/ports/SAMA/LLD/SDMMCv1/redtypes.h create mode 100644 os/various/fatfs_bindings/SAMA5D2x/ch_sdmmc_ff.c create mode 100644 os/various/fatfs_bindings/SAMA5D2x/fatfs.mk create mode 100644 os/various/fatfs_bindings/SAMA5D2x/readme.txt create mode 100644 os/various/reledge_bindings/SAMA5D2x/ch_sdmmc_reledge.c create mode 100644 os/various/reledge_bindings/SAMA5D2x/ch_sdmmc_reledge.h create mode 100644 os/various/reledge_bindings/SAMA5D2x/osassert.c create mode 100644 os/various/reledge_bindings/SAMA5D2x/osbdev.c create mode 100644 os/various/reledge_bindings/SAMA5D2x/osclock.c create mode 100644 os/various/reledge_bindings/SAMA5D2x/osmutex.c create mode 100644 os/various/reledge_bindings/SAMA5D2x/osoutput.c create mode 100644 os/various/reledge_bindings/SAMA5D2x/ostask.c create mode 100644 os/various/reledge_bindings/SAMA5D2x/readme.txt create mode 100644 os/various/reledge_bindings/SAMA5D2x/redosdeviations.h create mode 100644 os/various/reledge_bindings/SAMA5D2x/redostypes.h create mode 100644 os/various/reledge_bindings/SAMA5D2x/redtypes.h create mode 100644 os/various/reledge_bindings/SAMA5D2x/reledge.mk delete mode 100644 os/various/reledge_bindings/readme.txt delete mode 100644 os/various/reledge_bindings/reledge.mk diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_ff.c b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_ff.c deleted file mode 100644 index d4e98b885..000000000 --- a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_ff.c +++ /dev/null @@ -1,314 +0,0 @@ -/* ---------------------------------------------------------------------------- - * SAM Software Package License - * ---------------------------------------------------------------------------- - * Copyright (c) 2015, Atmel Corporation - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the disclaimer below. - * - * Atmel's name may not be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE - * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * ---------------------------------------------------------------------------- - */ - -/* ---------------------------------------------------------------------------- - * This file is based on the template source file named diskio.c, - * part of the FatFs Module R0.10b: - * Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 - * 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 existing - * storage control modules to the FatFs module with a defined API. - * ---------------------------------------------------------------------------- - */ - -#include "hal.h" - -#if (HAL_USE_SDMMC == TRUE) -#include "sama_sdmmc_lld.h" -#if SDMMC_USE_FF_LIB == 1 -#include "ccportab.h" -#include "ffconf.h" -#include "diskio.h" - -#include -#include "sama_sdmmc_lld.h" -#include "ch_sdmmc_device.h" -#include "ch_sdmmc_sd.h" -#include "ch_sdmmc_sdio.h" -#include "ch_sdmmc_trace.h" -/*---------------------------------------------------------------------------- - * Definitions - *----------------------------------------------------------------------------*/ - -/** - * \brief Access the SD/MMC Library instances owned by the application. - * Used upon calls from the FatFs Module. - * - * Shall be implemented by the application. - */ -extern bool CC_WEAK sdmmcGetInstance(uint8_t index, SdmmcDriver **sdmmcp) ; - -/*---------------------------------------------------------------------------- - * Exported functions - *----------------------------------------------------------------------------*/ - -/** - * \brief Initialize a Drive. - * \param slot Physical drive number (0..). - * \return Drive status flags; STA_NOINIT if the specified drive does not exist. - */ -DSTATUS disk_initialize(BYTE slot) -{ - SdmmcDriver *sdmmcp = NULL; - uint8_t rc; - - if (!sdmmcGetInstance(slot, &sdmmcp)) - return STA_NOINIT; - - - rc = SD_GetStatus(sdmmcp); - - if (rc == SDMMC_NOT_SUPPORTED) - return STA_NODISK | STA_NOINIT; -#if 0 - if (sdmmcp->state != MCID_IDLE ) - sdmmc_device_deInit(sdmmcp); - - /* FIXME a delay with the bus held off may be required by the device */ - rc = sdmmc_device_start(sdmmcp); - - if (rc == SDMMC_OK) { - rc = sdmmc_device_identify(sdmmcp); - } -#endif - - return rc == SDMMC_OK ? 0 : STA_NOINIT; -} - -/** - * \brief Get Drive Status. - * \param slot Physical drive number (0..). - * \return Drive status flags; STA_NODISK if there is currently no device in - * the specified slot. - */ -DSTATUS disk_status(BYTE slot) -{ - SdmmcDriver *sdmmcp = NULL; - uint8_t rc; - - if (!sdmmcGetInstance(slot, &sdmmcp)) - return STA_NODISK | STA_NOINIT; - - rc = SD_GetStatus(sdmmcp); - - if (rc == SDMMC_NOT_SUPPORTED) - return STA_NODISK | STA_NOINIT; - else if (rc != SDMMC_OK) - return STA_NOINIT; - /* Well, no restriction on this drive */ - return 0; -} - -/** - * \brief Read Sector(s). - * \param slot Physical drive number (0..). - * \param buff Data buffer to store read data. - * \param sector Sector address in LBA. - * \param count Number of sectors to read. - * \return Result code; RES_OK if successful. - */ -DRESULT disk_read(BYTE slot, BYTE* buff, DWORD sector, UINT count) -{ - SdmmcDriver *sdmmcp = NULL; - DRESULT res; - uint32_t blk_size, addr = sector, len = count; - uint8_t rc; - - if (!sdmmcGetInstance(slot, &sdmmcp)) - return RES_PARERR; - - blk_size = sdmmcp->card.wBlockSize; - - if (blk_size == 0) - return RES_NOTRDY; - - if (blk_size < FF_MIN_SS) { - if (FF_MIN_SS % blk_size) - return RES_PARERR; - addr = sector * (FF_MIN_SS / blk_size); - len = count * (FF_MIN_SS / blk_size); - } - - if (count <= 1) - rc = SD_ReadBlocks(sdmmcp, addr, buff, len); - else - rc = SD_Read(sdmmcp, addr, buff, len); - - if (rc == SDMMC_OK || rc == SDMMC_CHANGED) - res = RES_OK; - else if (rc == SDMMC_ERR_IO || rc == SDMMC_ERR_RESP || rc == SDMMC_ERR) - res = RES_ERROR; - else if (rc == SDMMC_NO_RESPONSE || rc == SDMMC_BUSY - || rc == SDMMC_NOT_INITIALIZED || rc == SDMMC_LOCKED - || rc == SDMMC_STATE || rc == SDMMC_USER_CANCEL) - res = RES_NOTRDY; - else if (rc == SDMMC_PARAM || rc == SDMMC_NOT_SUPPORTED) - res = RES_PARERR; - else - res = RES_ERROR; - - return res; -} - -#if !FF_FS_READONLY -/** - * \brief Write Sector(s). - * - * \param slot Physical drive number (0..). - * \param buff Data to be written. - * \param sector Sector address in LBA. - * \param count Number of sectors to write. - * \return Result code; RES_OK if successful. - * - * \note The FatFs module will issue multiple sector transfer request - * (count > 1) to the disk I/O layer. The disk function should process - * the multiple sector transfer properly. Do not translate it into - * multiple single sector transfers to the media, or the data read/write - * performance may be drastically decreased. - */ -DRESULT disk_write(BYTE slot, const BYTE* buff, DWORD sector, UINT count) -{ - SdmmcDriver *sdmmcp = NULL; - DRESULT res; - uint32_t blk_size, addr = sector, len = count; - uint8_t rc; - - if (!sdmmcGetInstance(slot, &sdmmcp)) - return RES_PARERR; - - blk_size = sdmmcp->card.wBlockSize; - - if (blk_size < FF_MIN_SS) { - if (FF_MIN_SS % blk_size) - return RES_PARERR; - addr = sector * (FF_MIN_SS / blk_size); - len = count * (FF_MIN_SS / blk_size); - } - if (count <= 1) - rc = SD_WriteBlocks(sdmmcp, addr, buff, len); - else - rc = SD_Write(sdmmcp, addr, buff, len); - - if (rc == SDMMC_OK || rc == SDMMC_CHANGED) - res = RES_OK; - else if (rc == SDMMC_ERR_IO || rc == SDMMC_ERR_RESP || rc == SDMMC_ERR) - res = RES_ERROR; - else if (rc == SDMMC_NO_RESPONSE || rc == SDMMC_BUSY - || rc == SDMMC_NOT_INITIALIZED || rc == SDMMC_LOCKED - || rc == SDMMC_STATE || rc == SDMMC_USER_CANCEL) - res = RES_NOTRDY; - else if (rc == SDMMC_PARAM || rc == SDMMC_NOT_SUPPORTED) - res = RES_PARERR; - else - res = RES_ERROR; - return res; -} -#endif /* _FS_READONLY */ - -/** - * \brief Miscellaneous Functions. - * \param slot Physical drive number (0..). - * \param cmd Control code. - * \param buff Buffer to send/receive control data. - * \return Result code; RES_OK if successful. - */ -DRESULT disk_ioctl(BYTE slot, BYTE cmd, void* buff) -{ - SdmmcDriver *sdmmcp = NULL; - DRESULT res; - DWORD *param_u32 = (DWORD *)buff; - WORD *param_u16 = (WORD *)buff; - uint32_t blk_size, blk_count; - - if (!sdmmcGetInstance(slot, &sdmmcp)) - return RES_PARERR; - - switch (cmd) - { - case CTRL_SYNC: - /* SD/MMC devices do not seem to cache data beyond completion - * of the write commands. Note that if _FS_READONLY is enabled, - * this command is not needed. */ - res = RES_OK; - break; - - case GET_SECTOR_COUNT: - if (!buff) - return RES_PARERR; - blk_size = sdmmcp->card.wBlockSize; - blk_count = sdmmcp->card.dwNbBlocks; - - if (blk_size < FF_MIN_SS) - { - if (FF_MIN_SS % blk_size) - return RES_PARERR; - *param_u32 = blk_count / (FF_MIN_SS / blk_size); - } - else - *param_u32 = blk_count; - res = RES_OK; - break; - - case GET_SECTOR_SIZE: - /* Note that if _MAX_SS equals _MIN_SS i.e. the drive does not - * have to support several sector sizes, this command is not - * needed. */ - if (!buff) - return RES_PARERR; - blk_size = sdmmcp->card.wBlockSize; - *param_u16 = blk_size >= FF_MIN_SS ? blk_size : FF_MIN_SS; - res = RES_OK; - break; - - case GET_BLOCK_SIZE: - if (!buff) - return RES_PARERR; - /* On SD/MMC devices, erase block size is the same as write - * block size. - * Hence, erasing as little as one sector is allowed. */ - *param_u32 = 1; - res = RES_OK; - break; - - case CTRL_TRIM: - /* This TRIM-like command is not implemented. - * It would be required if _USE_TRIM was enabled. */ - res = RES_PARERR; - break; - - default: - res = RES_PARERR; - break; - } - return res; -} -#endif -#endif - diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_reledge.c b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_reledge.c deleted file mode 100644 index 31630c081..000000000 --- a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_reledge.c +++ /dev/null @@ -1,64 +0,0 @@ -#include "hal.h" - -#if (HAL_USE_SDMMC == TRUE) - -#include "sama_sdmmc_lld.h" - -#include "ch_sdmmc_device.h" -#include "ch_sdmmc_cmds.h" -#include "ch_sdmmc_sdio.h" -#include "ch_sdmmc_sd.h" -#include "ch_sdmmc_mmc.h" - -#include "ch_sdmmc_reledge.h" - -eSDMMC_RC sd_mmc_test_unit_ready( SdmmcDriver *sdmmcp) -{ - - uint32_t rc; - - if (sdmmc_is_busy(sdmmcp)) - return SDMMC_BUSY; - - rc = SD_GetStatus(sdmmcp); - - if (rc != SDMMC_OK) - { - return rc; - } - - - if ( !(sdmmcp->card.bCardType == CARD_UNKNOWN) ) { - return SDMMC_OK; - } - // It is not a memory card - return SDMMC_ERR; - -} - -bool sd_mmc_is_write_protected(SdmmcDriver *sdmmcp) -{ - uint32_t rc; - - rc = SD_GetWpStatus(sdmmcp); - - return (rc == SDMMC_LOCKED); -} - - - -eSDMMC_RC sd_mmc_read_capacity(SdmmcDriver *sdmmcp, uint32_t *nb_sector) -{ - // Return last sector address (-1) - *nb_sector = sdmmcp->card.dwNbBlocks - 1; - - return sd_mmc_test_unit_ready(sdmmcp); -} - - - - - -#endif - - diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_reledge.h b/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_reledge.h deleted file mode 100644 index 04ed471cf..000000000 --- a/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_reledge.h +++ /dev/null @@ -1,14 +0,0 @@ - -#ifndef CH_SDMMC_RELEDGE_H_ -#define CH_SDMMC_RELEDGE_H_ - - - - -extern eSDMMC_RC sd_mmc_test_unit_ready( SdmmcDriver *sdmmcp); -extern bool sd_mmc_is_write_protected(SdmmcDriver *sdmmcp); -extern eSDMMC_RC sd_mmc_read_capacity(SdmmcDriver *sdmmcp, uint32_t *nb_sector); - - - -#endif /* CH_SDMMC_RELEDGE_H_ */ diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/driver.mk b/os/hal/ports/SAMA/LLD/SDMMCv1/driver.mk index 06bb80865..32695db51 100644 --- a/os/hal/ports/SAMA/LLD/SDMMCv1/driver.mk +++ b/os/hal/ports/SAMA/LLD/SDMMCv1/driver.mk @@ -4,15 +4,7 @@ PLATFORMSRC += $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_lld.c \ $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_cmds.c \ $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_mmc.c \ $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_sd.c \ - $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc.c \ - $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/osassert.c \ - $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/osoutput.c \ - $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/osclock.c \ - $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/osbdev.c \ - $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/osmutex.c \ - $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/ostask.c \ - $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_reledge.c \ - $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc_ff.c + $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1/ch_sdmmc.c PLATFORMINC += $(CHIBIOS)/os/hal/ports/SAMA/LLD/SDMMCv1 diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/osassert.c b/os/hal/ports/SAMA/LLD/SDMMCv1/osassert.c deleted file mode 100644 index c4cc20497..000000000 --- a/os/hal/ports/SAMA/LLD/SDMMCv1/osassert.c +++ /dev/null @@ -1,62 +0,0 @@ -/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- - - Copyright (c) 2014-2017 Datalight, Inc. - All Rights Reserved Worldwide. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; use version 2 of the License. - - This program is distributed in the hope that it will be useful, - but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -/* Businesses and individuals that for commercial or other reasons cannot - comply with the terms of the GPLv2 license may obtain a commercial license - before incorporating Reliance Edge into proprietary software for - distribution in any form. Visit http://www.datalight.com/reliance-edge for - more information. -*/ -/** @file - @brief Implements assertion handling. -*/ -#include "hal.h" -#if (HAL_USE_SDMMC == TRUE) -#include "sama_sdmmc_lld.h" -#if SDMMC_USE_RELEDGE_LIB == 1 -#include - -#if REDCONF_ASSERTS == 1 - -#include - - -/** @brief Invoke the native assertion handler. - - @param pszFileName Null-terminated string containing the name of the file - where the assertion fired. - @param ulLineNum Line number in @p pszFileName where the assertion - fired. -*/ -void RedOsAssertFail( - const char *pszFileName, - uint32_t ulLineNum) -{ - #if REDCONF_OUTPUT == 1 - IGNORE_ERRORS(PRINT_ASSERT(pszFileName, ulLineNum)); - #endif - - while(true) - { - } -} - -#endif - -#endif -#endif diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/osbdev.c b/os/hal/ports/SAMA/LLD/SDMMCv1/osbdev.c deleted file mode 100644 index 645201521..000000000 --- a/os/hal/ports/SAMA/LLD/SDMMCv1/osbdev.c +++ /dev/null @@ -1,515 +0,0 @@ -/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- - - Copyright (c) 2014-2017 Datalight, Inc. - All Rights Reserved Worldwide. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; use version 2 of the License. - - This program is distributed in the hope that it will be useful, - but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -/* Businesses and individuals that for commercial or other reasons cannot - comply with the terms of the GPLv2 license may obtain a commercial license - before incorporating Reliance Edge into proprietary software for - distribution in any form. Visit http://www.datalight.com/reliance-edge for - more information. -*/ -/** @file - @brief Implements block device I/O. -*/ -#include "hal.h" - -#if (HAL_USE_SDMMC == TRUE) -#include "sama_sdmmc_lld.h" -#if SDMMC_USE_RELEDGE_LIB == 1 - -#include "sama_sdmmc_lld.h" -#include "ch_sdmmc_device.h" -#include "ch_sdmmc_cmds.h" -#include "ch_sdmmc_sdio.h" -#include "ch_sdmmc_sd.h" -#include "ch_sdmmc_mmc.h" -#include "ch_sdmmc_reledge.h" - -#include -#include -#include - -#if REDCONF_API_POSIX == 0 -#error "REDCONF_API_POSIX should be 1" -#endif - -#if REDCONF_API_FSE == 1 -#error "REDCONF_API_FSE not supported, should be 0" -#endif - - -/* sd_mmc_mem_2_ram_multi() and sd_mmc_ram_2_mem_multi() use an unsigned - 16-bit value to specify the sector count, so no transfer can be larger - than UINT16_MAX sectors. -*/ -#define MAX_SECTOR_TRANSFER UINT16_MAX - - -/** @brief Initialize a disk. - - @param bVolNum The volume number of the volume whose block device is being - initialized. - @param mode The open mode, indicating the type of access required. - - @return A negated ::REDSTATUS code indicating the operation result. - - @retval 0 Operation was successful. - @retval -RED_EIO A disk I/O error occurred. - @retval -RED_EROFS The device is read-only media and write access was - requested. -*/ -static REDSTATUS DiskOpen( - uint8_t bVolNum, - BDEVOPENMODE mode) -{ - REDSTATUS ret = 0; - uint32_t ulTries; - - - eSDMMC_RC cs; - - SdmmcDriver *sdmmcp = NULL; - - - if (!sdmmcGetInstance(bVolNum, &sdmmcp)) - return RED_EINVAL; - - /* Note: Assuming the volume number is the same as the SD card slot. The - ASF SD/MMC driver supports two SD slots. This implementation will need - to be modified if multiple volumes share a single SD card. - */ - - /* The first time the disk is opened, the SD card can take a while to get - ready, in which time sd_mmc_test_unit_ready() returns either CTRL_BUSY - or CTRL_NO_PRESENT. Try numerous times, waiting half a second after - each failure. Empirically, this has been observed to succeed on the - second try, so trying 10x more than that provides a margin of error. - */ - for(ulTries = 0U; ulTries < 20U; ulTries++) - { - cs = sd_mmc_test_unit_ready(sdmmcp); - - if((cs != SDMMC_OK) && (cs != SDMMC_BUSY)) - { - break; - } - - // t_msleep(sdmmcp,500); - } - - if(cs == SDMMC_OK) - { - #if REDCONF_READ_ONLY == 0 - if(mode != BDEV_O_RDONLY) - { - if(sd_mmc_is_write_protected(sdmmcp)) - { - ret = -RED_EROFS; - } - } - - if(ret == 0) - #endif - { - uint32_t ulSectorLast; - - IGNORE_ERRORS(sd_mmc_read_capacity(sdmmcp, &ulSectorLast)); - - /* The ASF SD/MMC driver only supports 512-byte sectors. - */ - if( (gaRedVolConf[bVolNum].ulSectorSize != 512U) - || (((uint64_t)ulSectorLast + 1U) < gaRedVolConf[bVolNum].ullSectorCount)) - { - ret = -RED_EINVAL; - } - } - } - else - { - ret = -RED_EIO; - } - - return ret; -} - - -/** @brief Uninitialize a disk. - - @param bVolNum The volume number of the volume whose block device is being - uninitialized. - - @return A negated ::REDSTATUS code indicating the operation result. - - @retval 0 Operation was successful. -*/ -static REDSTATUS DiskClose( - uint8_t bVolNum) -{ - (void)bVolNum; - return 0; -} - - -/** @brief Read sectors from a disk. - - @param bVolNum The volume number of the volume whose block device - is being read from. - @param ullSectorStart The starting sector number. - @param ulSectorCount The number of sectors to read. - @param pBuffer The buffer into which to read the sector data. - - @return A negated ::REDSTATUS code indicating the operation result. - - @retval 0 Operation was successful. -*/ -static REDSTATUS DiskRead( - uint8_t bVolNum, - uint64_t ullSectorStart, - uint32_t ulSectorCount, - void *pBuffer) -{ - REDSTATUS ret = 0; - uint8_t *pbBuffer = CAST_VOID_PTR_TO_UINT8_PTR(pBuffer); - - SdmmcDriver *sdmmcp = NULL; - eSDMMC_RC cs; - - if (!sdmmcGetInstance(bVolNum, &sdmmcp)) - return RED_EINVAL; - - cs = SD_ReadBlocks(sdmmcp, ullSectorStart, pbBuffer,ulSectorCount); - - if(cs != SDMMC_OK) - { - ret = -RED_EIO; - } - - - return ret; -} - - -#if REDCONF_READ_ONLY == 0 - -/** @brief Write sectors to a disk. - - @param bVolNum The volume number of the volume whose block device - is being written to. - @param ullSectorStart The starting sector number. - @param ulSectorCount The number of sectors to write. - @param pBuffer The buffer from which to write the sector data. - - @return A negated ::REDSTATUS code indicating the operation result. - - @retval 0 Operation was successful. -*/ -static REDSTATUS DiskWrite( - uint8_t bVolNum, - uint64_t ullSectorStart, - uint32_t ulSectorCount, - const void *pBuffer) -{ - REDSTATUS ret = 0; - const uint8_t *pbBuffer = CAST_VOID_PTR_TO_CONST_UINT8_PTR(pBuffer); - - SdmmcDriver *sdmmcp = NULL; - eSDMMC_RC cs; - - if (!sdmmcGetInstance(bVolNum, &sdmmcp)) - return RED_EINVAL; - - - cs = SD_WriteBlocks(sdmmcp, ullSectorStart, pbBuffer, ulSectorCount); - if(cs != SDMMC_OK) - { - ret = -RED_EIO; - } - - - return ret; -} - - -/** @brief Flush any caches beneath the file system. - - @param bVolNum The volume number of the volume whose block device is being - flushed. - - @return A negated ::REDSTATUS code indicating the operation result. - - @retval 0 Operation was successful. -*/ -static REDSTATUS DiskFlush( - uint8_t bVolNum) -{ - REDSTATUS ret; - - eSDMMC_RC cs; - - SdmmcDriver *sdmmcp = NULL; - - - if (!sdmmcGetInstance(bVolNum, &sdmmcp)) - return RED_EINVAL; - - /* The ASF SD/MMC driver appears to write sectors synchronously, so it - should be fine to do nothing and return success. However, Atmel's - implementation of the FatFs diskio.c file does the equivalent of the - below when the disk is flushed. Just in case this is important for some - non-obvious reason, do the same. - */ - cs = sd_mmc_test_unit_ready(sdmmcp); - if(cs == SDMMC_OK) - { - ret = 0; - } - else - { - ret = -RED_EIO; - } - - return ret; -} - - -#if REDCONF_DISCARDS == 1 -/** @brief Discard sectors on a disk. - - @param bVolNum The volume number of the volume whose block device - is being accessed. - @param ullSectorStart The starting sector number. - @param ullSectorCount The number of sectors to discard. -*/ -static void DiskDiscard( - uint8_t bVolNum, - uint64_t ullSectorStart, - uint64_t ullSectorCount) -{ -#error "this SD/MMC driver does not support discards." -} -#endif /* REDCONF_DISCARDS == 1 */ - -#endif /* REDCONF_READ_ONLY == 0 */ - -/** @brief Initialize a block device. - - This function is called when the file system needs access to a block - device. - - Upon successful return, the block device should be fully initialized and - ready to service read/write/flush/close requests. - - The behavior of calling this function on a block device which is already - open is undefined. - - @param bVolNum The volume number of the volume whose block device is being - initialized. - @param mode The open mode, indicating the type of access required. - - @return A negated ::REDSTATUS code indicating the operation result. - - @retval 0 Operation was successful. - @retval -RED_EINVAL @p bVolNum is an invalid volume number. - @retval -RED_EIO A disk I/O error occurred. -*/ -REDSTATUS RedOsBDevOpen( - uint8_t bVolNum, - BDEVOPENMODE mode) -{ - REDSTATUS ret; - - if(bVolNum >= REDCONF_VOLUME_COUNT) - { - ret = -RED_EINVAL; - } - else - { - ret = DiskOpen(bVolNum, mode); - } - - return ret; -} - - -/** @brief Uninitialize a block device. - - This function is called when the file system no longer needs access to a - block device. If any resource were allocated by RedOsBDevOpen() to service - block device requests, they should be freed at this time. - - Upon successful return, the block device must be in such a state that it - can be opened again. - - The behavior of calling this function on a block device which is already - closed is undefined. - - @param bVolNum The volume number of the volume whose block device is being - uninitialized. - - @return A negated ::REDSTATUS code indicating the operation result. - - @retval 0 Operation was successful. - @retval -RED_EINVAL @p bVolNum is an invalid volume number. -*/ -REDSTATUS RedOsBDevClose( - uint8_t bVolNum) -{ - REDSTATUS ret; - - if(bVolNum >= REDCONF_VOLUME_COUNT) - { - ret = -RED_EINVAL; - } - else - { - ret = DiskClose(bVolNum); - } - - return ret; -} - - -/** @brief Read sectors from a physical block device. - - The behavior of calling this function is undefined if the block device is - closed or if it was opened with ::BDEV_O_WRONLY. - - @param bVolNum The volume number of the volume whose block device - is being read from. - @param ullSectorStart The starting sector number. - @param ulSectorCount The number of sectors to read. - @param pBuffer The buffer into which to read the sector data. - - @return A negated ::REDSTATUS code indicating the operation result. - - @retval 0 Operation was successful. - @retval -RED_EINVAL @p bVolNum is an invalid volume number, @p pBuffer is - `NULL`, or @p ullStartSector and/or @p ulSectorCount - refer to an invalid range of sectors. - @retval -RED_EIO A disk I/O error occurred. -*/ -REDSTATUS RedOsBDevRead( - uint8_t bVolNum, - uint64_t ullSectorStart, - uint32_t ulSectorCount, - void *pBuffer) -{ - REDSTATUS ret = 0; - - if( (bVolNum >= REDCONF_VOLUME_COUNT) - || (ullSectorStart >= gaRedVolConf[bVolNum].ullSectorCount) - || ((gaRedVolConf[bVolNum].ullSectorCount - ullSectorStart) < ulSectorCount) - || (pBuffer == NULL)) - { - ret = -RED_EINVAL; - } - else - { - ret = DiskRead(bVolNum, ullSectorStart, ulSectorCount, pBuffer); - } - - return ret; -} - - -#if REDCONF_READ_ONLY == 0 - -/** @brief Write sectors to a physical block device. - - The behavior of calling this function is undefined if the block device is - closed or if it was opened with ::BDEV_O_RDONLY. - - @param bVolNum The volume number of the volume whose block device - is being written to. - @param ullSectorStart The starting sector number. - @param ulSectorCount The number of sectors to write. - @param pBuffer The buffer from which to write the sector data. - - @return A negated ::REDSTATUS code indicating the operation result. - - @retval 0 Operation was successful. - @retval -RED_EINVAL @p bVolNum is an invalid volume number, @p pBuffer is - `NULL`, or @p ullStartSector and/or @p ulSectorCount - refer to an invalid range of sectors. - @retval -RED_EIO A disk I/O error occurred. -*/ -REDSTATUS RedOsBDevWrite( - uint8_t bVolNum, - uint64_t ullSectorStart, - uint32_t ulSectorCount, - const void *pBuffer) -{ - REDSTATUS ret = 0; - - if( (bVolNum >= REDCONF_VOLUME_COUNT) - || (ullSectorStart >= gaRedVolConf[bVolNum].ullSectorCount) - || ((gaRedVolConf[bVolNum].ullSectorCount - ullSectorStart) < ulSectorCount) - || (pBuffer == NULL)) - { - ret = -RED_EINVAL; - } - else - { - ret = DiskWrite(bVolNum, ullSectorStart, ulSectorCount, pBuffer); - } - - return ret; -} - - -/** @brief Flush any caches beneath the file system. - - This function must synchronously flush all software and hardware caches - beneath the file system, ensuring that all sectors written previously are - committed to permanent storage. - - If the environment has no caching beneath the file system, the - implementation of this function can do nothing and return success. - - The behavior of calling this function is undefined if the block device is - closed or if it was opened with ::BDEV_O_RDONLY. - - @param bVolNum The volume number of the volume whose block device is being - flushed. - - @return A negated ::REDSTATUS code indicating the operation result. - - @retval 0 Operation was successful. - @retval -RED_EINVAL @p bVolNum is an invalid volume number. - @retval -RED_EIO A disk I/O error occurred. -*/ -REDSTATUS RedOsBDevFlush( - uint8_t bVolNum) -{ - REDSTATUS ret; - - if(bVolNum >= REDCONF_VOLUME_COUNT) - { - ret = -RED_EINVAL; - } - else - { - ret = DiskFlush(bVolNum); - } - - return ret; -} - -#endif /* REDCONF_READ_ONLY == 0 */ -#endif - -#endif diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/osclock.c b/os/hal/ports/SAMA/LLD/SDMMCv1/osclock.c deleted file mode 100644 index e140e6e28..000000000 --- a/os/hal/ports/SAMA/LLD/SDMMCv1/osclock.c +++ /dev/null @@ -1,85 +0,0 @@ -/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- - - Copyright (c) 2014-2017 Datalight, Inc. - All Rights Reserved Worldwide. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; use version 2 of the License. - - This program is distributed in the hope that it will be useful, - but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -/* Businesses and individuals that for commercial or other reasons cannot - comply with the terms of the GPLv2 license may obtain a commercial license - before incorporating Reliance Edge into proprietary software for - distribution in any form. Visit http://www.datalight.com/reliance-edge for - more information. -*/ -/** @file - @brief Implements real-time clock functions. -*/ -#include "hal.h" -#if (HAL_USE_SDMMC == TRUE) -#include "sama_sdmmc_lld.h" -#if SDMMC_USE_RELEDGE_LIB == 1 -#include - - -/** @brief Initialize the real time clock. - - The behavior of calling this function when the RTC is already initialized - is undefined. - - @return A negated ::REDSTATUS code indicating the operation result. - - @retval 0 Operation was successful. -*/ -REDSTATUS RedOsClockInit(void) -{ - return 0; -} - - -/** @brief Uninitialize the real time clock. - - The behavior of calling this function when the RTC is not initialized is - undefined. - - @return A negated ::REDSTATUS code indicating the operation result. - - @retval 0 Operation was successful. -*/ -REDSTATUS RedOsClockUninit(void) -{ - return 0; -} - - -/** @brief Get the date/time. - - The behavior of calling this function when the RTC is not initialized is - undefined. - - @return The number of seconds since January 1, 1970 excluding leap seconds - (in other words, standard Unix time). If the resolution or epoch - of the RTC is different than this, the implementation must convert - it to the expected representation. -*/ -uint32_t RedOsClockGetTime(void) -{ - /* FreeRTOS does not provide an RTC abstraction since most of the systems - it targets have no RTC hardware. If your hardware includes an RTC that - you would like to use, this function must be customized. - */ - return 0; -} -#endif -#endif - diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/osmutex.c b/os/hal/ports/SAMA/LLD/SDMMCv1/osmutex.c deleted file mode 100644 index b921a8aa9..000000000 --- a/os/hal/ports/SAMA/LLD/SDMMCv1/osmutex.c +++ /dev/null @@ -1,108 +0,0 @@ -/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- - - Copyright (c) 2014-2017 Datalight, Inc. - All Rights Reserved Worldwide. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; use version 2 of the License. - - This program is distributed in the hope that it will be useful, - but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -/* Businesses and individuals that for commercial or other reasons cannot - comply with the terms of the GPLv2 license may obtain a commercial license - before incorporating Reliance Edge into proprietary software for - distribution in any form. Visit http://www.datalight.com/reliance-edge for - more information. -*/ -/** @file - @brief Implements a synchronization object to provide mutual exclusion. -*/ -#include "ch.h" -#include "hal.h" -#if (HAL_USE_SDMMC == TRUE) -#include "sama_sdmmc_lld.h" -#if SDMMC_USE_RELEDGE_LIB == 1 -#include -#include - -#if REDCONF_TASK_COUNT > 1U - - -static semaphore_t red_sem; - - -/** @brief Initialize the mutex. - - After initialization, the mutex is in the released state. - - The behavior of calling this function when the mutex is still initialized - is undefined. - - @return A negated ::REDSTATUS code indicating the operation result. - - @retval 0 Operation was successful. -*/ -REDSTATUS RedOsMutexInit(void) -{ - chSemObjectInit(&red_sem, 1); - - return 0; -} - - -/** @brief Uninitialize the mutex. - - The behavior of calling this function when the mutex is not initialized is - undefined; likewise, the behavior of uninitializing the mutex when it is - in the acquired state is undefined. - - @return A negated ::REDSTATUS code indicating the operation result. - - @retval 0 Operation was successful. -*/ -REDSTATUS RedOsMutexUninit(void) -{ - chSemReset(&red_sem, 0); - - return 0; -} - - -/** @brief Acquire the mutex. - - The behavior of calling this function when the mutex is not initialized is - undefined; likewise, the behavior of recursively acquiring the mutex is - undefined. -*/ -void RedOsMutexAcquire(void) -{ - chSemWaitTimeout(&red_sem, TIME_INFINITE); -} - - -/** @brief Release the mutex. - - The behavior is undefined in the following cases: - - - Releasing the mutex when the mutex is not initialized. - - Releasing the mutex when it is not in the acquired state. - - Releasing the mutex from a task or thread other than the one which - acquired the mutex. -*/ -void RedOsMutexRelease(void) -{ - chSemSignal(&red_sem); -} - -#endif -#endif -#endif - diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/osoutput.c b/os/hal/ports/SAMA/LLD/SDMMCv1/osoutput.c deleted file mode 100644 index bff230522..000000000 --- a/os/hal/ports/SAMA/LLD/SDMMCv1/osoutput.c +++ /dev/null @@ -1,76 +0,0 @@ -/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- - - Copyright (c) 2014-2017 Datalight, Inc. - All Rights Reserved Worldwide. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; use version 2 of the License. - - This program is distributed in the hope that it will be useful, - but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -/* Businesses and individuals that for commercial or other reasons cannot - comply with the terms of the GPLv2 license may obtain a commercial license - before incorporating Reliance Edge into proprietary software for - distribution in any form. Visit http://www.datalight.com/reliance-edge for - more information. -*/ -/** @file - @brief Implements outputting a character string. -*/ -#include "hal.h" -#if (HAL_USE_SDMMC == TRUE) -#include "sama_sdmmc_lld.h" -#if SDMMC_USE_RELEDGE_LIB == 1 -#include - -#if REDCONF_OUTPUT == 1 - -#include - - -/** @brief Write a string to a user-visible output location. - - Write a null-terminated string to the serial port, console, terminal, or - other display device, such that the text is visible to the user. - - @param pszString A null-terminated string. -*/ -void RedOsOutputString( - const char *pszString) -{ - if(pszString == NULL) - { - REDERROR(); - } - else - { - uint32_t ulIdx = 0U; - - while(pszString[ulIdx] != '\0') - { - OUTPUT_CHARACTER(pszString[ulIdx]); - - /* Serial output often requires a \r to print newlines correctly. - */ - if(pszString[ulIdx] == '\n') - { - OUTPUT_CHARACTER('\r'); - } - - ulIdx++; - } - } -} - -#endif - -#endif -#endif diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/ostask.c b/os/hal/ports/SAMA/LLD/SDMMCv1/ostask.c deleted file mode 100644 index f06f00f22..000000000 --- a/os/hal/ports/SAMA/LLD/SDMMCv1/ostask.c +++ /dev/null @@ -1,68 +0,0 @@ -/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- - - Copyright (c) 2014-2017 Datalight, Inc. - All Rights Reserved Worldwide. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; use version 2 of the License. - - This program is distributed in the hope that it will be useful, - but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -/* Businesses and individuals that for commercial or other reasons cannot - comply with the terms of the GPLv2 license may obtain a commercial license - before incorporating Reliance Edge into proprietary software for - distribution in any form. Visit http://www.datalight.com/reliance-edge for - more information. -*/ -/** @file - @brief Implements task functions. -*/ -#include "ch.h" -#include "hal.h" -#if (HAL_USE_SDMMC == TRUE) -#include "sama_sdmmc_lld.h" -#if SDMMC_USE_RELEDGE_LIB == 1 -#include - -#if (REDCONF_TASK_COUNT > 1U) && (REDCONF_API_POSIX == 1) - -#include - - -/** @brief Get the current task ID. - - This task ID must be unique for all tasks using the file system. - - @return The task ID. Must not be 0. -*/ -uint32_t RedOsTaskId(void) -{ - /* Simply casting the xTaskGetCurrentTaskHandle() return value results in - warnings from some compilers, so use variables. - */ - thread_t* t= chThdGetSelfX(); - uintptr_t taskptr = CAST_TASK_PTR_TO_UINTPTR(t); - uint32_t ulTaskPtr = (uint32_t)taskptr; - - /* Assert no information was lost casting from uintptr_t to uint32_t. - */ - REDASSERT(ulTaskPtr == taskptr); - - /* NULL is a valid task handle in FreeRTOS, so add one to all task IDs. - */ - REDASSERT((ulTaskPtr + 1U) != 0U); - return ulTaskPtr + 1U; -} - -#endif - -#endif -#endif diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/redosdeviations.h b/os/hal/ports/SAMA/LLD/SDMMCv1/redosdeviations.h deleted file mode 100644 index b00fc4184..000000000 --- a/os/hal/ports/SAMA/LLD/SDMMCv1/redosdeviations.h +++ /dev/null @@ -1,245 +0,0 @@ -/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- - - Copyright (c) 2014-2017 Datalight, Inc. - All Rights Reserved Worldwide. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; use version 2 of the License. - - This program is distributed in the hope that it will be useful, - but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -/* Businesses and individuals that for commercial or other reasons cannot - comply with the terms of the GPLv2 license may obtain a commercial license - before incorporating Reliance Edge into proprietary software for - distribution in any form. Visit http://www.datalight.com/reliance-edge for - more information. -*/ -/** @file - @brief Macros to encapsulate MISRA C:2012 deviations in OS-specific code. -*/ -#ifndef REDOSDEVIATIONS_H -#define REDOSDEVIATIONS_H - - -#if REDCONF_OUTPUT == 1 -/* Needed for PRINT_ASSERT() and OUTPUT_CHARACTER(). -*/ -#include -#endif - - -#if (REDCONF_ASSERTS == 1) && (REDCONF_OUTPUT == 1) -/** @brief Print a formatted message for an assertion. - - Usages of this macro deviate from MISRA C:2012 Rule 21.6 (required). Using - printf() is the most convenient way to output this information; and the risk - of "unspecified, undefined and implementation-defined" behavior causing - problems (as cited in the rationale for the rule) is small. The driver does - not depend on this string being outputted correctly. Furthermore, use of - printf() disappears when either asserts or output are disabled. - - As Rule 21.6 is required, a separate deviation record is required. -*/ -#define PRINT_ASSERT(file, line) \ - printf("Assertion failed in \"%s\" at line %u\n\r", ((file) == NULL) ? "" : (file), (unsigned)(line)) -#endif - - -/** @brief Cast a value to unsigned long. - - Usages of this macro deviate from MISRA C:2012 Directive 4.6. This macro is - used in two places to cast a uint64_t value (used by the block device - abstraction for sector numbers) to unsigned long, since third-party code - which is not under the control of this project uses unsigned long for sector - numbers. The cast is guaranteed to not lose any information, since when the - disk is opened the sector count is verified to be less than or equal to an - unsigned long value. The text of the directive mentions that "it might be - desirable not to apply this guideline when interfacing with ... code outside - the project's control", which describes the situation for this deviation. - - As Directive 4.6 is advisory, a deviation record is not required. This - notice is the only record of the deviation. -*/ -#define CAST_ULONG(ull) ((unsigned long)(ull)) - - -/** @brief Cast a const-qualified pointer to a pointer which is *not* - const-qualified. - - Usages of this macro deviate from MISRA C:2012 Rule 11.8. This macro is - used in exactly one place in order to cope with a poorly designed - third-party interface. Reliance Edge, at every level of the stack, uses - const-qualified pointers for buffers used in write operations, since the - data is read from the buffer, and the buffer does not need to be modified - (consistent with Rule 8.13). One of the third-party block device interfaces - that Reliance Edge interfaces with does not follow this convention: it uses - an unqualified pointer for the buffer parameter of its sector write - function. This forces the need for the cast to avoid warnings. The - implementation of the sector write function is provided by the user, so it - is to be hoped that the buffer is not actually modified. - - As Rule 11.8 is required, a separate deviation record is required. -*/ -#define CAST_AWAY_CONST(type, ptr) ((type *)(ptr)) - - -/** @brief Allocate zero-initialized (cleared) memory. - - All usages of this macro deviate from MISRA C:2012 Directive 4.12 (required) - and Rule 21.3 (required). In the context of the single place it is actually - used, this macro also deviates from Rule 22.1 (required). - - This macro is used in the FreeRTOS block device code in order to allocate a - RAM disk, when that implementation of the block device is selected. The - primary rationale for all these deviations is that a) the RAM disk cannot be - allocated statically (since the volume information is stored in a - structure), and b) the RAM disk is primarily intended as a temporary testing - tool for users who want to try out Reliance Edge before the real storage - media is available. In most real systems, Reliance Edge is used with - non-volatile storage like SD/MMC or eMMC, not with RAM disks. - - Rule 22.1 states that all resources which are allocated must also be - explicitly freed. The RAM disk is allocated and never freed, deviating from - that rule. This is done because the data in the RAM disk is emulating a - non-volatile storage medium, and thus needs to persist even after the block - device is closed, to allow the file system to be ormatted and then mounted, - or unmounted and remounted in the course of a test. Thus the memory will - remain allocated until the target device is rebooted. This is assumed to be - acceptable for the primary purpose of the RAM disk, which is preliminary - testing. - - As Directive 4.12, Rule 21.3, and Rule 22.1 are all required, separate - deviation records are required. -*/ -#define ALLOCATE_CLEARED_MEMORY(nelem, elsize) calloc(nelem, elsize) - - -#if REDCONF_OUTPUT == 1 -/** @brief Output a character to a serial port or other display device. - - Usages of this macro deviate from MISRA C:2012 Rule 21.6 (required). - FreeRTOS does not include a standard method of printing characters, so - putchar() is the most convenient and portable way to accomplish the task. - The risk of "unspecified, undefined and implementation-defined" behavior - causing problems (as cited in the rationale for the rule) is small. The - driver does not depend on the character being outputted correctly. - Furthermore, use of putchar() disappears when output is disabled. - - As Rule 21.6 is required, a separate deviation record is required. -*/ -#define OUTPUT_CHARACTER(ch) (void)putchar(ch) -#endif - - -#if (REDCONF_TASK_COUNT > 1U) && (REDCONF_API_POSIX == 1) -/** @brief Cast a TaskHandle_t (a pointer type) to uintptr_t. - - Usage of this macro deivate from MISRA-C:2012 Rule 11.4 (advisory). This - macro is used for the FreeRTOS version of RedOsTaskId(). Some RTOSes - natively use an integer for task IDs; others use pointers. RedOsTaskId() - uses integers, FreeRTOS uses pointers; to reconcile this difference, the - pointer must be cast to integer. This is fairly safe, since the resulting - integer is never cast back to a pointer; and although the integer - representation of a pointer is implementation-defined, the representation is - irrelevant provided that unique pointers are converted to unique integers. - - As Rule 11.4 is advisory, a deviation record is not required. This notice - is the only record of the deviation. -*/ -#define CAST_TASK_PTR_TO_UINTPTR(taskptr) ((uintptr_t)(taskptr)) -#endif - - -/** @brief Ignore the return value of a function (cast to void) - - Usages of this macro deviate from MISRA C:2012 Directive 4.7, which states - that error information must be checked immediately after a function returns - potential error information. - - If asserts and output are enabled, then this macro is used to document that - the return value of printf() is ignored. A failure of printf() does not - impact the filesystem core, nor is there anything the filesystem can do to - respond to such an error (especially since it occurs within an assert). - Thus, the most reasonable action is to ignore the error. - - In the STM32 SDIO block device implementation, errors are also ignored in an - IRQ interrupt handler. This is the most reasonable action to take for two - reasons: (a) it would be dangerous to spend processor time responding to the - error inside the IRQ handler; (b) it has been verified that the same error - is propegated to the DiskRead/Write method, which does return the error to - the core. - - In the Atmel SD/MMC block device implementation, error information from - sd_mmc_read_capacity() is ignored. This is a reasonable action because all - of the possible error conditions were eliminated by a previous check. - sd_mmc_read_capacity() fails under the same conditions as - sd_mmc_test_unit_ready(), which was checked ealier in the same function. - - In the mutex module, error information returned from the mutex release - function is ignored when asserts are disabled. This is a reasonable action - because the mutex release function (xSemaphoreGive) is documented only to - fail if the mutex was not obtained correctly, which can be demonstrably - avoided. - - As Directive 4.7 is required, a separate deviation record is required. -*/ -#define IGNORE_ERRORS(fn) ((void) (fn)) - - -/** @brief Determine whether a pointer is aligned on a 32-bit boundary. - - This is used to determine whether a data buffer meets the requirements of - the underlying block device implementation. When transferring data via - DMA (Direct Memory Access) on an STM32 device, the data buffer must be cast - as a uint32 pointer, and unexpected behavior may occur if the buffer is not - aligned correctly. - - There is no way to perform this check without deviating from MISRA C rules - against casting pointers to integer types. Usage of this macro deviates - from MISRA C:2012 Rule 11.4 (advisory). The main rationale the rule cites - against converting pointers to integers is that the chosen integer type may - not be able to represent the pointer; this is a non-issue here since we use - uintptr_t. The text says the rule still applies when using uintptr_t due to - concern about unaligned pointers, but that is not an issue here since the - integer value of the pointer is not saved and not converted back into a - pointer and dereferenced. The result of casting a pointer to a sufficiently - large integer is implementation-defined, but macros similar to this one have - been used by Datalight for a long time in a wide variety of environments and - they have always worked as expected. - - This deviation only occurs when using the STM32 SDIO block device - implementation. - - As Rule 11.4 is advisory, a deviation record is not required. This notice - is the only record of deviation. -*/ -#define IS_UINT32_ALIGNED_PTR(ptr) (((uintptr_t)(ptr) & (sizeof(uint32_t) - 1U)) == 0U) - - -/** @brief Cast a 32-bit aligned void pointer to a uint32 pointer. - - Usages of this macro deviate from MISRA C:2012 Rule 11.5 (advisory). A - cast from a void pointer to an object pointer is discouraged because of - potential alignment issues. However, this macro is only used to cast - pointers that have already been tested to be 32-bit aligned, so the - operation will be safe. - - This deviation only occurs when using the STM32 SDIO block device - implementation. - - As rule 11.5 is advisory, a deviation record is not required. This notice - is the only record of the deviation. -*/ -#define CAST_UINT32_PTR(ptr) ((uint32_t *) (ptr)) - - -#endif - diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/redostypes.h b/os/hal/ports/SAMA/LLD/SDMMCv1/redostypes.h deleted file mode 100644 index 687b2d167..000000000 --- a/os/hal/ports/SAMA/LLD/SDMMCv1/redostypes.h +++ /dev/null @@ -1,42 +0,0 @@ -/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- - - Copyright (c) 2014-2017 Datalight, Inc. - All Rights Reserved Worldwide. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; use version 2 of the License. - - This program is distributed in the hope that it will be useful, - but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -/* Businesses and individuals that for commercial or other reasons cannot - comply with the terms of the GPLv2 license may obtain a commercial license - before incorporating Reliance Edge into proprietary software for - distribution in any form. Visit http://www.datalight.com/reliance-edge for - more information. -*/ -/** @file - @brief Defines OS-specific types for use in common code. -*/ -#ifndef REDOSTYPES_H -#define REDOSTYPES_H - - -/** @brief Implementation-defined timestamp type. - - This can be an integer, a structure, or a pointer: anything that is - convenient for the implementation. Since the underlying type is not fixed, - common code should treat this as an opaque type. -*/ -typedef uint32_t REDTIMESTAMP; - - -#endif - diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/redtypes.h b/os/hal/ports/SAMA/LLD/SDMMCv1/redtypes.h deleted file mode 100644 index bb5606eef..000000000 --- a/os/hal/ports/SAMA/LLD/SDMMCv1/redtypes.h +++ /dev/null @@ -1,98 +0,0 @@ -/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- - - Copyright (c) 2014-2017 Datalight, Inc. - All Rights Reserved Worldwide. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; use version 2 of the License. - - This program is distributed in the hope that it will be useful, - but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty - of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -/* Businesses and individuals that for commercial or other reasons cannot - comply with the terms of the GPLv2 license may obtain a commercial license - before incorporating Reliance Edge into proprietary software for - distribution in any form. Visit http://www.datalight.com/reliance-edge for - more information. -*/ -/** @file - @brief Defines basic types used by Reliance Edge. - - The following types *must* be defined by this header, either directly (using - typedef) or indirectly (by including other headers, such as the C99 headers - stdint.h and stdbool.h): - - - bool: Boolean type, capable of storing true (1) or false (0) - - uint8_t: Unsigned 8-bit integer - - int8_t: Signed 8-bit integer - - uint16_t: Unsigned 16-bit integer - - int16_t: Signed 16-bit integer - - uint32_t: Unsigned 32-bit integer - - int32_t: Signed 32-bit integer - - uint64_t: Unsigned 64-bit integer - - int64_t: Signed 64-bit integer - - uintptr_t: Unsigned integer capable of storing a pointer, preferably the - same size as pointers themselves. - - These types deliberately use the same names as the standard C99 types, so - that if the C99 headers stdint.h and stdbool.h are available, they may be - included here. - - If the user application defines similar types, those may be reused. For - example, suppose there is an application header apptypes.h which defines - types with a similar purpose but different names. That header could be - reused to define the types Reliance Edge needs: - - ~~~{.c} - #include - - typedef BOOL bool; - typedef BYTE uint8_t; - typedef INT8 int8_t; - // And so on... - ~~~ - - If there are neither C99 headers nor suitable types in application headers, - this header should be populated with typedefs that define the required types - in terms of the standard C types. This requires knowledge of the size of - the C types on the target hardware (e.g., how big is an "int" or a pointer). - Below is an example which assumes the target has 8-bit chars, 16-bit shorts, - 32-bit ints, 32-bit pointers, and 64-bit long longs: - - ~~~{.c} - typedef int bool; - typedef unsigned char uint8_t; - typedef signed char int8_t; - typedef unsigned short uint16_t; - typedef short int16_t; - typedef unsigned int uint32_t; - typedef int int32_t; - typedef unsigned long long uint64_t; - typedef long long int64_t; - typedef uint32_t uintptr_t; - ~~~ -*/ -#ifndef REDTYPES_H -#define REDTYPES_H - -#include "hal.h" - -/* Defines bool. -*/ -//#include - -/* Defines uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, - int64_t, and uintptr_t. -*/ -//#include - - -#endif - diff --git a/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_conf.h b/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_conf.h index 74dde4632..9df0b5d9e 100644 --- a/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_conf.h +++ b/os/hal/ports/SAMA/LLD/SDMMCv1/sama_sdmmc_conf.h @@ -24,13 +24,5 @@ #endif -#ifndef SDMMC_USE_FF_LIB -#define SDMMC_USE_FF_LIB 1 -#endif - -#ifndef SDMMC_USE_RELEDGE_LIB -#define SDMMC_USE_RELEDGE_LIB 1 -#endif - #endif //SAMA_SDMMC_CONF_H diff --git a/os/various/fatfs_bindings/SAMA5D2x/ch_sdmmc_ff.c b/os/various/fatfs_bindings/SAMA5D2x/ch_sdmmc_ff.c new file mode 100644 index 000000000..d4e98b885 --- /dev/null +++ b/os/various/fatfs_bindings/SAMA5D2x/ch_sdmmc_ff.c @@ -0,0 +1,314 @@ +/* ---------------------------------------------------------------------------- + * SAM Software Package License + * ---------------------------------------------------------------------------- + * Copyright (c) 2015, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +/* ---------------------------------------------------------------------------- + * This file is based on the template source file named diskio.c, + * part of the FatFs Module R0.10b: + * Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 + * 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 existing + * storage control modules to the FatFs module with a defined API. + * ---------------------------------------------------------------------------- + */ + +#include "hal.h" + +#if (HAL_USE_SDMMC == TRUE) +#include "sama_sdmmc_lld.h" +#if SDMMC_USE_FF_LIB == 1 +#include "ccportab.h" +#include "ffconf.h" +#include "diskio.h" + +#include +#include "sama_sdmmc_lld.h" +#include "ch_sdmmc_device.h" +#include "ch_sdmmc_sd.h" +#include "ch_sdmmc_sdio.h" +#include "ch_sdmmc_trace.h" +/*---------------------------------------------------------------------------- + * Definitions + *----------------------------------------------------------------------------*/ + +/** + * \brief Access the SD/MMC Library instances owned by the application. + * Used upon calls from the FatFs Module. + * + * Shall be implemented by the application. + */ +extern bool CC_WEAK sdmmcGetInstance(uint8_t index, SdmmcDriver **sdmmcp) ; + +/*---------------------------------------------------------------------------- + * Exported functions + *----------------------------------------------------------------------------*/ + +/** + * \brief Initialize a Drive. + * \param slot Physical drive number (0..). + * \return Drive status flags; STA_NOINIT if the specified drive does not exist. + */ +DSTATUS disk_initialize(BYTE slot) +{ + SdmmcDriver *sdmmcp = NULL; + uint8_t rc; + + if (!sdmmcGetInstance(slot, &sdmmcp)) + return STA_NOINIT; + + + rc = SD_GetStatus(sdmmcp); + + if (rc == SDMMC_NOT_SUPPORTED) + return STA_NODISK | STA_NOINIT; +#if 0 + if (sdmmcp->state != MCID_IDLE ) + sdmmc_device_deInit(sdmmcp); + + /* FIXME a delay with the bus held off may be required by the device */ + rc = sdmmc_device_start(sdmmcp); + + if (rc == SDMMC_OK) { + rc = sdmmc_device_identify(sdmmcp); + } +#endif + + return rc == SDMMC_OK ? 0 : STA_NOINIT; +} + +/** + * \brief Get Drive Status. + * \param slot Physical drive number (0..). + * \return Drive status flags; STA_NODISK if there is currently no device in + * the specified slot. + */ +DSTATUS disk_status(BYTE slot) +{ + SdmmcDriver *sdmmcp = NULL; + uint8_t rc; + + if (!sdmmcGetInstance(slot, &sdmmcp)) + return STA_NODISK | STA_NOINIT; + + rc = SD_GetStatus(sdmmcp); + + if (rc == SDMMC_NOT_SUPPORTED) + return STA_NODISK | STA_NOINIT; + else if (rc != SDMMC_OK) + return STA_NOINIT; + /* Well, no restriction on this drive */ + return 0; +} + +/** + * \brief Read Sector(s). + * \param slot Physical drive number (0..). + * \param buff Data buffer to store read data. + * \param sector Sector address in LBA. + * \param count Number of sectors to read. + * \return Result code; RES_OK if successful. + */ +DRESULT disk_read(BYTE slot, BYTE* buff, DWORD sector, UINT count) +{ + SdmmcDriver *sdmmcp = NULL; + DRESULT res; + uint32_t blk_size, addr = sector, len = count; + uint8_t rc; + + if (!sdmmcGetInstance(slot, &sdmmcp)) + return RES_PARERR; + + blk_size = sdmmcp->card.wBlockSize; + + if (blk_size == 0) + return RES_NOTRDY; + + if (blk_size < FF_MIN_SS) { + if (FF_MIN_SS % blk_size) + return RES_PARERR; + addr = sector * (FF_MIN_SS / blk_size); + len = count * (FF_MIN_SS / blk_size); + } + + if (count <= 1) + rc = SD_ReadBlocks(sdmmcp, addr, buff, len); + else + rc = SD_Read(sdmmcp, addr, buff, len); + + if (rc == SDMMC_OK || rc == SDMMC_CHANGED) + res = RES_OK; + else if (rc == SDMMC_ERR_IO || rc == SDMMC_ERR_RESP || rc == SDMMC_ERR) + res = RES_ERROR; + else if (rc == SDMMC_NO_RESPONSE || rc == SDMMC_BUSY + || rc == SDMMC_NOT_INITIALIZED || rc == SDMMC_LOCKED + || rc == SDMMC_STATE || rc == SDMMC_USER_CANCEL) + res = RES_NOTRDY; + else if (rc == SDMMC_PARAM || rc == SDMMC_NOT_SUPPORTED) + res = RES_PARERR; + else + res = RES_ERROR; + + return res; +} + +#if !FF_FS_READONLY +/** + * \brief Write Sector(s). + * + * \param slot Physical drive number (0..). + * \param buff Data to be written. + * \param sector Sector address in LBA. + * \param count Number of sectors to write. + * \return Result code; RES_OK if successful. + * + * \note The FatFs module will issue multiple sector transfer request + * (count > 1) to the disk I/O layer. The disk function should process + * the multiple sector transfer properly. Do not translate it into + * multiple single sector transfers to the media, or the data read/write + * performance may be drastically decreased. + */ +DRESULT disk_write(BYTE slot, const BYTE* buff, DWORD sector, UINT count) +{ + SdmmcDriver *sdmmcp = NULL; + DRESULT res; + uint32_t blk_size, addr = sector, len = count; + uint8_t rc; + + if (!sdmmcGetInstance(slot, &sdmmcp)) + return RES_PARERR; + + blk_size = sdmmcp->card.wBlockSize; + + if (blk_size < FF_MIN_SS) { + if (FF_MIN_SS % blk_size) + return RES_PARERR; + addr = sector * (FF_MIN_SS / blk_size); + len = count * (FF_MIN_SS / blk_size); + } + if (count <= 1) + rc = SD_WriteBlocks(sdmmcp, addr, buff, len); + else + rc = SD_Write(sdmmcp, addr, buff, len); + + if (rc == SDMMC_OK || rc == SDMMC_CHANGED) + res = RES_OK; + else if (rc == SDMMC_ERR_IO || rc == SDMMC_ERR_RESP || rc == SDMMC_ERR) + res = RES_ERROR; + else if (rc == SDMMC_NO_RESPONSE || rc == SDMMC_BUSY + || rc == SDMMC_NOT_INITIALIZED || rc == SDMMC_LOCKED + || rc == SDMMC_STATE || rc == SDMMC_USER_CANCEL) + res = RES_NOTRDY; + else if (rc == SDMMC_PARAM || rc == SDMMC_NOT_SUPPORTED) + res = RES_PARERR; + else + res = RES_ERROR; + return res; +} +#endif /* _FS_READONLY */ + +/** + * \brief Miscellaneous Functions. + * \param slot Physical drive number (0..). + * \param cmd Control code. + * \param buff Buffer to send/receive control data. + * \return Result code; RES_OK if successful. + */ +DRESULT disk_ioctl(BYTE slot, BYTE cmd, void* buff) +{ + SdmmcDriver *sdmmcp = NULL; + DRESULT res; + DWORD *param_u32 = (DWORD *)buff; + WORD *param_u16 = (WORD *)buff; + uint32_t blk_size, blk_count; + + if (!sdmmcGetInstance(slot, &sdmmcp)) + return RES_PARERR; + + switch (cmd) + { + case CTRL_SYNC: + /* SD/MMC devices do not seem to cache data beyond completion + * of the write commands. Note that if _FS_READONLY is enabled, + * this command is not needed. */ + res = RES_OK; + break; + + case GET_SECTOR_COUNT: + if (!buff) + return RES_PARERR; + blk_size = sdmmcp->card.wBlockSize; + blk_count = sdmmcp->card.dwNbBlocks; + + if (blk_size < FF_MIN_SS) + { + if (FF_MIN_SS % blk_size) + return RES_PARERR; + *param_u32 = blk_count / (FF_MIN_SS / blk_size); + } + else + *param_u32 = blk_count; + res = RES_OK; + break; + + case GET_SECTOR_SIZE: + /* Note that if _MAX_SS equals _MIN_SS i.e. the drive does not + * have to support several sector sizes, this command is not + * needed. */ + if (!buff) + return RES_PARERR; + blk_size = sdmmcp->card.wBlockSize; + *param_u16 = blk_size >= FF_MIN_SS ? blk_size : FF_MIN_SS; + res = RES_OK; + break; + + case GET_BLOCK_SIZE: + if (!buff) + return RES_PARERR; + /* On SD/MMC devices, erase block size is the same as write + * block size. + * Hence, erasing as little as one sector is allowed. */ + *param_u32 = 1; + res = RES_OK; + break; + + case CTRL_TRIM: + /* This TRIM-like command is not implemented. + * It would be required if _USE_TRIM was enabled. */ + res = RES_PARERR; + break; + + default: + res = RES_PARERR; + break; + } + return res; +} +#endif +#endif + diff --git a/os/various/fatfs_bindings/SAMA5D2x/fatfs.mk b/os/various/fatfs_bindings/SAMA5D2x/fatfs.mk new file mode 100644 index 000000000..fbdeeece2 --- /dev/null +++ b/os/various/fatfs_bindings/SAMA5D2x/fatfs.mk @@ -0,0 +1,12 @@ +# FATFS files. +FATFSSRC = $(CHIBIOS)/os/various/syscalls.c \ + $(CHIBIOS)/os/various/fatfs_bindings/SAMA5D2x/ch_sdmmc_ff.c \ + $(CHIBIOS)/os/various/fatfs_bindings/fatfs_syscall.c \ + $(CHIBIOS)/ext/fatfs/src/ff.c \ + $(CHIBIOS)/ext/fatfs/src/ffunicode.c + +FATFSINC = $(CHIBIOS)/ext/fatfs/src + +# Shared variables +ALLCSRC += $(FATFSSRC) +ALLINC += $(FATFSINC) diff --git a/os/various/fatfs_bindings/SAMA5D2x/readme.txt b/os/various/fatfs_bindings/SAMA5D2x/readme.txt new file mode 100644 index 000000000..b44f832ef --- /dev/null +++ b/os/various/fatfs_bindings/SAMA5D2x/readme.txt @@ -0,0 +1,13 @@ +This directory contains the ChibiOS/RT "official" bindings with the FatFS for the +library by ChaN: http://elm-chan.org + +In order to use FatFS within ChibiOS/RT project: +1. unzip FatFS under ./ext/fatfs [See Note 2] +2. include $(CHIBIOS)/os/various/fatfs_bindings/SAMA5D2x/fatfs.mk in your makefile. +3. Add $(FATFSSRC) to $(CSRC) +4. Add $(FATFSINC) to $(INCDIR) + +Note: +1. These files modified for use with version 0.13 of fatfs. +2. In the original distribution, the source directory is called 'source' rather than 'src' +3. this implementation is for SAMA5D2X diff --git a/os/various/reledge_bindings/SAMA5D2x/ch_sdmmc_reledge.c b/os/various/reledge_bindings/SAMA5D2x/ch_sdmmc_reledge.c new file mode 100644 index 000000000..31630c081 --- /dev/null +++ b/os/various/reledge_bindings/SAMA5D2x/ch_sdmmc_reledge.c @@ -0,0 +1,64 @@ +#include "hal.h" + +#if (HAL_USE_SDMMC == TRUE) + +#include "sama_sdmmc_lld.h" + +#include "ch_sdmmc_device.h" +#include "ch_sdmmc_cmds.h" +#include "ch_sdmmc_sdio.h" +#include "ch_sdmmc_sd.h" +#include "ch_sdmmc_mmc.h" + +#include "ch_sdmmc_reledge.h" + +eSDMMC_RC sd_mmc_test_unit_ready( SdmmcDriver *sdmmcp) +{ + + uint32_t rc; + + if (sdmmc_is_busy(sdmmcp)) + return SDMMC_BUSY; + + rc = SD_GetStatus(sdmmcp); + + if (rc != SDMMC_OK) + { + return rc; + } + + + if ( !(sdmmcp->card.bCardType == CARD_UNKNOWN) ) { + return SDMMC_OK; + } + // It is not a memory card + return SDMMC_ERR; + +} + +bool sd_mmc_is_write_protected(SdmmcDriver *sdmmcp) +{ + uint32_t rc; + + rc = SD_GetWpStatus(sdmmcp); + + return (rc == SDMMC_LOCKED); +} + + + +eSDMMC_RC sd_mmc_read_capacity(SdmmcDriver *sdmmcp, uint32_t *nb_sector) +{ + // Return last sector address (-1) + *nb_sector = sdmmcp->card.dwNbBlocks - 1; + + return sd_mmc_test_unit_ready(sdmmcp); +} + + + + + +#endif + + diff --git a/os/various/reledge_bindings/SAMA5D2x/ch_sdmmc_reledge.h b/os/various/reledge_bindings/SAMA5D2x/ch_sdmmc_reledge.h new file mode 100644 index 000000000..04ed471cf --- /dev/null +++ b/os/various/reledge_bindings/SAMA5D2x/ch_sdmmc_reledge.h @@ -0,0 +1,14 @@ + +#ifndef CH_SDMMC_RELEDGE_H_ +#define CH_SDMMC_RELEDGE_H_ + + + + +extern eSDMMC_RC sd_mmc_test_unit_ready( SdmmcDriver *sdmmcp); +extern bool sd_mmc_is_write_protected(SdmmcDriver *sdmmcp); +extern eSDMMC_RC sd_mmc_read_capacity(SdmmcDriver *sdmmcp, uint32_t *nb_sector); + + + +#endif /* CH_SDMMC_RELEDGE_H_ */ diff --git a/os/various/reledge_bindings/SAMA5D2x/osassert.c b/os/various/reledge_bindings/SAMA5D2x/osassert.c new file mode 100644 index 000000000..c4cc20497 --- /dev/null +++ b/os/various/reledge_bindings/SAMA5D2x/osassert.c @@ -0,0 +1,62 @@ +/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- + + Copyright (c) 2014-2017 Datalight, Inc. + All Rights Reserved Worldwide. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; use version 2 of the License. + + This program is distributed in the hope that it will be useful, + but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +/* Businesses and individuals that for commercial or other reasons cannot + comply with the terms of the GPLv2 license may obtain a commercial license + before incorporating Reliance Edge into proprietary software for + distribution in any form. Visit http://www.datalight.com/reliance-edge for + more information. +*/ +/** @file + @brief Implements assertion handling. +*/ +#include "hal.h" +#if (HAL_USE_SDMMC == TRUE) +#include "sama_sdmmc_lld.h" +#if SDMMC_USE_RELEDGE_LIB == 1 +#include + +#if REDCONF_ASSERTS == 1 + +#include + + +/** @brief Invoke the native assertion handler. + + @param pszFileName Null-terminated string containing the name of the file + where the assertion fired. + @param ulLineNum Line number in @p pszFileName where the assertion + fired. +*/ +void RedOsAssertFail( + const char *pszFileName, + uint32_t ulLineNum) +{ + #if REDCONF_OUTPUT == 1 + IGNORE_ERRORS(PRINT_ASSERT(pszFileName, ulLineNum)); + #endif + + while(true) + { + } +} + +#endif + +#endif +#endif diff --git a/os/various/reledge_bindings/SAMA5D2x/osbdev.c b/os/various/reledge_bindings/SAMA5D2x/osbdev.c new file mode 100644 index 000000000..645201521 --- /dev/null +++ b/os/various/reledge_bindings/SAMA5D2x/osbdev.c @@ -0,0 +1,515 @@ +/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- + + Copyright (c) 2014-2017 Datalight, Inc. + All Rights Reserved Worldwide. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; use version 2 of the License. + + This program is distributed in the hope that it will be useful, + but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +/* Businesses and individuals that for commercial or other reasons cannot + comply with the terms of the GPLv2 license may obtain a commercial license + before incorporating Reliance Edge into proprietary software for + distribution in any form. Visit http://www.datalight.com/reliance-edge for + more information. +*/ +/** @file + @brief Implements block device I/O. +*/ +#include "hal.h" + +#if (HAL_USE_SDMMC == TRUE) +#include "sama_sdmmc_lld.h" +#if SDMMC_USE_RELEDGE_LIB == 1 + +#include "sama_sdmmc_lld.h" +#include "ch_sdmmc_device.h" +#include "ch_sdmmc_cmds.h" +#include "ch_sdmmc_sdio.h" +#include "ch_sdmmc_sd.h" +#include "ch_sdmmc_mmc.h" +#include "ch_sdmmc_reledge.h" + +#include +#include +#include + +#if REDCONF_API_POSIX == 0 +#error "REDCONF_API_POSIX should be 1" +#endif + +#if REDCONF_API_FSE == 1 +#error "REDCONF_API_FSE not supported, should be 0" +#endif + + +/* sd_mmc_mem_2_ram_multi() and sd_mmc_ram_2_mem_multi() use an unsigned + 16-bit value to specify the sector count, so no transfer can be larger + than UINT16_MAX sectors. +*/ +#define MAX_SECTOR_TRANSFER UINT16_MAX + + +/** @brief Initialize a disk. + + @param bVolNum The volume number of the volume whose block device is being + initialized. + @param mode The open mode, indicating the type of access required. + + @return A negated ::REDSTATUS code indicating the operation result. + + @retval 0 Operation was successful. + @retval -RED_EIO A disk I/O error occurred. + @retval -RED_EROFS The device is read-only media and write access was + requested. +*/ +static REDSTATUS DiskOpen( + uint8_t bVolNum, + BDEVOPENMODE mode) +{ + REDSTATUS ret = 0; + uint32_t ulTries; + + + eSDMMC_RC cs; + + SdmmcDriver *sdmmcp = NULL; + + + if (!sdmmcGetInstance(bVolNum, &sdmmcp)) + return RED_EINVAL; + + /* Note: Assuming the volume number is the same as the SD card slot. The + ASF SD/MMC driver supports two SD slots. This implementation will need + to be modified if multiple volumes share a single SD card. + */ + + /* The first time the disk is opened, the SD card can take a while to get + ready, in which time sd_mmc_test_unit_ready() returns either CTRL_BUSY + or CTRL_NO_PRESENT. Try numerous times, waiting half a second after + each failure. Empirically, this has been observed to succeed on the + second try, so trying 10x more than that provides a margin of error. + */ + for(ulTries = 0U; ulTries < 20U; ulTries++) + { + cs = sd_mmc_test_unit_ready(sdmmcp); + + if((cs != SDMMC_OK) && (cs != SDMMC_BUSY)) + { + break; + } + + // t_msleep(sdmmcp,500); + } + + if(cs == SDMMC_OK) + { + #if REDCONF_READ_ONLY == 0 + if(mode != BDEV_O_RDONLY) + { + if(sd_mmc_is_write_protected(sdmmcp)) + { + ret = -RED_EROFS; + } + } + + if(ret == 0) + #endif + { + uint32_t ulSectorLast; + + IGNORE_ERRORS(sd_mmc_read_capacity(sdmmcp, &ulSectorLast)); + + /* The ASF SD/MMC driver only supports 512-byte sectors. + */ + if( (gaRedVolConf[bVolNum].ulSectorSize != 512U) + || (((uint64_t)ulSectorLast + 1U) < gaRedVolConf[bVolNum].ullSectorCount)) + { + ret = -RED_EINVAL; + } + } + } + else + { + ret = -RED_EIO; + } + + return ret; +} + + +/** @brief Uninitialize a disk. + + @param bVolNum The volume number of the volume whose block device is being + uninitialized. + + @return A negated ::REDSTATUS code indicating the operation result. + + @retval 0 Operation was successful. +*/ +static REDSTATUS DiskClose( + uint8_t bVolNum) +{ + (void)bVolNum; + return 0; +} + + +/** @brief Read sectors from a disk. + + @param bVolNum The volume number of the volume whose block device + is being read from. + @param ullSectorStart The starting sector number. + @param ulSectorCount The number of sectors to read. + @param pBuffer The buffer into which to read the sector data. + + @return A negated ::REDSTATUS code indicating the operation result. + + @retval 0 Operation was successful. +*/ +static REDSTATUS DiskRead( + uint8_t bVolNum, + uint64_t ullSectorStart, + uint32_t ulSectorCount, + void *pBuffer) +{ + REDSTATUS ret = 0; + uint8_t *pbBuffer = CAST_VOID_PTR_TO_UINT8_PTR(pBuffer); + + SdmmcDriver *sdmmcp = NULL; + eSDMMC_RC cs; + + if (!sdmmcGetInstance(bVolNum, &sdmmcp)) + return RED_EINVAL; + + cs = SD_ReadBlocks(sdmmcp, ullSectorStart, pbBuffer,ulSectorCount); + + if(cs != SDMMC_OK) + { + ret = -RED_EIO; + } + + + return ret; +} + + +#if REDCONF_READ_ONLY == 0 + +/** @brief Write sectors to a disk. + + @param bVolNum The volume number of the volume whose block device + is being written to. + @param ullSectorStart The starting sector number. + @param ulSectorCount The number of sectors to write. + @param pBuffer The buffer from which to write the sector data. + + @return A negated ::REDSTATUS code indicating the operation result. + + @retval 0 Operation was successful. +*/ +static REDSTATUS DiskWrite( + uint8_t bVolNum, + uint64_t ullSectorStart, + uint32_t ulSectorCount, + const void *pBuffer) +{ + REDSTATUS ret = 0; + const uint8_t *pbBuffer = CAST_VOID_PTR_TO_CONST_UINT8_PTR(pBuffer); + + SdmmcDriver *sdmmcp = NULL; + eSDMMC_RC cs; + + if (!sdmmcGetInstance(bVolNum, &sdmmcp)) + return RED_EINVAL; + + + cs = SD_WriteBlocks(sdmmcp, ullSectorStart, pbBuffer, ulSectorCount); + if(cs != SDMMC_OK) + { + ret = -RED_EIO; + } + + + return ret; +} + + +/** @brief Flush any caches beneath the file system. + + @param bVolNum The volume number of the volume whose block device is being + flushed. + + @return A negated ::REDSTATUS code indicating the operation result. + + @retval 0 Operation was successful. +*/ +static REDSTATUS DiskFlush( + uint8_t bVolNum) +{ + REDSTATUS ret; + + eSDMMC_RC cs; + + SdmmcDriver *sdmmcp = NULL; + + + if (!sdmmcGetInstance(bVolNum, &sdmmcp)) + return RED_EINVAL; + + /* The ASF SD/MMC driver appears to write sectors synchronously, so it + should be fine to do nothing and return success. However, Atmel's + implementation of the FatFs diskio.c file does the equivalent of the + below when the disk is flushed. Just in case this is important for some + non-obvious reason, do the same. + */ + cs = sd_mmc_test_unit_ready(sdmmcp); + if(cs == SDMMC_OK) + { + ret = 0; + } + else + { + ret = -RED_EIO; + } + + return ret; +} + + +#if REDCONF_DISCARDS == 1 +/** @brief Discard sectors on a disk. + + @param bVolNum The volume number of the volume whose block device + is being accessed. + @param ullSectorStart The starting sector number. + @param ullSectorCount The number of sectors to discard. +*/ +static void DiskDiscard( + uint8_t bVolNum, + uint64_t ullSectorStart, + uint64_t ullSectorCount) +{ +#error "this SD/MMC driver does not support discards." +} +#endif /* REDCONF_DISCARDS == 1 */ + +#endif /* REDCONF_READ_ONLY == 0 */ + +/** @brief Initialize a block device. + + This function is called when the file system needs access to a block + device. + + Upon successful return, the block device should be fully initialized and + ready to service read/write/flush/close requests. + + The behavior of calling this function on a block device which is already + open is undefined. + + @param bVolNum The volume number of the volume whose block device is being + initialized. + @param mode The open mode, indicating the type of access required. + + @return A negated ::REDSTATUS code indicating the operation result. + + @retval 0 Operation was successful. + @retval -RED_EINVAL @p bVolNum is an invalid volume number. + @retval -RED_EIO A disk I/O error occurred. +*/ +REDSTATUS RedOsBDevOpen( + uint8_t bVolNum, + BDEVOPENMODE mode) +{ + REDSTATUS ret; + + if(bVolNum >= REDCONF_VOLUME_COUNT) + { + ret = -RED_EINVAL; + } + else + { + ret = DiskOpen(bVolNum, mode); + } + + return ret; +} + + +/** @brief Uninitialize a block device. + + This function is called when the file system no longer needs access to a + block device. If any resource were allocated by RedOsBDevOpen() to service + block device requests, they should be freed at this time. + + Upon successful return, the block device must be in such a state that it + can be opened again. + + The behavior of calling this function on a block device which is already + closed is undefined. + + @param bVolNum The volume number of the volume whose block device is being + uninitialized. + + @return A negated ::REDSTATUS code indicating the operation result. + + @retval 0 Operation was successful. + @retval -RED_EINVAL @p bVolNum is an invalid volume number. +*/ +REDSTATUS RedOsBDevClose( + uint8_t bVolNum) +{ + REDSTATUS ret; + + if(bVolNum >= REDCONF_VOLUME_COUNT) + { + ret = -RED_EINVAL; + } + else + { + ret = DiskClose(bVolNum); + } + + return ret; +} + + +/** @brief Read sectors from a physical block device. + + The behavior of calling this function is undefined if the block device is + closed or if it was opened with ::BDEV_O_WRONLY. + + @param bVolNum The volume number of the volume whose block device + is being read from. + @param ullSectorStart The starting sector number. + @param ulSectorCount The number of sectors to read. + @param pBuffer The buffer into which to read the sector data. + + @return A negated ::REDSTATUS code indicating the operation result. + + @retval 0 Operation was successful. + @retval -RED_EINVAL @p bVolNum is an invalid volume number, @p pBuffer is + `NULL`, or @p ullStartSector and/or @p ulSectorCount + refer to an invalid range of sectors. + @retval -RED_EIO A disk I/O error occurred. +*/ +REDSTATUS RedOsBDevRead( + uint8_t bVolNum, + uint64_t ullSectorStart, + uint32_t ulSectorCount, + void *pBuffer) +{ + REDSTATUS ret = 0; + + if( (bVolNum >= REDCONF_VOLUME_COUNT) + || (ullSectorStart >= gaRedVolConf[bVolNum].ullSectorCount) + || ((gaRedVolConf[bVolNum].ullSectorCount - ullSectorStart) < ulSectorCount) + || (pBuffer == NULL)) + { + ret = -RED_EINVAL; + } + else + { + ret = DiskRead(bVolNum, ullSectorStart, ulSectorCount, pBuffer); + } + + return ret; +} + + +#if REDCONF_READ_ONLY == 0 + +/** @brief Write sectors to a physical block device. + + The behavior of calling this function is undefined if the block device is + closed or if it was opened with ::BDEV_O_RDONLY. + + @param bVolNum The volume number of the volume whose block device + is being written to. + @param ullSectorStart The starting sector number. + @param ulSectorCount The number of sectors to write. + @param pBuffer The buffer from which to write the sector data. + + @return A negated ::REDSTATUS code indicating the operation result. + + @retval 0 Operation was successful. + @retval -RED_EINVAL @p bVolNum is an invalid volume number, @p pBuffer is + `NULL`, or @p ullStartSector and/or @p ulSectorCount + refer to an invalid range of sectors. + @retval -RED_EIO A disk I/O error occurred. +*/ +REDSTATUS RedOsBDevWrite( + uint8_t bVolNum, + uint64_t ullSectorStart, + uint32_t ulSectorCount, + const void *pBuffer) +{ + REDSTATUS ret = 0; + + if( (bVolNum >= REDCONF_VOLUME_COUNT) + || (ullSectorStart >= gaRedVolConf[bVolNum].ullSectorCount) + || ((gaRedVolConf[bVolNum].ullSectorCount - ullSectorStart) < ulSectorCount) + || (pBuffer == NULL)) + { + ret = -RED_EINVAL; + } + else + { + ret = DiskWrite(bVolNum, ullSectorStart, ulSectorCount, pBuffer); + } + + return ret; +} + + +/** @brief Flush any caches beneath the file system. + + This function must synchronously flush all software and hardware caches + beneath the file system, ensuring that all sectors written previously are + committed to permanent storage. + + If the environment has no caching beneath the file system, the + implementation of this function can do nothing and return success. + + The behavior of calling this function is undefined if the block device is + closed or if it was opened with ::BDEV_O_RDONLY. + + @param bVolNum The volume number of the volume whose block device is being + flushed. + + @return A negated ::REDSTATUS code indicating the operation result. + + @retval 0 Operation was successful. + @retval -RED_EINVAL @p bVolNum is an invalid volume number. + @retval -RED_EIO A disk I/O error occurred. +*/ +REDSTATUS RedOsBDevFlush( + uint8_t bVolNum) +{ + REDSTATUS ret; + + if(bVolNum >= REDCONF_VOLUME_COUNT) + { + ret = -RED_EINVAL; + } + else + { + ret = DiskFlush(bVolNum); + } + + return ret; +} + +#endif /* REDCONF_READ_ONLY == 0 */ +#endif + +#endif diff --git a/os/various/reledge_bindings/SAMA5D2x/osclock.c b/os/various/reledge_bindings/SAMA5D2x/osclock.c new file mode 100644 index 000000000..e140e6e28 --- /dev/null +++ b/os/various/reledge_bindings/SAMA5D2x/osclock.c @@ -0,0 +1,85 @@ +/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- + + Copyright (c) 2014-2017 Datalight, Inc. + All Rights Reserved Worldwide. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; use version 2 of the License. + + This program is distributed in the hope that it will be useful, + but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +/* Businesses and individuals that for commercial or other reasons cannot + comply with the terms of the GPLv2 license may obtain a commercial license + before incorporating Reliance Edge into proprietary software for + distribution in any form. Visit http://www.datalight.com/reliance-edge for + more information. +*/ +/** @file + @brief Implements real-time clock functions. +*/ +#include "hal.h" +#if (HAL_USE_SDMMC == TRUE) +#include "sama_sdmmc_lld.h" +#if SDMMC_USE_RELEDGE_LIB == 1 +#include + + +/** @brief Initialize the real time clock. + + The behavior of calling this function when the RTC is already initialized + is undefined. + + @return A negated ::REDSTATUS code indicating the operation result. + + @retval 0 Operation was successful. +*/ +REDSTATUS RedOsClockInit(void) +{ + return 0; +} + + +/** @brief Uninitialize the real time clock. + + The behavior of calling this function when the RTC is not initialized is + undefined. + + @return A negated ::REDSTATUS code indicating the operation result. + + @retval 0 Operation was successful. +*/ +REDSTATUS RedOsClockUninit(void) +{ + return 0; +} + + +/** @brief Get the date/time. + + The behavior of calling this function when the RTC is not initialized is + undefined. + + @return The number of seconds since January 1, 1970 excluding leap seconds + (in other words, standard Unix time). If the resolution or epoch + of the RTC is different than this, the implementation must convert + it to the expected representation. +*/ +uint32_t RedOsClockGetTime(void) +{ + /* FreeRTOS does not provide an RTC abstraction since most of the systems + it targets have no RTC hardware. If your hardware includes an RTC that + you would like to use, this function must be customized. + */ + return 0; +} +#endif +#endif + diff --git a/os/various/reledge_bindings/SAMA5D2x/osmutex.c b/os/various/reledge_bindings/SAMA5D2x/osmutex.c new file mode 100644 index 000000000..b921a8aa9 --- /dev/null +++ b/os/various/reledge_bindings/SAMA5D2x/osmutex.c @@ -0,0 +1,108 @@ +/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- + + Copyright (c) 2014-2017 Datalight, Inc. + All Rights Reserved Worldwide. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; use version 2 of the License. + + This program is distributed in the hope that it will be useful, + but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +/* Businesses and individuals that for commercial or other reasons cannot + comply with the terms of the GPLv2 license may obtain a commercial license + before incorporating Reliance Edge into proprietary software for + distribution in any form. Visit http://www.datalight.com/reliance-edge for + more information. +*/ +/** @file + @brief Implements a synchronization object to provide mutual exclusion. +*/ +#include "ch.h" +#include "hal.h" +#if (HAL_USE_SDMMC == TRUE) +#include "sama_sdmmc_lld.h" +#if SDMMC_USE_RELEDGE_LIB == 1 +#include +#include + +#if REDCONF_TASK_COUNT > 1U + + +static semaphore_t red_sem; + + +/** @brief Initialize the mutex. + + After initialization, the mutex is in the released state. + + The behavior of calling this function when the mutex is still initialized + is undefined. + + @return A negated ::REDSTATUS code indicating the operation result. + + @retval 0 Operation was successful. +*/ +REDSTATUS RedOsMutexInit(void) +{ + chSemObjectInit(&red_sem, 1); + + return 0; +} + + +/** @brief Uninitialize the mutex. + + The behavior of calling this function when the mutex is not initialized is + undefined; likewise, the behavior of uninitializing the mutex when it is + in the acquired state is undefined. + + @return A negated ::REDSTATUS code indicating the operation result. + + @retval 0 Operation was successful. +*/ +REDSTATUS RedOsMutexUninit(void) +{ + chSemReset(&red_sem, 0); + + return 0; +} + + +/** @brief Acquire the mutex. + + The behavior of calling this function when the mutex is not initialized is + undefined; likewise, the behavior of recursively acquiring the mutex is + undefined. +*/ +void RedOsMutexAcquire(void) +{ + chSemWaitTimeout(&red_sem, TIME_INFINITE); +} + + +/** @brief Release the mutex. + + The behavior is undefined in the following cases: + + - Releasing the mutex when the mutex is not initialized. + - Releasing the mutex when it is not in the acquired state. + - Releasing the mutex from a task or thread other than the one which + acquired the mutex. +*/ +void RedOsMutexRelease(void) +{ + chSemSignal(&red_sem); +} + +#endif +#endif +#endif + diff --git a/os/various/reledge_bindings/SAMA5D2x/osoutput.c b/os/various/reledge_bindings/SAMA5D2x/osoutput.c new file mode 100644 index 000000000..bff230522 --- /dev/null +++ b/os/various/reledge_bindings/SAMA5D2x/osoutput.c @@ -0,0 +1,76 @@ +/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- + + Copyright (c) 2014-2017 Datalight, Inc. + All Rights Reserved Worldwide. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; use version 2 of the License. + + This program is distributed in the hope that it will be useful, + but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +/* Businesses and individuals that for commercial or other reasons cannot + comply with the terms of the GPLv2 license may obtain a commercial license + before incorporating Reliance Edge into proprietary software for + distribution in any form. Visit http://www.datalight.com/reliance-edge for + more information. +*/ +/** @file + @brief Implements outputting a character string. +*/ +#include "hal.h" +#if (HAL_USE_SDMMC == TRUE) +#include "sama_sdmmc_lld.h" +#if SDMMC_USE_RELEDGE_LIB == 1 +#include + +#if REDCONF_OUTPUT == 1 + +#include + + +/** @brief Write a string to a user-visible output location. + + Write a null-terminated string to the serial port, console, terminal, or + other display device, such that the text is visible to the user. + + @param pszString A null-terminated string. +*/ +void RedOsOutputString( + const char *pszString) +{ + if(pszString == NULL) + { + REDERROR(); + } + else + { + uint32_t ulIdx = 0U; + + while(pszString[ulIdx] != '\0') + { + OUTPUT_CHARACTER(pszString[ulIdx]); + + /* Serial output often requires a \r to print newlines correctly. + */ + if(pszString[ulIdx] == '\n') + { + OUTPUT_CHARACTER('\r'); + } + + ulIdx++; + } + } +} + +#endif + +#endif +#endif diff --git a/os/various/reledge_bindings/SAMA5D2x/ostask.c b/os/various/reledge_bindings/SAMA5D2x/ostask.c new file mode 100644 index 000000000..f06f00f22 --- /dev/null +++ b/os/various/reledge_bindings/SAMA5D2x/ostask.c @@ -0,0 +1,68 @@ +/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- + + Copyright (c) 2014-2017 Datalight, Inc. + All Rights Reserved Worldwide. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; use version 2 of the License. + + This program is distributed in the hope that it will be useful, + but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +/* Businesses and individuals that for commercial or other reasons cannot + comply with the terms of the GPLv2 license may obtain a commercial license + before incorporating Reliance Edge into proprietary software for + distribution in any form. Visit http://www.datalight.com/reliance-edge for + more information. +*/ +/** @file + @brief Implements task functions. +*/ +#include "ch.h" +#include "hal.h" +#if (HAL_USE_SDMMC == TRUE) +#include "sama_sdmmc_lld.h" +#if SDMMC_USE_RELEDGE_LIB == 1 +#include + +#if (REDCONF_TASK_COUNT > 1U) && (REDCONF_API_POSIX == 1) + +#include + + +/** @brief Get the current task ID. + + This task ID must be unique for all tasks using the file system. + + @return The task ID. Must not be 0. +*/ +uint32_t RedOsTaskId(void) +{ + /* Simply casting the xTaskGetCurrentTaskHandle() return value results in + warnings from some compilers, so use variables. + */ + thread_t* t= chThdGetSelfX(); + uintptr_t taskptr = CAST_TASK_PTR_TO_UINTPTR(t); + uint32_t ulTaskPtr = (uint32_t)taskptr; + + /* Assert no information was lost casting from uintptr_t to uint32_t. + */ + REDASSERT(ulTaskPtr == taskptr); + + /* NULL is a valid task handle in FreeRTOS, so add one to all task IDs. + */ + REDASSERT((ulTaskPtr + 1U) != 0U); + return ulTaskPtr + 1U; +} + +#endif + +#endif +#endif diff --git a/os/various/reledge_bindings/SAMA5D2x/readme.txt b/os/various/reledge_bindings/SAMA5D2x/readme.txt new file mode 100644 index 000000000..9cd07d397 --- /dev/null +++ b/os/various/reledge_bindings/SAMA5D2x/readme.txt @@ -0,0 +1,12 @@ +This directory contains the ChibiOS/RT "official" bindings with the RelianceEdge +library by Datalight : https://github.com/datalightinc/reliance-edge + +In order to use Reliance Edge within ChibiOS/RT project: +1. unzip Reliance Edge under $(CHIBIOS)/ext/reliance-edge +2. include $(CHIBIOS)/os/various/reledge_bindings/SAMA5D2x/reledge.mk in your makefile. +3. Add $(RELEDGESRC) to $(CSRC) +4. Add $(RELEDGEINC) to $(INCDIR) + +Note: +1. These files modified for use with version 2.2 of reliance edge + diff --git a/os/various/reledge_bindings/SAMA5D2x/redosdeviations.h b/os/various/reledge_bindings/SAMA5D2x/redosdeviations.h new file mode 100644 index 000000000..b00fc4184 --- /dev/null +++ b/os/various/reledge_bindings/SAMA5D2x/redosdeviations.h @@ -0,0 +1,245 @@ +/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- + + Copyright (c) 2014-2017 Datalight, Inc. + All Rights Reserved Worldwide. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; use version 2 of the License. + + This program is distributed in the hope that it will be useful, + but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +/* Businesses and individuals that for commercial or other reasons cannot + comply with the terms of the GPLv2 license may obtain a commercial license + before incorporating Reliance Edge into proprietary software for + distribution in any form. Visit http://www.datalight.com/reliance-edge for + more information. +*/ +/** @file + @brief Macros to encapsulate MISRA C:2012 deviations in OS-specific code. +*/ +#ifndef REDOSDEVIATIONS_H +#define REDOSDEVIATIONS_H + + +#if REDCONF_OUTPUT == 1 +/* Needed for PRINT_ASSERT() and OUTPUT_CHARACTER(). +*/ +#include +#endif + + +#if (REDCONF_ASSERTS == 1) && (REDCONF_OUTPUT == 1) +/** @brief Print a formatted message for an assertion. + + Usages of this macro deviate from MISRA C:2012 Rule 21.6 (required). Using + printf() is the most convenient way to output this information; and the risk + of "unspecified, undefined and implementation-defined" behavior causing + problems (as cited in the rationale for the rule) is small. The driver does + not depend on this string being outputted correctly. Furthermore, use of + printf() disappears when either asserts or output are disabled. + + As Rule 21.6 is required, a separate deviation record is required. +*/ +#define PRINT_ASSERT(file, line) \ + printf("Assertion failed in \"%s\" at line %u\n\r", ((file) == NULL) ? "" : (file), (unsigned)(line)) +#endif + + +/** @brief Cast a value to unsigned long. + + Usages of this macro deviate from MISRA C:2012 Directive 4.6. This macro is + used in two places to cast a uint64_t value (used by the block device + abstraction for sector numbers) to unsigned long, since third-party code + which is not under the control of this project uses unsigned long for sector + numbers. The cast is guaranteed to not lose any information, since when the + disk is opened the sector count is verified to be less than or equal to an + unsigned long value. The text of the directive mentions that "it might be + desirable not to apply this guideline when interfacing with ... code outside + the project's control", which describes the situation for this deviation. + + As Directive 4.6 is advisory, a deviation record is not required. This + notice is the only record of the deviation. +*/ +#define CAST_ULONG(ull) ((unsigned long)(ull)) + + +/** @brief Cast a const-qualified pointer to a pointer which is *not* + const-qualified. + + Usages of this macro deviate from MISRA C:2012 Rule 11.8. This macro is + used in exactly one place in order to cope with a poorly designed + third-party interface. Reliance Edge, at every level of the stack, uses + const-qualified pointers for buffers used in write operations, since the + data is read from the buffer, and the buffer does not need to be modified + (consistent with Rule 8.13). One of the third-party block device interfaces + that Reliance Edge interfaces with does not follow this convention: it uses + an unqualified pointer for the buffer parameter of its sector write + function. This forces the need for the cast to avoid warnings. The + implementation of the sector write function is provided by the user, so it + is to be hoped that the buffer is not actually modified. + + As Rule 11.8 is required, a separate deviation record is required. +*/ +#define CAST_AWAY_CONST(type, ptr) ((type *)(ptr)) + + +/** @brief Allocate zero-initialized (cleared) memory. + + All usages of this macro deviate from MISRA C:2012 Directive 4.12 (required) + and Rule 21.3 (required). In the context of the single place it is actually + used, this macro also deviates from Rule 22.1 (required). + + This macro is used in the FreeRTOS block device code in order to allocate a + RAM disk, when that implementation of the block device is selected. The + primary rationale for all these deviations is that a) the RAM disk cannot be + allocated statically (since the volume information is stored in a + structure), and b) the RAM disk is primarily intended as a temporary testing + tool for users who want to try out Reliance Edge before the real storage + media is available. In most real systems, Reliance Edge is used with + non-volatile storage like SD/MMC or eMMC, not with RAM disks. + + Rule 22.1 states that all resources which are allocated must also be + explicitly freed. The RAM disk is allocated and never freed, deviating from + that rule. This is done because the data in the RAM disk is emulating a + non-volatile storage medium, and thus needs to persist even after the block + device is closed, to allow the file system to be ormatted and then mounted, + or unmounted and remounted in the course of a test. Thus the memory will + remain allocated until the target device is rebooted. This is assumed to be + acceptable for the primary purpose of the RAM disk, which is preliminary + testing. + + As Directive 4.12, Rule 21.3, and Rule 22.1 are all required, separate + deviation records are required. +*/ +#define ALLOCATE_CLEARED_MEMORY(nelem, elsize) calloc(nelem, elsize) + + +#if REDCONF_OUTPUT == 1 +/** @brief Output a character to a serial port or other display device. + + Usages of this macro deviate from MISRA C:2012 Rule 21.6 (required). + FreeRTOS does not include a standard method of printing characters, so + putchar() is the most convenient and portable way to accomplish the task. + The risk of "unspecified, undefined and implementation-defined" behavior + causing problems (as cited in the rationale for the rule) is small. The + driver does not depend on the character being outputted correctly. + Furthermore, use of putchar() disappears when output is disabled. + + As Rule 21.6 is required, a separate deviation record is required. +*/ +#define OUTPUT_CHARACTER(ch) (void)putchar(ch) +#endif + + +#if (REDCONF_TASK_COUNT > 1U) && (REDCONF_API_POSIX == 1) +/** @brief Cast a TaskHandle_t (a pointer type) to uintptr_t. + + Usage of this macro deivate from MISRA-C:2012 Rule 11.4 (advisory). This + macro is used for the FreeRTOS version of RedOsTaskId(). Some RTOSes + natively use an integer for task IDs; others use pointers. RedOsTaskId() + uses integers, FreeRTOS uses pointers; to reconcile this difference, the + pointer must be cast to integer. This is fairly safe, since the resulting + integer is never cast back to a pointer; and although the integer + representation of a pointer is implementation-defined, the representation is + irrelevant provided that unique pointers are converted to unique integers. + + As Rule 11.4 is advisory, a deviation record is not required. This notice + is the only record of the deviation. +*/ +#define CAST_TASK_PTR_TO_UINTPTR(taskptr) ((uintptr_t)(taskptr)) +#endif + + +/** @brief Ignore the return value of a function (cast to void) + + Usages of this macro deviate from MISRA C:2012 Directive 4.7, which states + that error information must be checked immediately after a function returns + potential error information. + + If asserts and output are enabled, then this macro is used to document that + the return value of printf() is ignored. A failure of printf() does not + impact the filesystem core, nor is there anything the filesystem can do to + respond to such an error (especially since it occurs within an assert). + Thus, the most reasonable action is to ignore the error. + + In the STM32 SDIO block device implementation, errors are also ignored in an + IRQ interrupt handler. This is the most reasonable action to take for two + reasons: (a) it would be dangerous to spend processor time responding to the + error inside the IRQ handler; (b) it has been verified that the same error + is propegated to the DiskRead/Write method, which does return the error to + the core. + + In the Atmel SD/MMC block device implementation, error information from + sd_mmc_read_capacity() is ignored. This is a reasonable action because all + of the possible error conditions were eliminated by a previous check. + sd_mmc_read_capacity() fails under the same conditions as + sd_mmc_test_unit_ready(), which was checked ealier in the same function. + + In the mutex module, error information returned from the mutex release + function is ignored when asserts are disabled. This is a reasonable action + because the mutex release function (xSemaphoreGive) is documented only to + fail if the mutex was not obtained correctly, which can be demonstrably + avoided. + + As Directive 4.7 is required, a separate deviation record is required. +*/ +#define IGNORE_ERRORS(fn) ((void) (fn)) + + +/** @brief Determine whether a pointer is aligned on a 32-bit boundary. + + This is used to determine whether a data buffer meets the requirements of + the underlying block device implementation. When transferring data via + DMA (Direct Memory Access) on an STM32 device, the data buffer must be cast + as a uint32 pointer, and unexpected behavior may occur if the buffer is not + aligned correctly. + + There is no way to perform this check without deviating from MISRA C rules + against casting pointers to integer types. Usage of this macro deviates + from MISRA C:2012 Rule 11.4 (advisory). The main rationale the rule cites + against converting pointers to integers is that the chosen integer type may + not be able to represent the pointer; this is a non-issue here since we use + uintptr_t. The text says the rule still applies when using uintptr_t due to + concern about unaligned pointers, but that is not an issue here since the + integer value of the pointer is not saved and not converted back into a + pointer and dereferenced. The result of casting a pointer to a sufficiently + large integer is implementation-defined, but macros similar to this one have + been used by Datalight for a long time in a wide variety of environments and + they have always worked as expected. + + This deviation only occurs when using the STM32 SDIO block device + implementation. + + As Rule 11.4 is advisory, a deviation record is not required. This notice + is the only record of deviation. +*/ +#define IS_UINT32_ALIGNED_PTR(ptr) (((uintptr_t)(ptr) & (sizeof(uint32_t) - 1U)) == 0U) + + +/** @brief Cast a 32-bit aligned void pointer to a uint32 pointer. + + Usages of this macro deviate from MISRA C:2012 Rule 11.5 (advisory). A + cast from a void pointer to an object pointer is discouraged because of + potential alignment issues. However, this macro is only used to cast + pointers that have already been tested to be 32-bit aligned, so the + operation will be safe. + + This deviation only occurs when using the STM32 SDIO block device + implementation. + + As rule 11.5 is advisory, a deviation record is not required. This notice + is the only record of the deviation. +*/ +#define CAST_UINT32_PTR(ptr) ((uint32_t *) (ptr)) + + +#endif + diff --git a/os/various/reledge_bindings/SAMA5D2x/redostypes.h b/os/various/reledge_bindings/SAMA5D2x/redostypes.h new file mode 100644 index 000000000..687b2d167 --- /dev/null +++ b/os/various/reledge_bindings/SAMA5D2x/redostypes.h @@ -0,0 +1,42 @@ +/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- + + Copyright (c) 2014-2017 Datalight, Inc. + All Rights Reserved Worldwide. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; use version 2 of the License. + + This program is distributed in the hope that it will be useful, + but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +/* Businesses and individuals that for commercial or other reasons cannot + comply with the terms of the GPLv2 license may obtain a commercial license + before incorporating Reliance Edge into proprietary software for + distribution in any form. Visit http://www.datalight.com/reliance-edge for + more information. +*/ +/** @file + @brief Defines OS-specific types for use in common code. +*/ +#ifndef REDOSTYPES_H +#define REDOSTYPES_H + + +/** @brief Implementation-defined timestamp type. + + This can be an integer, a structure, or a pointer: anything that is + convenient for the implementation. Since the underlying type is not fixed, + common code should treat this as an opaque type. +*/ +typedef uint32_t REDTIMESTAMP; + + +#endif + diff --git a/os/various/reledge_bindings/SAMA5D2x/redtypes.h b/os/various/reledge_bindings/SAMA5D2x/redtypes.h new file mode 100644 index 000000000..bb5606eef --- /dev/null +++ b/os/various/reledge_bindings/SAMA5D2x/redtypes.h @@ -0,0 +1,98 @@ +/* ----> DO NOT REMOVE THE FOLLOWING NOTICE <---- + + Copyright (c) 2014-2017 Datalight, Inc. + All Rights Reserved Worldwide. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; use version 2 of the License. + + This program is distributed in the hope that it will be useful, + but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +/* Businesses and individuals that for commercial or other reasons cannot + comply with the terms of the GPLv2 license may obtain a commercial license + before incorporating Reliance Edge into proprietary software for + distribution in any form. Visit http://www.datalight.com/reliance-edge for + more information. +*/ +/** @file + @brief Defines basic types used by Reliance Edge. + + The following types *must* be defined by this header, either directly (using + typedef) or indirectly (by including other headers, such as the C99 headers + stdint.h and stdbool.h): + + - bool: Boolean type, capable of storing true (1) or false (0) + - uint8_t: Unsigned 8-bit integer + - int8_t: Signed 8-bit integer + - uint16_t: Unsigned 16-bit integer + - int16_t: Signed 16-bit integer + - uint32_t: Unsigned 32-bit integer + - int32_t: Signed 32-bit integer + - uint64_t: Unsigned 64-bit integer + - int64_t: Signed 64-bit integer + - uintptr_t: Unsigned integer capable of storing a pointer, preferably the + same size as pointers themselves. + + These types deliberately use the same names as the standard C99 types, so + that if the C99 headers stdint.h and stdbool.h are available, they may be + included here. + + If the user application defines similar types, those may be reused. For + example, suppose there is an application header apptypes.h which defines + types with a similar purpose but different names. That header could be + reused to define the types Reliance Edge needs: + + ~~~{.c} + #include + + typedef BOOL bool; + typedef BYTE uint8_t; + typedef INT8 int8_t; + // And so on... + ~~~ + + If there are neither C99 headers nor suitable types in application headers, + this header should be populated with typedefs that define the required types + in terms of the standard C types. This requires knowledge of the size of + the C types on the target hardware (e.g., how big is an "int" or a pointer). + Below is an example which assumes the target has 8-bit chars, 16-bit shorts, + 32-bit ints, 32-bit pointers, and 64-bit long longs: + + ~~~{.c} + typedef int bool; + typedef unsigned char uint8_t; + typedef signed char int8_t; + typedef unsigned short uint16_t; + typedef short int16_t; + typedef unsigned int uint32_t; + typedef int int32_t; + typedef unsigned long long uint64_t; + typedef long long int64_t; + typedef uint32_t uintptr_t; + ~~~ +*/ +#ifndef REDTYPES_H +#define REDTYPES_H + +#include "hal.h" + +/* Defines bool. +*/ +//#include + +/* Defines uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, + int64_t, and uintptr_t. +*/ +//#include + + +#endif + diff --git a/os/various/reledge_bindings/SAMA5D2x/reledge.mk b/os/various/reledge_bindings/SAMA5D2x/reledge.mk new file mode 100644 index 000000000..d014120cb --- /dev/null +++ b/os/various/reledge_bindings/SAMA5D2x/reledge.mk @@ -0,0 +1,41 @@ +# RELIANCE EDGE files. + +RELEDGESRC= \ + $(CHIBIOS)/ext/reliance-edge/core/driver/blockio.c \ + $(CHIBIOS)/ext/reliance-edge/core/driver/buffer.c \ + $(CHIBIOS)/ext/reliance-edge/core/driver/core.c \ + $(CHIBIOS)/ext/reliance-edge/core/driver/dir.c \ + $(CHIBIOS)/ext/reliance-edge/core/driver/format.c \ + $(CHIBIOS)/ext/reliance-edge/core/driver/imap.c \ + $(CHIBIOS)/ext/reliance-edge/core/driver/imapextern.c \ + $(CHIBIOS)/ext/reliance-edge/core/driver/imapinline.c \ + $(CHIBIOS)/ext/reliance-edge/core/driver/inode.c \ + $(CHIBIOS)/ext/reliance-edge/core/driver/inodedata.c \ + $(CHIBIOS)/ext/reliance-edge/core/driver/volume.c \ + $(CHIBIOS)/ext/reliance-edge/fse/fse.c \ + $(CHIBIOS)/ext/reliance-edge/posix/path.c \ + $(CHIBIOS)/ext/reliance-edge/posix/posix.c \ + $(CHIBIOS)/ext/reliance-edge/util/bitmap.c \ + $(CHIBIOS)/ext/reliance-edge/util/crc.c \ + $(CHIBIOS)/ext/reliance-edge/util/memory.c \ + $(CHIBIOS)/ext/reliance-edge/util/namelen.c \ + $(CHIBIOS)/ext/reliance-edge/util/sign.c \ + $(CHIBIOS)/ext/reliance-edge/util/string.c + +RELEDGEINC = $(CHIBIOS)/ext/reliance-edge/include \ + $(CHIBIOS)/ext/reliance-edge/core/include + +RELEDGEBINDINC = $(CHIBIOS)/os/various/reledge_bindings/SAMA5D2x + +RELEDGEBINDSRC = \ + $(CHIBIOS)/os/various/reledge_bindings/SAMA5D2x/ch_sdmmc_reledge.c \ + $(CHIBIOS)/os/various/reledge_bindings/SAMA5D2x/osassert.c \ + $(CHIBIOS)/os/various/reledge_bindings/SAMA5D2x/osbdev.c \ + $(CHIBIOS)/os/various/reledge_bindings/SAMA5D2x/osclock.c \ + $(CHIBIOS)/os/various/reledge_bindings/SAMA5D2x/osmutex.c \ + $(CHIBIOS)/os/various/reledge_bindings/SAMA5D2x/osoutput.c \ + $(CHIBIOS)/os/various/reledge_bindings/SAMA5D2x/ostask.c + +# Shared variables +ALLCSRC += $(RELEDGESRC) $(RELEDGEBINDSRC) +ALLINC += $(RELEDGEINC) $(RELEDGEBINDINC) \ No newline at end of file diff --git a/os/various/reledge_bindings/readme.txt b/os/various/reledge_bindings/readme.txt deleted file mode 100644 index 4489695c1..000000000 --- a/os/various/reledge_bindings/readme.txt +++ /dev/null @@ -1,12 +0,0 @@ -This directory contains the ChibiOS/RT "official" bindings with the RelianceEdge -library by Datalight : https://github.com/datalightinc/reliance-edge - -In order to use Reliance Edge within ChibiOS/RT project: -1. unzip Reliance Edge under reliance-edge -2. include $(CHIBIOS)/os/various/reledge_bindings/reledge.mk in your makefile. -3. Add $(RELEDGESRC) to $(CSRC) -4. Add $(RELEDGEINC) to $(INCDIR) - -Note: -1. These files modified for use with version 2.2 of reliance edge - diff --git a/os/various/reledge_bindings/reledge.mk b/os/various/reledge_bindings/reledge.mk deleted file mode 100644 index c85b7f659..000000000 --- a/os/various/reledge_bindings/reledge.mk +++ /dev/null @@ -1,30 +0,0 @@ -# RELIANCE EDGE files. - -RELEDGESRC= \ - $(CHIBIOS)/ext/reliance-edge/core/driver/blockio.c \ - $(CHIBIOS)/ext/reliance-edge/core/driver/buffer.c \ - $(CHIBIOS)/ext/reliance-edge/core/driver/core.c \ - $(CHIBIOS)/ext/reliance-edge/core/driver/dir.c \ - $(CHIBIOS)/ext/reliance-edge/core/driver/format.c \ - $(CHIBIOS)/ext/reliance-edge/core/driver/imap.c \ - $(CHIBIOS)/ext/reliance-edge/core/driver/imapextern.c \ - $(CHIBIOS)/ext/reliance-edge/core/driver/imapinline.c \ - $(CHIBIOS)/ext/reliance-edge/core/driver/inode.c \ - $(CHIBIOS)/ext/reliance-edge/core/driver/inodedata.c \ - $(CHIBIOS)/ext/reliance-edge/core/driver/volume.c \ - $(CHIBIOS)/ext/reliance-edge/fse/fse.c \ - $(CHIBIOS)/ext/reliance-edge/posix/path.c \ - $(CHIBIOS)/ext/reliance-edge/posix/posix.c \ - $(CHIBIOS)/ext/reliance-edge/util/bitmap.c \ - $(CHIBIOS)/ext/reliance-edge/util/crc.c \ - $(CHIBIOS)/ext/reliance-edge/util/memory.c \ - $(CHIBIOS)/ext/reliance-edge/util/namelen.c \ - $(CHIBIOS)/ext/reliance-edge/util/sign.c \ - $(CHIBIOS)/ext/reliance-edge/util/string.c - -RELEDGEINC = $(CHIBIOS)/ext/reliance-edge/include \ - $(CHIBIOS)/ext/reliance-edge/core/include - -# Shared variables -ALLCSRC += $(RELEDGESRC) -ALLINC += $(RELEDGEINC) \ No newline at end of file diff --git a/testhal/ATSAMA5D2/SDMMC/Makefile b/testhal/ATSAMA5D2/SDMMC/Makefile index 1a69f01f9..b9a924d9f 100644 --- a/testhal/ATSAMA5D2/SDMMC/Makefile +++ b/testhal/ATSAMA5D2/SDMMC/Makefile @@ -127,27 +127,20 @@ include $(CHIBIOS)/os/hal/osal/rt/osal.mk include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/common/ports/ARMCAx-TZ/compilers/GCC/mk/port_generic.mk # Other files (optional). -#include $(CHIBIOS)/test/lib/test.mk -#include $(CHIBIOS)/test/rt/rt_test.mk -#include $(CHIBIOS)/test/oslib/oslib_test.mk -include $(CHIBIOS)/os/various/reledge_bindings/reledge.mk -#include $(CHIBIOS)/os/various/fatfs_bindings/fatfs.mk +include $(CHIBIOS)/os/various/reledge_bindings/SAMA5D2x/reledge.mk +include $(CHIBIOS)/os/various/fatfs_bindings/SAMA5D2x/fatfs.mk include $(CHIBIOS)/os/hal/lib/streams/streams.mk # Define linker script file here #LDSCRIPT= $(STARTUPLD)/SAMA5D2.ld LDSCRIPT= $(STARTUPLD)/SAMA5D2ddr.ld -FATFSINC = $(CHIBIOS)/ext/fatfs/src + # C sources that can be compiled in ARM or THUMB mode depending on the global # setting. CSRC = $(ALLCSRC) \ main.c fat32test.c reledgetest.c redconf.c -CSRC += $(CHIBIOS)/os/various/syscalls.c -CSRC += $(CHIBIOS)/os/various/fatfs_bindings/fatfs_syscall.c -CSRC += $(CHIBIOS)/ext/fatfs/src/ff.c -CSRC += $(CHIBIOS)/ext/fatfs/src/ffunicode.c # C++ sources that can be compiled in ARM or THUMB mode depending on the global # setting. @@ -228,7 +221,7 @@ CPPWARN = -Wall -Wextra -Wundef # # List all user C define here, like -D_DEBUG=1 -UDEFS = -DPLATFORM_SDMMC_USE_SDMMC1=1 +UDEFS = -DPLATFORM_SDMMC_USE_SDMMC1=1 -DHAL_USE_TRNG=FALSE -DSDMMC_USE_RELEDGE_LIB=1 -DSDMMC_USE_FF_LIB=1 # Define ASM defines here UADEFS = diff --git a/testhal/ATSAMA5D2/SDMMC/main.c b/testhal/ATSAMA5D2/SDMMC/main.c index 0030167c5..9c2a026c4 100644 --- a/testhal/ATSAMA5D2/SDMMC/main.c +++ b/testhal/ATSAMA5D2/SDMMC/main.c @@ -18,14 +18,20 @@ #include "hal.h" #include "sama_sdmmc_lld.h" #include "chprintf.h" + +#if SDMMC_USE_FF_LIB == 1 #include "fat32test.h" +#endif + +#if SDMMC_USE_RELEDGE_LIB == 1 #include "reledgetest.h" +#endif //----------- DEMO CONFIGURATION ------------------------ //0 (SLOT0) or 1 (SLOT1) #define DEMO_SLOT 0 //1 for FFLib, 0 for Reliance -#define DEMO_FAT 0 +#define DEMO_FAT 1 //---------------------------------------------------------- #define BLOCK_CNT_MAX 32u @@ -118,9 +124,13 @@ int main(void) { if (sdmmcOpenDevice(&SDMMCD1)) { #if DEMO_FAT == 1 +#if SDMMC_USE_FF_LIB == 1 fat32test_demo(); +#endif #else +#if SDMMC_USE_RELEDGE_LIB == 1 relianceedge_demo(); +#endif #endif if (SDMMCD1.config->slot_id == SDMMC_SLOT1) @@ -157,7 +167,8 @@ bool sdmmcGetInstance(uint8_t index, SdmmcDriver **sdmmcp) (void)index; *sdmmcp = &SDMMCD1; - read(); + + //read(); return true; } -- cgit v1.2.3