Run all .c and .h files in previous commits through nxstyle.

This commit is contained in:
Gregory Nutt
2020-03-21 13:54:03 -06:00
committed by Xiang Xiao
parent 533528af01
commit 547a3cb3d9
15 changed files with 1043 additions and 766 deletions
+58 -24
View File
@@ -33,6 +33,10 @@
* *
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <sys/types.h> #include <sys/types.h>
@@ -55,6 +59,10 @@
#include "hardware/cxd56_emmc.h" #include "hardware/cxd56_emmc.h"
#include "cxd56_pinconfig.h" #include "cxd56_pinconfig.h"
/****************************************************************************
* Pre-processoro Definitions
****************************************************************************/
#define SECTOR_SIZE (512) #define SECTOR_SIZE (512)
#define EMMC_DATA_WRITE 0 #define EMMC_DATA_WRITE 0
@@ -67,7 +75,27 @@
#define EMMC_RESP_R2 3 #define EMMC_RESP_R2 3
#define EMMC_RESP_R3 4 #define EMMC_RESP_R3 4
struct emmc_dma_desc_s { #define EMMC_CLKDIV_UNDER_400KHZ (32u)
#define EMMC_CLKDIV_NON_DIV (0u)
#define EMMC_RCA (2) /* greater than 1 */
#define EMMC_DATA_TIMEOUT (0xFFFFFFu) /* max reg value */
#define EMMC_RESP_TIMEOUT (0xFFu) /* max reg value */
#define EMMC_MSIZE (6) /* Burst size is 512B */
#define EMMC_FIFO_DEPTH (0x100) /* FIFO size is 1KB */
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
/****************************************************************************
* Private Types
****************************************************************************/
struct emmc_dma_desc_s
{
uint32_t ctrl; uint32_t ctrl;
uint32_t size; uint32_t size;
uint32_t addr; uint32_t addr;
@@ -81,6 +109,10 @@ struct cxd56_emmc_state_s
uint32_t total_sectors; uint32_t total_sectors;
}; };
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/* Block driver interfaces **************************************************/ /* Block driver interfaces **************************************************/
static int cxd56_emmc_open(FAR struct inode *inode); static int cxd56_emmc_open(FAR struct inode *inode);
@@ -98,6 +130,10 @@ static int cxd56_emmc_geometry(FAR struct inode *inode,
struct geometry *geometry); struct geometry *geometry);
static int emmc_interrupt(int irq, FAR void *context, FAR void *arg); static int emmc_interrupt(int irq, FAR void *context, FAR void *arg);
/****************************************************************************
* Private Data
****************************************************************************/
static const struct block_operations g_bops = static const struct block_operations g_bops =
{ {
cxd56_emmc_open, /* open */ cxd56_emmc_open, /* open */
@@ -106,29 +142,18 @@ static const struct block_operations g_bops =
#if !defined(CONFIG_MMCSD_READONLY) #if !defined(CONFIG_MMCSD_READONLY)
cxd56_emmc_write, /* write */ cxd56_emmc_write, /* write */
#else #else
NULL, /* write */ NULL, /* write */
#endif #endif
cxd56_emmc_geometry, /* geometry */ cxd56_emmc_geometry, /* geometry */
NULL /* ioctl */ NULL /* ioctl */
}; };
static sem_t g_waitsem; static sem_t g_waitsem;
struct cxd56_emmc_state_s g_emmcdev; struct cxd56_emmc_state_s g_emmcdev;
#define EMMC_CLKDIV_UNDER_400KHZ (32u) /****************************************************************************
#define EMMC_CLKDIV_NON_DIV (0u) * Private Functions
****************************************************************************/
#define EMMC_RCA (2) /* greater than 1 */
#define EMMC_DATA_TIMEOUT (0xFFFFFFu) /* max reg value */
#define EMMC_RESP_TIMEOUT (0xFFu) /* max reg value */
#define EMMC_MSIZE (6) /* Burst size is 512B */
#define EMMC_FIFO_DEPTH (0x100) /* FIFO size is 1KB */
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
static void emmc_takesem(FAR sem_t *sem) static void emmc_takesem(FAR sem_t *sem)
{ {
@@ -308,9 +333,9 @@ static struct emmc_dma_desc_s *emmc_setupdma(void *buf, unsigned int nbytes)
/* Adjust first and last descriptor members */ /* Adjust first and last descriptor members */
descs[0].ctrl |= EMMC_IDMAC_DES0_FD; descs[0].ctrl |= EMMC_IDMAC_DES0_FD;
descs[ndescs-1].ctrl |= EMMC_IDMAC_DES0_LD; descs[ndescs - 1].ctrl |= EMMC_IDMAC_DES0_LD;
descs[ndescs-1].next = 0; descs[ndescs - 1].next = 0;
#ifdef CONFIG_DEBUG_VERBOSE #ifdef CONFIG_DEBUG_VERBOSE
for (i = 0, d = descs; i < ndescs; i++, d++) for (i = 0, d = descs; i < ndescs; i++, d++)
@@ -341,6 +366,7 @@ static int emmc_checkresponse(void)
ferr("Response error %08x\n", resp); ferr("Response error %08x\n", resp);
return -EIO; return -EIO;
} }
return OK; return OK;
} }
@@ -454,6 +480,7 @@ static int emmc_is_powerup(void)
{ {
return 0; return 0;
} }
up_mdelay(5); up_mdelay(5);
} }
while (--retry); while (--retry);
@@ -716,7 +743,7 @@ static int cxd56_emmc_readsectors(FAR struct cxd56_emmc_state_s *priv,
ret = -EIO; ret = -EIO;
} }
finish: finish:
emmc_givesem(&priv->excsem); emmc_givesem(&priv->excsem);
kmm_free(descs); kmm_free(descs);
@@ -787,7 +814,7 @@ static int cxd56_emmc_writesectors(FAR struct cxd56_emmc_state_s *priv,
emmc_flushwritefifo(); emmc_flushwritefifo();
finish: finish:
emmc_givesem(&priv->excsem); emmc_givesem(&priv->excsem);
kmm_free(descs); kmm_free(descs);
@@ -826,8 +853,9 @@ static int cxd56_emmc_close(FAR struct inode *inode)
return OK; return OK;
} }
static ssize_t cxd56_emmc_read(FAR struct inode *inode, unsigned char *buffer, static ssize_t cxd56_emmc_read(FAR struct inode *inode,
size_t start_sector, unsigned int nsectors) unsigned char *buffer, size_t start_sector,
unsigned int nsectors)
{ {
FAR struct cxd56_emmc_state_s *priv; FAR struct cxd56_emmc_state_s *priv;
int ret; int ret;
@@ -927,9 +955,11 @@ int cxd56_emmcinitialize(void)
kmm_free(buf); kmm_free(buf);
return -EIO; return -EIO;
} }
priv->total_sectors = *(FAR uint32_t *)&buf[EXTCSD_SEC_COUNT]; priv->total_sectors = *(FAR uint32_t *)&buf[EXTCSD_SEC_COUNT];
kmm_free(descs); kmm_free(descs);
} }
kmm_free(buf); kmm_free(buf);
} }
@@ -943,6 +973,10 @@ int cxd56_emmcinitialize(void)
return OK; return OK;
} }
/****************************************************************************
* Public Functions
****************************************************************************/
int emmc_uninitialize(void) int emmc_uninitialize(void)
{ {
/* Send power off command */ /* Send power off command */
+15 -8
View File
@@ -78,10 +78,13 @@ static int mmcl_open(FAR struct inode *inode);
static int mmcl_close(FAR struct inode *inode); static int mmcl_close(FAR struct inode *inode);
static ssize_t mmcl_read(FAR struct inode *inode, unsigned char *buffer, static ssize_t mmcl_read(FAR struct inode *inode, unsigned char *buffer,
size_t start_sector, unsigned int nsectors); size_t start_sector, unsigned int nsectors);
static ssize_t mmcl_write(FAR struct inode *inode, const unsigned char *buffer, static ssize_t mmcl_write(FAR struct inode *inode,
size_t start_sector, unsigned int nsectors); const unsigned char *buffer, size_t start_sector,
static int mmcl_geometry(FAR struct inode *inode, struct geometry *geometry); unsigned int nsectors);
static int mmcl_ioctl(FAR struct inode *inode, int cmd, unsigned long arg); static int mmcl_geometry(FAR struct inode *inode,
struct geometry *geometry);
static int mmcl_ioctl(FAR struct inode *inode, int cmd,
unsigned long arg);
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
@@ -163,8 +166,9 @@ static ssize_t mmcl_read(FAR struct inode *inode, unsigned char *buffer,
* *
****************************************************************************/ ****************************************************************************/
static ssize_t mmcl_write(FAR struct inode *inode, const unsigned char *buffer, static ssize_t mmcl_write(FAR struct inode *inode,
size_t start_sector, unsigned int nsectors) const unsigned char *buffer, size_t start_sector,
unsigned int nsectors)
{ {
ssize_t nwrite; ssize_t nwrite;
struct mmcl_dev_s *dev; struct mmcl_dev_s *dev;
@@ -249,7 +253,8 @@ static int mmcl_ioctl(FAR struct inode *inode, int cmd, unsigned long arg)
* Name: mmcl_allocdev * Name: mmcl_allocdev
****************************************************************************/ ****************************************************************************/
static FAR struct mmcl_dev_s *mmcl_allocdev(int number, FAR struct mtd_dev_s *mtd) static FAR struct mmcl_dev_s *mmcl_allocdev(int number,
FAR struct mtd_dev_s *mtd)
{ {
struct mmcl_dev_s *dev; struct mmcl_dev_s *dev;
int ret; int ret;
@@ -268,7 +273,8 @@ static FAR struct mmcl_dev_s *mmcl_allocdev(int number, FAR struct mtd_dev_s *mt
* from the size of a pointer). * from the size of a pointer).
*/ */
ret = MTD_IOCTL(mtd, MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&dev->geo)); ret = MTD_IOCTL(mtd, MTDIOC_GEOMETRY,
(unsigned long)((uintptr_t)&dev->geo));
if (ret < 0) if (ret < 0)
{ {
finfo("MTD ioctl(MTDIOC_GEOMETRY) failed: %d\n", ret); finfo("MTD ioctl(MTDIOC_GEOMETRY) failed: %d\n", ret);
@@ -317,6 +323,7 @@ int mmcl_initialize(int minor, FAR struct mtd_dev_s *mtd)
CONFIG_MTD_DEVPATH1, CONFIG_MTD_DEVPATH1,
#endif #endif
}; };
int ret = -ENOMEM; int ret = -ENOMEM;
/* Sanity check */ /* Sanity check */
@@ -65,9 +65,9 @@
#include "stm32l476vg-disco.h" #include "stm32l476vg-disco.h"
/* Conditional logic in stm32l476vg-disco.h will determine if certain features /* Conditional logic in stm32l476vg-disco.h will determine if certain
* are supported. Tests for these features need to be made after including * features are supported. Tests for these features need to be made after
* stm32l476vg-disco.h. * including stm32l476vg-disco.h.
*/ */
#ifdef HAVE_RTC_DRIVER #ifdef HAVE_RTC_DRIVER
@@ -129,7 +129,7 @@ int board_app_initialize(uintptr_t arg)
FAR struct rtc_lowerhalf_s *rtclower; FAR struct rtc_lowerhalf_s *rtclower;
#endif #endif
#if defined(HAVE_N25QXXX) #if defined(HAVE_N25QXXX)
FAR struct mtd_dev_s *mtd_temp; FAR struct mtd_dev_s *mtd_temp;
#endif #endif
#if defined(HAVE_N25QXXX_CHARDEV) #if defined(HAVE_N25QXXX_CHARDEV)
char blockdev[18]; char blockdev[18];
@@ -197,34 +197,35 @@ FAR struct mtd_dev_s *mtd_temp;
_err("ERROR: n25qxxx_initialize failed\n"); _err("ERROR: n25qxxx_initialize failed\n");
return ret; return ret;
} }
g_mtd_fs = mtd_temp; g_mtd_fs = mtd_temp;
#ifdef CONFIG_MTD_PARTITION #ifdef CONFIG_MTD_PARTITION
{ {
FAR struct mtd_geometry_s geo; FAR struct mtd_geometry_s geo;
off_t nblocks; off_t nblocks;
/* Setup a partition of 256KiB for our file system. */ /* Setup a partition of 256KiB for our file system. */
ret = MTD_IOCTL(g_mtd_fs, MTDIOC_GEOMETRY, ret = MTD_IOCTL(g_mtd_fs, MTDIOC_GEOMETRY,
(unsigned long)(uintptr_t)&geo); (unsigned long)(uintptr_t)&geo);
if (ret < 0) if (ret < 0)
{ {
_err("ERROR: MTDIOC_GEOMETRY failed\n"); _err("ERROR: MTDIOC_GEOMETRY failed\n");
return ret; return ret;
} }
nblocks = (256*1024) / geo.blocksize; nblocks = (256 * 1024) / geo.blocksize;
mtd_temp = mtd_partition(g_mtd_fs, 0, nblocks); mtd_temp = mtd_partition(g_mtd_fs, 0, nblocks);
if (!mtd_temp) if (!mtd_temp)
{ {
_err("ERROR: mtd_partition failed\n"); _err("ERROR: mtd_partition failed\n");
return ret; return ret;
} }
g_mtd_fs = mtd_temp; g_mtd_fs = mtd_temp;
} }
#endif #endif
#ifdef HAVE_N25QXXX_SMARTFS #ifdef HAVE_N25QXXX_SMARTFS
+68 -76
View File
@@ -1,35 +1,20 @@
/**************************************************************************** /****************************************************************************
* boards/boardctl.c * boards/boardctl.c
* *
* Copyright (C) 2015-2017, 2018-2019 Gregory Nutt. All rights reserved. * Licensed to the Apache Software Foundation (ASF) under one or more
* Author: Gregory Nutt <gnutt@nuttx.org> * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* *
* Redistribution and use in source and binary forms, with or without * http://www.apache.org/licenses/LICENSE-2.0
* modification, are permitted provided that the following conditions
* are met:
* *
* 1. Redistributions of source code must retain the above copyright * Unless required by applicable law or agreed to in writing, software
* notice, this list of conditions and the following disclaimer. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* 2. Redistributions in binary form must reproduce the above copyright * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* notice, this list of conditions and the following disclaimer in * License for the specific language governing permissions and limitations
* the documentation and/or other materials provided with the * under the License.
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
* *
****************************************************************************/ ****************************************************************************/
@@ -95,7 +80,8 @@
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_BOARDCTL_USBDEVCTRL #ifdef CONFIG_BOARDCTL_USBDEVCTRL
static inline int boardctl_usbdevctrl(FAR struct boardioc_usbdev_ctrl_s *ctrl) static inline int
boardctl_usbdevctrl(FAR struct boardioc_usbdev_ctrl_s *ctrl)
{ {
int ret = OK; int ret = OK;
@@ -297,10 +283,10 @@ static inline int boardctl_pmctrl(FAR struct boardioc_pm_ctrl_s *ctrl)
* to "correct" but awkward implementations. * to "correct" but awkward implementations.
* *
* boardctl() is non-standard OS interface to alleviate the problem. It * boardctl() is non-standard OS interface to alleviate the problem. It
* basically circumvents the normal device driver ioctl interlace and allows * basically circumvents the normal device driver ioctl interlace and
* the application to perform direction IOCTL-like calls to the board-specific * allows the application to perform direction IOCTL-like calls to the
* logic. In it is especially useful for setting up board operational and * board-specific logic. In it is especially useful for setting up board
* test configurations. * operational and test configurations.
* *
* Input Parameters: * Input Parameters:
* cmd - Identifies the board command to be executed * cmd - Identifies the board command to be executed
@@ -322,16 +308,16 @@ int boardctl(unsigned int cmd, uintptr_t arg)
/* CMD: BOARDIOC_INIT /* CMD: BOARDIOC_INIT
* DESCRIPTION: Perform one-time application initialization. * DESCRIPTION: Perform one-time application initialization.
* ARG: The boardctl() argument is passed to the * ARG: The boardctl() argument is passed to the
* board_app_initialize() implementation without modification. * board_app_initialize() implementation without
* The argument has no meaning to NuttX; the meaning of the * modification. The argument has no meaning to NuttX;
* argument is a contract between the board-specific * the meaning of the argument is a contract between
* initialization logic and the matching application logic. * the board-specific initialization logic and the
* The value cold be such things as a mode enumeration value, * matching application logic. The value cold be such
* a set of DIP switch switch settings, a pointer to * things as a mode enumeration value, a set of DIP
* configuration data read from a file or serial FLASH, or * switch switch settings, a pointer to configuration
* whatever you would like to do with it. Every * data read from a file or serial FLASH, or whatever
* implementation should accept zero/NULL as a default * you would like to do with it. Every implementation
* configuration. * should accept zero/NULL as a default configuration.
* CONFIGURATION: CONFIG_LIB_BOARDCTL * CONFIGURATION: CONFIG_LIB_BOARDCTL
* DEPENDENCIES: Board logic must provide board_app_initialization * DEPENDENCIES: Board logic must provide board_app_initialization
*/ */
@@ -411,8 +397,9 @@ int boardctl(unsigned int cmd, uintptr_t arg)
/* CMD: BOARDIOC_UNIQUEID /* CMD: BOARDIOC_UNIQUEID
* DESCRIPTION: Return a unique ID associated with the board (such * DESCRIPTION: Return a unique ID associated with the board (such
* as a serial number or a MAC address). * as a serial number or a MAC address).
* ARG: A writable array of size CONFIG_BOARDCTL_UNIQUEID_SIZE * ARG: A writable array of size
* in which to receive the board unique ID. * CONFIG_BOARDCTL_UNIQUEID_SIZE in which to receive
* the board unique ID.
* DEPENDENCIES: Board logic must provide the board_uniqueid() * DEPENDENCIES: Board logic must provide the board_uniqueid()
* interface. * interface.
*/ */
@@ -427,7 +414,8 @@ int boardctl(unsigned int cmd, uintptr_t arg)
#ifdef CONFIG_BOARDCTL_MKRD #ifdef CONFIG_BOARDCTL_MKRD
/* CMD: BOARDIOC_MKRD /* CMD: BOARDIOC_MKRD
* DESCRIPTION: Create a RAM disk * DESCRIPTION: Create a RAM disk
* ARG: Pointer to read-only instance of struct boardioc_mkrd_s. * ARG: Pointer to read-only instance of struct
* boardioc_mkrd_s.
* CONFIGURATION: CONFIG_BOARDCTL_MKRD * CONFIGURATION: CONFIG_BOARDCTL_MKRD
* DEPENDENCIES: None * DEPENDENCIES: None
*/ */
@@ -453,7 +441,8 @@ int boardctl(unsigned int cmd, uintptr_t arg)
#ifdef CONFIG_BOARDCTL_ROMDISK #ifdef CONFIG_BOARDCTL_ROMDISK
/* CMD: BOARDIOC_ROMDISK /* CMD: BOARDIOC_ROMDISK
* DESCRIPTION: Register * DESCRIPTION: Register
* ARG: Pointer to read-only instance of struct boardioc_romdisk_s. * ARG: Pointer to read-only instance of struct
* boardioc_romdisk_s.
* CONFIGURATION: CONFIG_BOARDCTL_ROMDISK * CONFIGURATION: CONFIG_BOARDCTL_ROMDISK
* DEPENDENCIES: None * DEPENDENCIES: None
*/ */
@@ -469,8 +458,8 @@ int boardctl(unsigned int cmd, uintptr_t arg)
} }
else else
{ {
ret = romdisk_register((int)desc->minor, desc->image, desc->nsectors, ret = romdisk_register((int)desc->minor, desc->image,
desc->sectsize); desc->nsectors, desc->sectsize);
} }
} }
break; break;
@@ -478,9 +467,9 @@ int boardctl(unsigned int cmd, uintptr_t arg)
#ifdef CONFIG_BOARDCTL_APP_SYMTAB #ifdef CONFIG_BOARDCTL_APP_SYMTAB
/* CMD: BOARDIOC_APP_SYMTAB /* CMD: BOARDIOC_APP_SYMTAB
* DESCRIPTION: Select the application symbol table. This symbol table * DESCRIPTION: Select the application symbol table. This symbol
* provides the symbol definitions exported to application * table provides the symbol definitions exported to
* code from application space. * application code from application space.
* ARG: A pointer to an instance of struct boardioc_symtab_s * ARG: A pointer to an instance of struct boardioc_symtab_s
* CONFIGURATION: CONFIG_BOARDCTL_APP_SYMTAB * CONFIGURATION: CONFIG_BOARDCTL_APP_SYMTAB
* DEPENDENCIES: None * DEPENDENCIES: None
@@ -500,9 +489,9 @@ int boardctl(unsigned int cmd, uintptr_t arg)
#ifdef CONFIG_BOARDCTL_OS_SYMTAB #ifdef CONFIG_BOARDCTL_OS_SYMTAB
/* CMD: BOARDIOC_OS_SYMTAB /* CMD: BOARDIOC_OS_SYMTAB
* DESCRIPTION: Select the OS symbol table. This symbol table provides * DESCRIPTION: Select the OS symbol table. This symbol table
* the symbol definitions exported by the OS to kernel * provides the symbol definitions exported by the OS to
* modules. * kernal modules.
* ARG: A pointer to an instance of struct boardioc_symtab_s * ARG: A pointer to an instance of struct boardioc_symtab_s
* CONFIGURATION: CONFIG_BOARDCTL_OS_SYMTAB * CONFIGURATION: CONFIG_BOARDCTL_OS_SYMTAB
* DEPENDENCIES: None * DEPENDENCIES: None
@@ -522,17 +511,18 @@ int boardctl(unsigned int cmd, uintptr_t arg)
#ifdef CONFIG_BUILTIN #ifdef CONFIG_BUILTIN
/* CMD: BOARDIOC_BUILTINS /* CMD: BOARDIOC_BUILTINS
* DESCRIPTION: Provide the user-space list of built-in applications for * DESCRIPTION: Provide the user-space list of built-in applications
* use by BINFS in protected mode. Normally this is small * for use by BINFS in protected mode. Normally this
* set of globals provided by user-space logic. It provides * is small set of globals provided by user-space
* name-value pairs for associating built-in application * logic. It provides name-value pairs for associating
* names with user-space entry point addresses. These * built-in application names with user-space entry
* globals are only needed for use by BINFS which executes * point addresses. These globals are only needed for
* built-in applications from kernel-space in PROTECTED mode. * use by BINFS which executes built-in applications
* In the FLAT build, the user space globals are readily * from kernel-space in PROTECTED mode. In the FLAT
* available. (BINFS is not supportable in KERNEL mode since * build, the user space globals are readily
* user-space address have no general meaning that * available. (BINFS is not supportable in KERNEL mode
* configuration). * since user-space address have no general meaning
* that configuration).
* ARG: A pointer to an instance of struct boardioc_builtin_s * ARG: A pointer to an instance of struct boardioc_builtin_s
* CONFIGURATION: This BOARDIOC command is always available when * CONFIGURATION: This BOARDIOC command is always available when
* CONFIG_BUILTIN is enabled, but does nothing unless * CONFIG_BUILTIN is enabled, but does nothing unless
@@ -557,7 +547,8 @@ int boardctl(unsigned int cmd, uintptr_t arg)
#ifdef CONFIG_BOARDCTL_USBDEVCTRL #ifdef CONFIG_BOARDCTL_USBDEVCTRL
/* CMD: BOARDIOC_USBDEV_CONTROL /* CMD: BOARDIOC_USBDEV_CONTROL
* DESCRIPTION: Manage USB device classes * DESCRIPTION: Manage USB device classes
* ARG: A pointer to an instance of struct boardioc_usbdev_ctrl_s * ARG: A pointer to an instance of struct
* boardioc_usbdev_ctrl_s
* CONFIGURATION: CONFIG_LIB_BOARDCTL && CONFIG_BOARDCTL_USBDEVCTRL * CONFIGURATION: CONFIG_LIB_BOARDCTL && CONFIG_BOARDCTL_USBDEVCTRL
* DEPENDENCIES: Board logic must provide board_<usbdev>_initialize() * DEPENDENCIES: Board logic must provide board_<usbdev>_initialize()
*/ */
@@ -673,9 +664,10 @@ int boardctl(unsigned int cmd, uintptr_t arg)
break; break;
/* CMD: BOARDIOC_NXTERM_IOCTL /* CMD: BOARDIOC_NXTERM_IOCTL
* DESCRIPTION: Create an NX terminal IOCTL command. Normal IOCTLs * DESCRIPTION: Create an NX terminal IOCTL command. Normal
* cannot be be performed in most graphics contexts since * IOCTLs cannot be be performed in most graphics
* the depend on the task holding an open file descriptor * contexts since the depend on the task holding an
* open file descriptor
* ARG: A reference readable/writable instance of struct * ARG: A reference readable/writable instance of struct
* boardioc_nxterm_ioctl_s * boardioc_nxterm_ioctl_s
* CONFIGURATION: CONFIG_NXTERM * CONFIGURATION: CONFIG_NXTERM
@@ -696,9 +688,9 @@ int boardctl(unsigned int cmd, uintptr_t arg)
#ifdef CONFIG_BOARDCTL_TESTSET #ifdef CONFIG_BOARDCTL_TESTSET
/* CMD: BOARDIOC_TESTSET /* CMD: BOARDIOC_TESTSET
* DESCRIPTION: Access architecture-specific up_testset() operation * DESCRIPTION: Access architecture-specific up_testset() operation
* ARG: A pointer to a write-able spinlock object. On success * ARG: A pointer to a write-able spinlock object. On
* the preceding spinlock state is returned: 0=unlocked, * success the preceding spinlock state is returned:
* 1=locked. * 0=unlocked, 1=locked.
* CONFIGURATION: CONFIG_BOARDCTL_TESTSET * CONFIGURATION: CONFIG_BOARDCTL_TESTSET
* DEPENDENCIES: Architecture-specific logic provides up_testset() * DEPENDENCIES: Architecture-specific logic provides up_testset()
*/ */
@@ -722,10 +714,10 @@ int boardctl(unsigned int cmd, uintptr_t arg)
default: default:
{ {
#ifdef CONFIG_BOARDCTL_IOCTL #ifdef CONFIG_BOARDCTL_IOCTL
/* Boards may also select CONFIG_BOARDCTL_IOCTL=y to enable board- /* Boards may also select CONFIG_BOARDCTL_IOCTL=y to enable
* specific commands. In this case, all commands not recognized * board-specific commands. In this case, all commands not
* by boardctl() will be forwarded to the board-provided board_ioctl() * recognized by boardctl() will be forwarded to the board-
* function. * provided board_ioctl() function.
*/ */
ret = board_ioctl(cmd, arg); ret = board_ioctl(cmd, arg);
+250 -210
View File
File diff suppressed because it is too large Load Diff
+142 -77
View File
@@ -82,6 +82,7 @@
#endif #endif
/* Slot struct info *********************************************************/ /* Slot struct info *********************************************************/
/* Slot status definitions */ /* Slot status definitions */
#define MMCSD_SLOTSTATUS_NOTREADY 0x01 /* Card not initialized */ #define MMCSD_SLOTSTATUS_NOTREADY 0x01 /* Card not initialized */
@@ -90,6 +91,7 @@
#define MMCSD_SLOTSTATUS_MEDIACHGD 0x08 /* Media changed in slot */ #define MMCSD_SLOTSTATUS_MEDIACHGD 0x08 /* Media changed in slot */
/* Values in the MMC/SD command table ***************************************/ /* Values in the MMC/SD command table ***************************************/
/* These define the value returned by the MMC/SD command */ /* These define the value returned by the MMC/SD command */
#define MMCSD_CMDRESP_R1 0 #define MMCSD_CMDRESP_R1 0
@@ -250,9 +252,9 @@ static struct mmcsd_slot_s g_mmcsdslot[CONFIG_MMCSD_NSLOTS];
static const uint32_t g_transpeedru[8] = static const uint32_t g_transpeedru[8] =
{ {
10000, /* 0: 100 Kbit/sec / 10 */ 10000, /* 0: 100 Kbit/sec / 10 */
100000, /* 1: 1 Mbit/sec / 10 */ 100000, /* 1: 1 Mbit/sec / 10 */
1000000, /* 2: 10 Mbit/sec / 10 */ 1000000, /* 2: 10 Mbit/sec / 10 */
10000000, /* 3: 100 Mbit/sec / 10 */ 10000000, /* 3: 100 Mbit/sec / 10 */
0, 0, 0, 0 /* 4-7: Reserved values */ 0, 0, 0, 0 /* 4-7: Reserved values */
@@ -260,7 +262,7 @@ static const uint32_t g_transpeedru[8] =
static const uint32_t g_transpeedtu[16] = static const uint32_t g_transpeedtu[16] =
{ {
0, 10, 12, 13, /* 0-3: Reserved, 1.0, 1.1, 1.2, 1.3 */ 0, 10, 12, 13, /* 0-3: Reserved, 1.0, 1.1, 1.2, 1.3 */
15, 20, 25, 30, /* 4-7: 1.5, 2.0, 2.5, 3.0 */ 15, 20, 25, 30, /* 4-7: 1.5, 2.0, 2.5, 3.0 */
35, 40, 45, 50, /* 8-11: 3.5, 4.0, 4.5, 5.0 */ 35, 40, 45, 50, /* 8-11: 3.5, 4.0, 4.5, 5.0 */
55, 60, 70, 80, /* 12-15: 5.5, 6.0, 7.0, 8.0 */ 55, 60, 70, 80, /* 12-15: 5.5, 6.0, 7.0, 8.0 */
@@ -286,16 +288,16 @@ static const uint16_t g_taactu[8] =
{ {
/* Units of nanoseconds */ /* Units of nanoseconds */
1, /* 0: 1 ns */ 1, /* 0: 1 ns */
10, /* 1: 10 ns */ 10, /* 1: 10 ns */
100, /* 2: 100 ns */ 100, /* 2: 100 ns */
/* Units of microseconds */ /* Units of microseconds */
1, /* 3: 1 us 1,000 ns */ 1, /* 3: 1 us 1,000 ns */
10, /* 4: 10 us 10,000 ns */ 10, /* 4: 10 us 10,000 ns */
100, /* 5: 100 us 100,000 ns */ 100, /* 5: 100 us 100,000 ns */
1000, /* 6: 1 ms 1,000,000 ns */ 1000, /* 6: 1 ms 1,000,000 ns */
10000, /* 7: 10 ms 10,000,000 ns */ 10000, /* 7: 10 ms 10,000,000 ns */
}; };
@@ -309,27 +311,72 @@ static const uint16_t g_taactv[] =
/* Commands *****************************************************************/ /* Commands *****************************************************************/
static const struct mmcsd_cmdinfo_s g_cmd0 = {CMD0, MMCSD_CMDRESP_R1, 0x95}; static const struct mmcsd_cmdinfo_s g_cmd0 =
static const struct mmcsd_cmdinfo_s g_cmd1 = {CMD1, MMCSD_CMDRESP_R1, 0xff}; {
static const struct mmcsd_cmdinfo_s g_cmd8 = {CMD8, MMCSD_CMDRESP_R7, 0x87}; CMD0, MMCSD_CMDRESP_R1, 0x95
static const struct mmcsd_cmdinfo_s g_cmd9 = {CMD9, MMCSD_CMDRESP_R1, 0xff}; };
static const struct mmcsd_cmdinfo_s g_cmd1 =
{
CMD1, MMCSD_CMDRESP_R1, 0xff
};
static const struct mmcsd_cmdinfo_s g_cmd8 =
{
CMD8, MMCSD_CMDRESP_R7, 0x87
};
static const struct mmcsd_cmdinfo_s g_cmd9 =
{
CMD9, MMCSD_CMDRESP_R1, 0xff
};
#if 0 /* Not used */ #if 0 /* Not used */
static const struct mmcsd_cmdinfo_s g_cmd10 = {CMD10, MMCSD_CMDRESP_R1, 0xff}; static const struct mmcsd_cmdinfo_s g_cmd10 =
{
CMD10, MMCSD_CMDRESP_R1, 0xff
};
#endif #endif
static const struct mmcsd_cmdinfo_s g_cmd12 = {CMD12, MMCSD_CMDRESP_R1, 0xff}; static const struct mmcsd_cmdinfo_s g_cmd12 =
static const struct mmcsd_cmdinfo_s g_cmd16 = {CMD16, MMCSD_CMDRESP_R1, 0xff}; {
static const struct mmcsd_cmdinfo_s g_cmd17 = {CMD17, MMCSD_CMDRESP_R1, 0xff}; CMD12, MMCSD_CMDRESP_R1, 0xff
static const struct mmcsd_cmdinfo_s g_cmd18 = {CMD18, MMCSD_CMDRESP_R1, 0xff}; };
static const struct mmcsd_cmdinfo_s g_cmd16 =
{
CMD16, MMCSD_CMDRESP_R1, 0xff
};
static const struct mmcsd_cmdinfo_s g_cmd17 =
{
CMD17, MMCSD_CMDRESP_R1, 0xff
};
static const struct mmcsd_cmdinfo_s g_cmd18 =
{
CMD18, MMCSD_CMDRESP_R1, 0xff
};
#if !defined(CONFIG_MMCSD_READONLY) #if !defined(CONFIG_MMCSD_READONLY)
static const struct mmcsd_cmdinfo_s g_cmd24 = {CMD24, MMCSD_CMDRESP_R1, 0xff}; static const struct mmcsd_cmdinfo_s g_cmd24 =
static const struct mmcsd_cmdinfo_s g_cmd25 = {CMD25, MMCSD_CMDRESP_R1, 0xff}; {
CMD24, MMCSD_CMDRESP_R1, 0xff
};
static const struct mmcsd_cmdinfo_s g_cmd25 =
{
CMD25, MMCSD_CMDRESP_R1, 0xff
};
#endif #endif
static const struct mmcsd_cmdinfo_s g_cmd55 = {CMD55, MMCSD_CMDRESP_R1, 0xff}; static const struct mmcsd_cmdinfo_s g_cmd55 =
static const struct mmcsd_cmdinfo_s g_cmd58 = {CMD58, MMCSD_CMDRESP_R3, 0xff}; {
CMD55, MMCSD_CMDRESP_R1, 0xff
};
static const struct mmcsd_cmdinfo_s g_cmd58 =
{
CMD58, MMCSD_CMDRESP_R3, 0xff
};
#if !defined(CONFIG_MMCSD_READONLY) #if !defined(CONFIG_MMCSD_READONLY)
static const struct mmcsd_cmdinfo_s g_acmd23 = {ACMD23, MMCSD_CMDRESP_R1, 0xff}; static const struct mmcsd_cmdinfo_s g_acmd23 =
{
ACMD23, MMCSD_CMDRESP_R1, 0xff
};
#endif #endif
static const struct mmcsd_cmdinfo_s g_acmd41 = {ACMD41, MMCSD_CMDRESP_R1, 0xff}; static const struct mmcsd_cmdinfo_s g_acmd41 =
{
ACMD41, MMCSD_CMDRESP_R1, 0xff
};
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
@@ -416,11 +463,11 @@ static int mmcsd_waitready(FAR struct mmcsd_slot_s *slot)
elapsed = ELAPSED_TIME(start); elapsed = ELAPSED_TIME(start);
if (elapsed > MMCSD_DELAY_10MS) if (elapsed > MMCSD_DELAY_10MS)
{ {
/* Give other threads time to run */ /* Give other threads time to run */
nxsig_usleep(10000); nxsig_usleep(10000);
} }
} }
while (elapsed < MMCSD_DELAY_500MS); while (elapsed < MMCSD_DELAY_500MS);
@@ -440,7 +487,8 @@ static int mmcsd_waitready(FAR struct mmcsd_slot_s *slot)
****************************************************************************/ ****************************************************************************/
static uint32_t mmcsd_sendcmd(FAR struct mmcsd_slot_s *slot, static uint32_t mmcsd_sendcmd(FAR struct mmcsd_slot_s *slot,
const struct mmcsd_cmdinfo_s *cmd, uint32_t arg) FAR const struct mmcsd_cmdinfo_s *cmd,
uint32_t arg)
{ {
FAR struct spi_dev_s *spi = slot->spi; FAR struct spi_dev_s *spi = slot->spi;
uint32_t result; uint32_t result;
@@ -624,7 +672,7 @@ static uint32_t mmcsd_nsac(FAR struct mmcsd_slot_s *slot, uint8_t *csd,
* the maximum value is 25.5K clock cycles. * the maximum value is 25.5K clock cycles.
*/ */
uint32_t nsac = MMCSD_CSD_NSAC(csd) * ((uint32_t)100*1000); uint32_t nsac = MMCSD_CSD_NSAC(csd) * ((uint32_t)100 * 1000);
uint32_t fhkz = (frequency + 500) / 1000; uint32_t fhkz = (frequency + 500) / 1000;
return (nsac + (fhkz >> 1)) / fhkz; return (nsac + (fhkz >> 1)) / fhkz;
} }
@@ -647,7 +695,8 @@ static uint32_t mmcsd_taac(FAR struct mmcsd_slot_s *slot, uint8_t *csd)
* taccess = TU*TV + NSAC/spifrequency * taccess = TU*TV + NSAC/spifrequency
* *
* g_taactu holds TU in units of nanoseconds and microseconds (you have to * g_taactu holds TU in units of nanoseconds and microseconds (you have to
* use the index to distinguish. g_taactv holds TV with 8-bits of fraction. * use the index to distinguish. g_taactv holds TV with 8-bits of
* fraction.
*/ */
tundx = MMCSD_CSD_TAAC_TIMEUNIT(csd); tundx = MMCSD_CSD_TAAC_TIMEUNIT(csd);
@@ -663,7 +712,8 @@ static uint32_t mmcsd_taac(FAR struct mmcsd_slot_s *slot, uint8_t *csd)
{ {
/* Return the answer in microseconds */ /* Return the answer in microseconds */
return (g_taactu[tundx]*g_taactv[MMCSD_CSD_TAAC_TIMEVALUE(csd)] + 0x80) >> 8; return (g_taactu[tundx] * g_taactv[MMCSD_CSD_TAAC_TIMEVALUE(csd)] +
0x80) >> 8;
} }
} }
@@ -714,24 +764,31 @@ static void mmcsd_decodecsd(FAR struct mmcsd_slot_s *slot, uint8_t *csd)
* *
* Example: TAAC = 1.5 ms, NSAC = 0, r2wfactor = 4, CLK_TCK=100 * Example: TAAC = 1.5 ms, NSAC = 0, r2wfactor = 4, CLK_TCK=100
* taccessus = 1,500uS * taccessus = 1,500uS
* taccess = (1,500 * 100) / 100,000) + 1 = 2 (ideal, 1.5) * taccess = (1,500 * 100) / 100,000) + 1 = 2
* twrite = (1,500 * 4 * 100) / 100,000) + 1 = 7 (ideal 6.0) * (ideal, 1.5)
* twrite = (1,500 * 4 * 100) / 100,000) + 1 = 7
* (ideal 6.0)
* *
* First get the access time in microseconds * First get the access time in microseconds
*/ */
uint32_t taccessus = mmcsd_taac(slot, csd) + mmcsd_nsac(slot, csd, frequency); uint32_t taccessus = mmcsd_taac(slot, csd) +
mmcsd_nsac(slot, csd, frequency);
/* Then convert to system clock ticks. The maximum read access is 10 times /* Then convert to system clock ticks. The maximum read access is 10
* the tacc value: taccess = 10 * (taccessus / 1,000,000) * CLK_TCK, or * times the tacc value:
*
* taccess = 10 * (taccessus / 1,000,000) * CLK_TCK
*/ */
slot->taccess = (taccessus * CLK_TCK) / 100000 + 1; slot->taccess = (taccessus * CLK_TCK) / 100000 + 1;
/* NOTE that we add one to taccess to assure that we wait at least this /* NOTE that we add one to taccess to assure that we wait at least
* time. The write access time is larger by the R2WFACTOR: */ * this time. The write access time is larger by the R2WFACTOR:
*/
slot->taccess = (taccessus * MMCSD_CSD_R2WFACTOR(csd) * CLK_TCK) / 100000 + 1; slot->taccess = (taccessus * MMCSD_CSD_R2WFACTOR(csd) * CLK_TCK) /
100000 + 1;
} }
else else
{ {
@@ -769,6 +826,7 @@ static void mmcsd_decodecsd(FAR struct mmcsd_slot_s *slot, uint8_t *csd)
if (MMCSD_CSD_CSDSTRUCT(csd) != 0) if (MMCSD_CSD_CSDSTRUCT(csd) != 0)
{ {
/* SDC structure ver 2.xx */ /* SDC structure ver 2.xx */
/* Note: On SD card WRITE_BL_LEN is always the same as READ_BL_LEN */ /* Note: On SD card WRITE_BL_LEN is always the same as READ_BL_LEN */
readbllen = SD20_CSD_READBLLEN(csd); readbllen = SD20_CSD_READBLLEN(csd);
@@ -778,6 +836,7 @@ static void mmcsd_decodecsd(FAR struct mmcsd_slot_s *slot, uint8_t *csd)
else else
{ {
/* MMC or SD structure ver 1.xx */ /* MMC or SD structure ver 1.xx */
/* Note: On SD card WRITE_BL_LEN is always the same as READ_BL_LEN */ /* Note: On SD card WRITE_BL_LEN is always the same as READ_BL_LEN */
readbllen = MMCSD_CSD_READBLLEN(csd); readbllen = MMCSD_CSD_READBLLEN(csd);
@@ -930,7 +989,8 @@ static int mmcsd_recvblock(FAR struct mmcsd_slot_s *slot, uint8_t *buffer,
/* Wait up to the maximum to receive a valid data token. taccess is the /* Wait up to the maximum to receive a valid data token. taccess is the
* time from when the command is sent until the first byte of data is * time from when the command is sent until the first byte of data is
* received */ * received.
*/
start = START_TIME; start = START_TIME;
do do
@@ -1218,8 +1278,8 @@ static ssize_t mmcsd_read(FAR struct inode *inode, unsigned char *buffer,
goto errout_with_eio; goto errout_with_eio;
} }
buffer += SECTORSIZE(slot); buffer += SECTORSIZE(slot);
} }
/* Send CMD12: Stops transmission */ /* Send CMD12: Stops transmission */
@@ -1251,8 +1311,9 @@ errout_with_eio:
****************************************************************************/ ****************************************************************************/
#if !defined(CONFIG_MMCSD_READONLY) #if !defined(CONFIG_MMCSD_READONLY)
static ssize_t mmcsd_write(FAR struct inode *inode, const unsigned char *buffer, static ssize_t mmcsd_write(FAR struct inode *inode,
size_t start_sector, unsigned int nsectors) FAR const unsigned char *buffer,
size_t start_sector, unsigned int nsectors)
{ {
FAR struct mmcsd_slot_s *slot; FAR struct mmcsd_slot_s *slot;
FAR struct spi_dev_s *spi; FAR struct spi_dev_s *spi;
@@ -1376,7 +1437,7 @@ static ssize_t mmcsd_write(FAR struct inode *inode, const unsigned char *buffer,
ferr("ERROR: ACMD23 failed: R1=%02x\n", response); ferr("ERROR: ACMD23 failed: R1=%02x\n", response);
goto errout_with_sem; goto errout_with_sem;
} }
} }
/* Send CMD25: Continuously write blocks of data until the /* Send CMD25: Continuously write blocks of data until the
* transmission is stopped. * transmission is stopped.
@@ -1398,6 +1459,7 @@ static ssize_t mmcsd_write(FAR struct inode *inode, const unsigned char *buffer,
ferr("ERROR: Failed: to receive the block\n"); ferr("ERROR: Failed: to receive the block\n");
goto errout_with_sem; goto errout_with_sem;
} }
buffer += SECTORSIZE(slot); buffer += SECTORSIZE(slot);
if (mmcsd_waitready(slot) != OK) if (mmcsd_waitready(slot) != OK)
@@ -1493,7 +1555,8 @@ static int mmcsd_geometry(FAR struct inode *inode, struct geometry *geometry)
/* Then return the card geometry */ /* Then return the card geometry */
geometry->geo_available = geometry->geo_available =
((slot->state & (MMCSD_SLOTSTATUS_NOTREADY | MMCSD_SLOTSTATUS_NODISK)) == 0); ((slot->state & (MMCSD_SLOTSTATUS_NOTREADY |
MMCSD_SLOTSTATUS_NODISK)) == 0);
geometry->geo_mediachanged = geometry->geo_mediachanged =
((slot->state & MMCSD_SLOTSTATUS_MEDIACHGD) != 0); ((slot->state & MMCSD_SLOTSTATUS_MEDIACHGD) != 0);
#if !defined(CONFIG_MMCSD_READONLY) #if !defined(CONFIG_MMCSD_READONLY)
@@ -1521,10 +1584,6 @@ static int mmcsd_geometry(FAR struct inode *inode, struct geometry *geometry)
return OK; return OK;
} }
/****************************************************************************
* Initialization
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mmcsd_mediainitialize * Name: mmcsd_mediainitialize
* *
@@ -1551,10 +1610,10 @@ static int mmcsd_mediainitialize(FAR struct mmcsd_slot_s *slot)
slot->state |= MMCSD_SLOTSTATUS_NOTREADY; slot->state |= MMCSD_SLOTSTATUS_NOTREADY;
/* Check if there is a card present in the slot. This is normally a matter is /* Check if there is a card present in the slot. This is normally a
* of GPIO sensing and does not really involve SPI, but by putting this * matter is of GPIO sensing and does not really involve SPI, but by
* functionality in the SPI interface, we encapsulate the SPI MMC/SD * putting this functionality in the SPI interface, we encapsulate the
* interface * SPI MMC/SD interface
*/ */
if ((SPI_STATUS(spi, SPIDEV_MMCSD(0)) & SPI_STATUS_PRESENT) == 0) if ((SPI_STATUS(spi, SPIDEV_MMCSD(0)) & SPI_STATUS_PRESENT) == 0)
@@ -1632,7 +1691,8 @@ static int mmcsd_mediainitialize(FAR struct mmcsd_slot_s *slot)
{ {
/* Verify the operating voltage and that the 0xaa was correctly echoed */ /* Verify the operating voltage and that the 0xaa was correctly echoed */
if (((slot->r7 & MMCSD_SPIR7_VOLTAGE_MASK) == MMCSD_SPIR7_VOLTAGE_27) && if (((slot->r7 & MMCSD_SPIR7_VOLTAGE_MASK) ==
MMCSD_SPIR7_VOLTAGE_27) &&
((slot->r7 & MMCSD_SPIR7_ECHO_MASK) == 0xaa)) ((slot->r7 & MMCSD_SPIR7_ECHO_MASK) == 0xaa))
{ {
/* Try CMD55/ACMD41 for up to 1 second or until the card exits /* Try CMD55/ACMD41 for up to 1 second or until the card exits
@@ -1645,7 +1705,8 @@ static int mmcsd_mediainitialize(FAR struct mmcsd_slot_s *slot)
{ {
finfo("%d. Send CMD55/ACMD41\n", elapsed); finfo("%d. Send CMD55/ACMD41\n", elapsed);
result = mmcsd_sendcmd(slot, &g_cmd55, 0); result = mmcsd_sendcmd(slot, &g_cmd55, 0);
if (result == MMCSD_SPIR1_IDLESTATE || result == MMCSD_SPIR1_OK) if (result == MMCSD_SPIR1_IDLESTATE ||
result == MMCSD_SPIR1_OK)
{ {
result = mmcsd_sendcmd(slot, &g_acmd41, (uint32_t)1 << 30); result = mmcsd_sendcmd(slot, &g_acmd41, (uint32_t)1 << 30);
if (result == MMCSD_SPIR1_OK) if (result == MMCSD_SPIR1_OK)
@@ -1661,26 +1722,27 @@ static int mmcsd_mediainitialize(FAR struct mmcsd_slot_s *slot)
/* Check if ACMD41 was sent successfully */ /* Check if ACMD41 was sent successfully */
if (elapsed < MMCSD_DELAY_1SEC) if (elapsed < MMCSD_DELAY_1SEC)
{ {
finfo("Send CMD58\n"); finfo("Send CMD58\n");
SPI_SEND(spi, 0xff); SPI_SEND(spi, 0xff);
result = mmcsd_sendcmd(slot, &g_cmd58, 0); result = mmcsd_sendcmd(slot, &g_cmd58, 0);
if (result == MMCSD_SPIR1_OK) if (result == MMCSD_SPIR1_OK)
{ {
finfo("OCR: %08x\n", slot->ocr); finfo("OCR: %08x\n", slot->ocr);
if ((slot->ocr & MMCSD_OCR_CCS) != 0) if ((slot->ocr & MMCSD_OCR_CCS) != 0)
{ {
finfo("Identified SD ver2 card/with block access\n"); finfo("Identified SD ver2 card/with block access\n");
slot->type = MMCSD_CARDTYPE_SDV2 | MMCSD_CARDTYPE_BLOCK; slot->type = MMCSD_CARDTYPE_SDV2 |
MMCSD_CARDTYPE_BLOCK;
} }
else else
{ {
finfo("Identified SD ver2 card\n"); finfo("Identified SD ver2 card\n");
slot->type = MMCSD_CARDTYPE_SDV2; slot->type = MMCSD_CARDTYPE_SDV2;
} }
} }
} }
} }
} }
@@ -1714,7 +1776,8 @@ static int mmcsd_mediainitialize(FAR struct mmcsd_slot_s *slot)
{ {
finfo("%d. Send CMD55/ACMD41\n", elapsed); finfo("%d. Send CMD55/ACMD41\n", elapsed);
result = mmcsd_sendcmd(slot, &g_cmd55, 0); result = mmcsd_sendcmd(slot, &g_cmd55, 0);
if (result == MMCSD_SPIR1_IDLESTATE || result == MMCSD_SPIR1_OK) if (result == MMCSD_SPIR1_IDLESTATE ||
result == MMCSD_SPIR1_OK)
{ {
result = mmcsd_sendcmd(slot, &g_acmd41, 0); result = mmcsd_sendcmd(slot, &g_acmd41, 0);
if (result == MMCSD_SPIR1_OK) if (result == MMCSD_SPIR1_OK)
@@ -1733,7 +1796,7 @@ static int mmcsd_mediainitialize(FAR struct mmcsd_slot_s *slot)
slot->type = MMCSD_CARDTYPE_MMC; slot->type = MMCSD_CARDTYPE_MMC;
break; break;
} }
} }
elapsed = ELAPSED_TIME(start); elapsed = ELAPSED_TIME(start);
} }
@@ -1785,13 +1848,13 @@ static int mmcsd_mediainitialize(FAR struct mmcsd_slot_s *slot)
*/ */
#ifdef CONFIG_MMCSD_SECTOR512 #ifdef CONFIG_MMCSD_SECTOR512
/* Using 512 byte sectors, the maximum ver1.x capacity is 4096 x 512 blocks. /* Using 512 byte sectors, the maximum ver1.x capacity is 4096 x 512
* The saved slot->nsectors is converted to 512 byte blocks, so if slot->nsectors * blocks. The saved slot->nsectors is converted to 512 byte blocks, so
* exceeds 4096 x 512, then we must be dealing with a card with read_bl_len * if slot->nsectors exceeds 4096 x 512, then we must be dealing with a
* of 1024 or 2048. * card with read_bl_len of 1024 or 2048.
*/ */
if (!IS_SDV2(slot->type) && slot->nsectors <= ((uint32_t)4096*12)) if (!IS_SDV2(slot->type) && slot->nsectors <= ((uint32_t)4096 * 12))
{ {
/* Don't set the block len on high capacity cards (ver1.x or ver2.x) */ /* Don't set the block len on high capacity cards (ver1.x or ver2.x) */
@@ -1865,7 +1928,8 @@ static void mmcsd_mediachanged(void *arg)
* ready, then try re-initializing it * ready, then try re-initializing it
*/ */
else if ((oldstate & (MMCSD_SLOTSTATUS_NODISK | MMCSD_SLOTSTATUS_NOTREADY)) != 0) else if ((oldstate & (MMCSD_SLOTSTATUS_NODISK |
MMCSD_SLOTSTATUS_NOTREADY)) != 0)
{ {
/* (Re-)initialize for the media in the slot */ /* (Re-)initialize for the media in the slot */
@@ -1909,7 +1973,8 @@ int mmcsd_spislotinitialize(int minor, int slotno, FAR struct spi_dev_s *spi)
int ret; int ret;
#ifdef CONFIG_DEBUG_FEATURES #ifdef CONFIG_DEBUG_FEATURES
if ((unsigned)slotno >= CONFIG_MMCSD_NSLOTS || (unsigned)minor > 255 || !spi) if ((unsigned)slotno >= CONFIG_MMCSD_NSLOTS || (unsigned)minor > 255 ||
spi == NULL)
{ {
ferr("ERROR: Invalid arguments\n"); ferr("ERROR: Invalid arguments\n");
return -EINVAL; return -EINVAL;
+9 -7
View File
@@ -56,6 +56,7 @@
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* Configuration ************************************************************/ /* Configuration ************************************************************/
#ifndef CONFIG_FILEMTD_BLOCKSIZE #ifndef CONFIG_FILEMTD_BLOCKSIZE
@@ -383,9 +384,9 @@ static ssize_t filemtd_byteread(FAR struct mtd_dev_s *dev, off_t offset,
/* Don't let read read past end of buffer */ /* Don't let read read past end of buffer */
if (offset + nbytes > priv->nblocks * priv->erasesize) if (offset + nbytes > priv->nblocks * priv->erasesize)
{ {
return 0; return 0;
} }
filemtd_read(priv, buf, offset, nbytes); filemtd_read(priv, buf, offset, nbytes);
return nbytes; return nbytes;
@@ -438,8 +439,8 @@ static int filemtd_ioctl(FAR struct mtd_dev_s *dev, int cmd,
if (geo) if (geo)
{ {
/* Populate the geometry structure with information need to know /* Populate the geometry structure with information need to
* the capacity and how to access the device. * know the capacity and how to access the device.
*/ */
geo->blocksize = priv->blocksize; geo->blocksize = priv->blocksize;
@@ -486,8 +487,9 @@ static int filemtd_ioctl(FAR struct mtd_dev_s *dev, int cmd,
* *
****************************************************************************/ ****************************************************************************/
FAR struct mtd_dev_s *blockmtd_initialize(FAR const char *path, size_t offset, FAR struct mtd_dev_s *blockmtd_initialize(FAR const char *path,
size_t mtdlen, int16_t sectsize, size_t offset, size_t mtdlen,
int16_t sectsize,
int32_t erasesize) int32_t erasesize)
{ {
FAR struct file_dev_s *priv; FAR struct file_dev_s *priv;
+319 -207
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -414,7 +414,8 @@ int ramdisk_register(int minor, FAR uint8_t *buffer, uint32_t nsectors,
char devname[16]; char devname[16];
int ret = -ENOMEM; int ret = -ENOMEM;
finfo("buffer: %p nsectors: %d sectsize: %d\n", buffer, nsectors, sectsize); finfo("buffer: %p nsectors: %d sectsize: %d\n",
buffer, nsectors, sectsize);
/* Sanity check */ /* Sanity check */
File diff suppressed because it is too large Load Diff
+16 -11
View File
@@ -68,13 +68,15 @@ struct part_struct_s
static int part_open(FAR struct inode *inode); static int part_open(FAR struct inode *inode);
static int part_close(FAR struct inode *inode); static int part_close(FAR struct inode *inode);
static ssize_t part_read(FAR struct inode *inode, unsigned char *buffer, static ssize_t part_read(FAR struct inode *inode, FAR unsigned char *buffer,
size_t start_sector, unsigned int nsectors); size_t start_sector, unsigned int nsectors);
static ssize_t part_write(FAR struct inode *inode, const unsigned char *buffer, static ssize_t part_write(FAR struct inode *inode,
size_t start_sector, unsigned int nsectors); FAR const unsigned char *buffer, size_t start_sector,
static int part_geometry(FAR struct inode *inode, struct geometry *geometry); unsigned int nsectors);
static int part_ioctl(FAR struct inode *inode, int cmd, unsigned long arg); static int part_geometry(FAR struct inode *inode,
FAR struct geometry *geometry);
static int part_ioctl(FAR struct inode *inode, int cmd,
unsigned long arg);
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static int part_unlink(FAR struct inode *inode); static int part_unlink(FAR struct inode *inode);
#endif #endif
@@ -174,8 +176,9 @@ static ssize_t part_read(FAR struct inode *inode, unsigned char *buffer,
* *
****************************************************************************/ ****************************************************************************/
static ssize_t part_write(FAR struct inode *inode, const unsigned char *buffer, static ssize_t part_write(FAR struct inode *inode,
size_t start_sector, unsigned int nsectors) FAR const unsigned char *buffer,
size_t start_sector, unsigned int nsectors)
{ {
FAR struct part_struct_s *dev = inode->i_private; FAR struct part_struct_s *dev = inode->i_private;
FAR struct inode *parent = dev->parent; FAR struct inode *parent = dev->parent;
@@ -245,12 +248,14 @@ static int part_ioctl(FAR struct inode *inode, int cmd, unsigned long arg)
ret = parent->u.i_bops->geometry(parent, &geo); ret = parent->u.i_bops->geometry(parent, &geo);
if (ret >= 0) if (ret >= 0)
{ {
*(FAR uint8_t *)base += dev->firstsector * geo.geo_sectorsize; *(FAR uint8_t *)base +=
dev->firstsector * geo.geo_sectorsize;
} }
} }
else if (cmd == MTDIOC_GEOMETRY) else if (cmd == MTDIOC_GEOMETRY)
{ {
FAR struct mtd_geometry_s *mgeo = (FAR struct mtd_geometry_s *)arg; FAR struct mtd_geometry_s *mgeo =
(FAR struct mtd_geometry_s *)arg;
uint32_t blkper = mgeo->erasesize / mgeo->blocksize; uint32_t blkper = mgeo->erasesize / mgeo->blocksize;
mgeo->neraseblocks = dev->nsectors / blkper; mgeo->neraseblocks = dev->nsectors / blkper;
+2 -2
View File
@@ -488,8 +488,8 @@ int rename(FAR const char *oldpath, FAR const char *newpath)
FAR struct inode *oldinode; FAR struct inode *oldinode;
int ret; int ret;
/* Ignore paths that are interpreted as the root directory which has no name /* Ignore paths that are interpreted as the root directory which has no
* and cannot be moved * name and cannot be moved
*/ */
if (!oldpath || *oldpath == '\0' || oldpath[0] != '/' || if (!oldpath || *oldpath == '\0' || oldpath[0] != '/' ||
+3 -3
View File
@@ -138,9 +138,9 @@ int rmdir(FAR const char *pathname)
} }
/* Remove the inode. NOTE: Because we hold a reference count on the /* Remove the inode. NOTE: Because we hold a reference count on the
* inode, it will not be deleted now. But probably when inode_release() * inode, it will not be deleted now. But probably when
* is called below. inode_remove should return -EBUSY to indicate that * inode_release() is called below. inode_remove should return
* the inode was not deleted now. * -EBUSY to indicate that the inode was not deleted now.
*/ */
inode_semtake(); inode_semtake();
+12 -27
View File
@@ -1,35 +1,20 @@
/**************************************************************************** /****************************************************************************
* include/nuttx/drivers/ramdisk.h * include/nuttx/drivers/ramdisk.h
* *
* Copyright (C) 2008-2009, 2012-2013, 2015-2016 Gregory Nutt. All rights reserved. * Licensed to the Apache Software Foundation (ASF) under one or more
* Author: Gregory Nutt <gnutt@nuttx.org> * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* *
* Redistribution and use in source and binary forms, with or without * http://www.apache.org/licenses/LICENSE-2.0
* modification, are permitted provided that the following conditions
* are met:
* *
* 1. Redistributions of source code must retain the above copyright * Unless required by applicable law or agreed to in writing, software
* notice, this list of conditions and the following disclaimer. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* 2. Redistributions in binary form must reproduce the above copyright * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* notice, this list of conditions and the following disclaimer in * License for the specific language governing permissions and limitations
* the documentation and/or other materials provided with the * under the License.
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
* *
****************************************************************************/ ****************************************************************************/
+7 -7
View File
@@ -157,14 +157,14 @@ static void get_base62(FAR uint8_t *ptr)
static void copy_base62(FAR const uint8_t *src, FAR char *dest, int len) static void copy_base62(FAR const uint8_t *src, FAR char *dest, int len)
{ {
if (len < MAX_XS) if (len < MAX_XS)
{ {
src += MAX_XS - len; src += MAX_XS - len;
} }
for (; len > 0; len--) for (; len > 0; len--)
{ {
*dest++ = base62_to_char(*src++); *dest++ = base62_to_char(*src++);
} }
} }
/**************************************************************************** /****************************************************************************