cxd56/spresense: Add callback mechanism to notice SDCard injection

Add a mechanism to callback to an application to notice the SDCard
status is changed (inserted or ejected).
This commit is contained in:
SPRESENSE 2022-04-11 20:12:20 +09:00 committed by Masayuki Ishikawa
parent 81534df8a3
commit 64e5867a8b
4 changed files with 70 additions and 0 deletions

View File

@ -261,6 +261,10 @@ enum board_power_device
#define BOARDIOC_USBDEV_SETNOTIFYSIG (BOARDIOC_USER+0x0001)
/* Set callback function pointer for notify SDCard state change *************/
#define BOARDIOC_SDCARD_SETNOTIFYCB (BOARDIOC_USER+0x0002)
/* Altair modem device pin definitions **************************************/
#define ALTMDM_SLAVE_REQ PIN_SPI2_SCK

View File

@ -26,6 +26,7 @@
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
/****************************************************************************
* Public Types
@ -130,6 +131,18 @@ void board_sdcard_set_high_voltage(void);
void board_sdcard_set_low_voltage(void);
/****************************************************************************
* Name: board_sdcard_set_state_cb
*
* Description:
* Register callback function to notify state change of card slot.
* This function is called by board_ioctl()
* as BOARDIOC_SDCARD_SETNOTIFYCB command.
*
****************************************************************************/
int board_sdcard_set_state_cb(uintptr_t cb);
#undef EXTERN
#if defined(__cplusplus)
}

View File

@ -34,6 +34,7 @@
#include <arch/chip/chip.h>
#include "cxd56_usbdev.h"
#include "arch/board/cxd56_sdcard.h"
#ifdef CONFIG_BOARDCTL_IOCTL
@ -91,6 +92,22 @@ int board_ioctl(unsigned int cmd, uintptr_t arg)
}
break;
#endif
#ifdef CONFIG_CXD56_SDIO
/* CMD: BOARDIOC_SDCARD_SETNOTIFYCB
* DESCRIPTION: Set a callback function pointer to SDCard driver
* to notify when card status is changed.
* ARG: Callback function.
* CONFIGURATION: CONFIG_BOARDCTL & CONFIG_CXD56_SDIO
* DEPENDENCIES: Board logic must provide board_app_initialization
*/
case BOARDIOC_SDCARD_SETNOTIFYCB:
{
ret = board_sdcard_set_state_cb(arg);
}
break;
#endif
default:
break;
}

View File

@ -70,6 +70,7 @@ struct cxd56_sdhci_state_s
struct sdio_dev_s *sdhci; /* R/W device handle */
bool initialized; /* TRUE: SDHCI block driver is initialized */
bool inserted; /* TRUE: card is inserted */
void (*cb)(bool); /* Callback function pointer to application */
};
/****************************************************************************
@ -165,6 +166,13 @@ static void board_sdcard_enable(FAR void *arg)
}
g_sdhci.initialized = true;
/* Callback to application to notice card is inserted */
if (g_sdhci.cb != NULL)
{
g_sdhci.cb(true);
}
}
release_frequency_lock:
@ -203,6 +211,13 @@ static void board_sdcard_disable(FAR void *arg)
cxd56_sdhci_finalize(0);
g_sdhci.initialized = false;
/* Callback to application to notice card is ejected */
if (g_sdhci.cb != NULL)
{
g_sdhci.cb(false);
}
}
}
@ -515,3 +530,24 @@ void board_sdcard_set_high_voltage(void)
void board_sdcard_set_low_voltage(void)
{
}
/****************************************************************************
* Name: board_sdcard_set_state_cb
*
* Description:
* Register callback function to notify state change of card slot.
* This function is called by board_ioctl()
* as BOARDIOC_SDCARD_SETNOTIFYCB command.
*
****************************************************************************/
int board_sdcard_set_state_cb(uintptr_t cb)
{
if (g_sdhci.cb != NULL && cb != 0)
{
return -EBUSY;
}
g_sdhci.cb = (void (*)(bool))cb;
return OK;
}