Merge pull request 'move nsh_sdmmc_initialize to imxrt_mmcsd.c for xidatong' (#35) from ok1052 into prepare_for_master

ok
This commit is contained in:
wgzAIIT 2022-04-12 18:30:58 +08:00
commit 72effb4915
5 changed files with 114 additions and 44 deletions

View File

@ -70,8 +70,12 @@ ifeq ($(CONFIG_USBHOST),y)
CSRCS += imxrt_usbhost.c CSRCS += imxrt_usbhost.c
endif endif
ifeq ($(CONFIG_IMXRT_USDHC),y)
CSRCS += imxrt_mmcsd.c
endif
ifeq ($(CONFIG_XIDATONG_SDIO_AUTOMOUNT),y) ifeq ($(CONFIG_XIDATONG_SDIO_AUTOMOUNT),y)
CSRCS += imxrt_sdhc_automount.c CSRCS += imxrt_mmcsd_automount.c
endif endif
include $(TOPDIR)/boards/Board.mk include $(TOPDIR)/boards/Board.mk

View File

@ -43,10 +43,6 @@
#include <imxrt_lpi2c.h> #include <imxrt_lpi2c.h>
#include <imxrt_lpspi.h> #include <imxrt_lpspi.h>
#ifdef CONFIG_IMXRT_USDHC
# include "imxrt_usdhc.h"
#endif
#ifdef CONFIG_USBMONITOR #ifdef CONFIG_USBMONITOR
# include <nuttx/usb/usbmonitor.h> # include <nuttx/usb/usbmonitor.h>
#endif #endif
@ -94,45 +90,6 @@ static void imxrt_i2c_register(int bus)
} }
#endif #endif
#ifdef CONFIG_IMXRT_USDHC
static int nsh_sdmmc_initialize(void)
{
struct sdio_dev_s *sdmmc;
int ret = 0;
/* Get an instance of the SDIO interface */
sdmmc = imxrt_usdhc_initialize(0);
if (!sdmmc)
{
syslog(LOG_ERR, "ERROR: Failed to initialize SD/MMC\n");
}
else
{
/* Bind the SDIO interface to the MMC/SD driver */
ret = mmcsd_slotinitialize(0, sdmmc);
if (ret != OK)
{
syslog(LOG_ERR,
"ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n",
ret);
}
#ifdef CONFIG_XIDATONG_SDIO_AUTOMOUNT
imxrt_automount_initialize();
imxrt_usdhc_set_sdio_card_isr(sdmmc, imxrt_sdhc_automount_event, NULL);
#else
imxrt_usdhc_set_sdio_card_isr(sdmmc, NULL, NULL);
#endif
}
return OK;
}
#else
# define nsh_sdmmc_initialize() (OK)
#endif
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/

View File

@ -0,0 +1,103 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiOS is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file imxrt_sdhc_automount.c
* @brief imxrt board sd card automount
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022.04.12
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include <debug.h>
#include "xidatong.h"
#ifdef CONFIG_IMXRT_USDHC
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/* This structure holds static information unique to one SDHC peripheral */
struct imxrt_sdhc_state_s
{
struct sdio_dev_s *sdhc; /* R/W device handle */
bool inserted; /* true: card is inserted */
};
/****************************************************************************
* Private Data
****************************************************************************/
/* device state */
static struct imxrt_sdhc_state_s g_sdhc;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nsh_sdmmc_initialize
*
* Description:
* Initialize the SDHC SD card slot
*
****************************************************************************/
int nsh_sdmmc_initialize(void)
{
int ret = 0;
/* Get an instance of the SDIO interface */
g_sdhc.sdhc = imxrt_usdhc_initialize(0);
if (!g_sdhc.sdhc)
{
syslog(LOG_ERR, "ERROR: Failed to initialize SD/MMC\n");
return -ENODEV;
}
/* Bind the SDIO interface to the MMC/SD driver */
ret = mmcsd_slotinitialize(0, g_sdhc.sdhc);
if (ret != OK)
{
syslog(LOG_ERR, "ERROR: Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
return ret;
}
#ifdef CONFIG_XIDATONG_SDIO_AUTOMOUNT
imxrt_automount_initialize();
imxrt_usdhc_set_sdio_card_isr(g_sdhc.sdhc, imxrt_sdhc_automount_event, NULL);
#else
imxrt_usdhc_set_sdio_card_isr(g_sdhc.sdhc, NULL, NULL);
#endif
return OK;
}
#endif

View File

@ -208,6 +208,12 @@ int imxrt_usbhost_initialize(void);
int imxrt_mmcsd_initialize(void); int imxrt_mmcsd_initialize(void);
#endif #endif
#ifdef CONFIG_IMXRT_USDHC
int nsh_sdmmc_initialize(void);
#else
# define nsh_sdmmc_initialize() (OK)
#endif
#ifdef CONFIG_XIDATONG_SDIO_AUTOMOUNT #ifdef CONFIG_XIDATONG_SDIO_AUTOMOUNT
int imxrt_sdhc_automount_event(void *arg); int imxrt_sdhc_automount_event(void *arg);
void imxrt_automount_initialize(void); void imxrt_automount_initialize(void);