Merged in alinjerpelea/nuttx (pull request #1056)

boards: cxd56xx: add board support for LTE modem and modem driver

* drivers: modem: add altair modem driver

    Add modem driver for the altair modem

    Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>

* boards: cxd56xx: add board support for LTE modem

    Add the Altair LTE modem support on the Spresense board

    Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>

* boards: cxd56xx: spresense: add LTE defconfig

    Add the Altair LTE modem defconfig for spresense board

    Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>

Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
Alin Jerpelea 2019-10-21 14:14:33 +00:00 committed by Gregory Nutt
parent 185557440b
commit 07f9154e5b
23 changed files with 7649 additions and 0 deletions

View File

@ -38,6 +38,11 @@ ifeq ($(CONFIG_CXD56_AUDIO), y)
CSRCS += cxd56_audio.c
endif
ifeq ($(CONFIG_MODEM_ALTMDM),y)
CSRCS += cxd56_altmdm.c
CSRCS += cxd56_altmdm_spi.c
endif
ifeq ($(CONFIG_BOARDCTL_UNIQUEID),y)
CSRCS += cxd56_uid.c
endif

View File

@ -0,0 +1,319 @@
/****************************************************************************
* boards/arm/cxd56xx/common/src/cxd56_altmdm.c
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/board.h>
#include <nuttx/spi/spi.h>
#include <nuttx/modem/altmdm.h>
#if defined(CONFIG_MODEM_ALTMDM) && defined(CONFIG_CXD56_GPIO_IRQ)
#include <arch/board/board.h>
#include <arch/board/cxd56_altmdm.h>
#include "cxd56_gpio.h"
#include "cxd56_gpioint.h"
#include "cxd56_pinconfig.h"
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_MODEM_ALTMDM) && defined(CONFIG_CXD56_GPIO_IRQ)
#define ALTMDM_SHUTDOWN (PIN_SPI2_MISO)
#define MODEM_WAKEUP (PIN_SPI2_MOSI)
#define MASTER_REQUEST (PIN_RTC_IRQ_OUT)
#define SLAVE_REQUEST (PIN_SPI2_SCK)
#define LTE_POWER_BUTTON (PIN_AP_CLK)
#define NUM_OF_PINS (sizeof(pincfg) / sizeof(struct altmdm_pincfg))
#endif
/****************************************************************************
* Private Types
****************************************************************************/
#if defined(CONFIG_MODEM_ALTMDM) && defined(CONFIG_CXD56_GPIO_IRQ)
struct altmdm_pincfg
{
uint32_t pin;
bool input_enable;
bool init_val;
};
#endif
/****************************************************************************
* Private Data
****************************************************************************/
#if defined(CONFIG_MODEM_ALTMDM) && defined(CONFIG_CXD56_GPIO_IRQ)
static const struct altmdm_pincfg pincfg[] =
{
{MODEM_WAKEUP, false, false}, /* out, low */
{MASTER_REQUEST, false, false}, /* out, low */
{SLAVE_REQUEST, true, false}, /* in, low */
};
#endif
#if defined(CONFIG_MODEM_ALTMDM) && defined(CONFIG_CXD56_GPIO_IRQ)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_altmdm_poweron
*
* Description:
* Power on the Altair modem device on the board.
*
****************************************************************************/
void board_altmdm_poweron(void)
{
int i;
/* power on altair modem device */
cxd56_gpio_config(ALTMDM_SHUTDOWN, false);
cxd56_gpio_write(ALTMDM_SHUTDOWN, true);
cxd56_gpio_config(LTE_POWER_BUTTON, false);
cxd56_gpio_write(LTE_POWER_BUTTON, true);
board_power_control(POWER_LTE, true);
for (i = 0; i < NUM_OF_PINS; i++)
{
/* input pin: input enable */
cxd56_gpio_config(pincfg[i].pin, pincfg[i].input_enable);
/* if it is an output pin, write a default value */
if (pincfg[i].input_enable == false)
{
cxd56_gpio_write(pincfg[i].pin, pincfg[i].init_val);
}
}
/* Slave request seems to float in Lite Hibernation and becomes HIGH at some
* times when it should stay LOW.
*/
cxd56_pin_config(PINCONF_SET(SLAVE_REQUEST,
PINCONF_MODE0,
PINCONF_INPUT_ENABLE,
PINCONF_DRIVE_NORMAL, PINCONF_PULLDOWN));
}
/****************************************************************************
* Name: board_altmdm_poweroff
*
* Description:
* Power off the Altair modem device on the board.
*
****************************************************************************/
void board_altmdm_poweroff(void)
{
int i;
for (i = 0; i < NUM_OF_PINS; i++)
{
/* input disable, output disable(Hi-z) */
cxd56_gpio_config(pincfg[i].pin, false);
}
/* power off Altair modem device */
cxd56_gpio_write(ALTMDM_SHUTDOWN, true);
board_power_control(POWER_LTE, false);
cxd56_gpio_write(ALTMDM_SHUTDOWN, false);
cxd56_gpio_write(LTE_POWER_BUTTON, false);
}
/****************************************************************************
* Name: board_altmdm_gpio_write
*
* Description:
* Write GPIO pin.
*
****************************************************************************/
void board_altmdm_gpio_write(uint32_t pin, bool value)
{
if (pin < NUM_OF_PINS)
{
if (pincfg[pin].input_enable == false)
{
cxd56_gpio_write(pincfg[pin].pin, value);
}
}
}
/****************************************************************************
* Name: board_altmdm_gpio_read
*
* Description:
* Read GPIO pin.
*
****************************************************************************/
bool board_altmdm_gpio_read(uint32_t pin)
{
bool val = false;
if (pin < NUM_OF_PINS)
{
if (pincfg[pin].input_enable == true)
{
val = cxd56_gpio_read(pincfg[pin].pin);
}
}
return val;
}
/****************************************************************************
* Name: board_altmdm_gpio_irq
*
* Description:
* Register GPIO irq.
*
****************************************************************************/
void board_altmdm_gpio_irq(uint32_t pin, uint32_t polarity,
uint32_t noise_filter, xcpt_t irqhandler)
{
uint32_t pol;
uint32_t nf;
switch (polarity)
{
case ALTMDM_GPIOINT_LEVEL_HIGH:
pol = GPIOINT_LEVEL_HIGH;
break;
case ALTMDM_GPIOINT_LEVEL_LOW:
pol = GPIOINT_LEVEL_LOW;
break;
case ALTMDM_GPIOINT_EDGE_RISE:
pol = GPIOINT_EDGE_RISE;
break;
case ALTMDM_GPIOINT_EDGE_FALL:
pol = GPIOINT_EDGE_FALL;
break;
case ALTMDM_GPIOINT_EDGE_BOTH:
pol = GPIOINT_EDGE_BOTH;
break;
default:
return;
break;
}
if (noise_filter == ALTMDM_GPIOINT_NOISE_FILTER_ENABLE)
{
nf = GPIOINT_NOISE_FILTER_ENABLE;
}
else
{
nf = GPIOINT_NOISE_FILTER_DISABLE;
}
if (pin < NUM_OF_PINS)
{
if (pincfg[pin].input_enable == true)
{
if (irqhandler)
{
/* Attach then enable the new interrupt handler */
cxd56_gpioint_config(pincfg[pin].pin,
(GPIOINT_TOGGLE_MODE_MASK | nf | pol),
irqhandler, NULL);
}
}
}
}
/****************************************************************************
* Name: board_altmdm_gpio_int_control
*
* Description:
* Enable or disable GPIO interrupt.
*
****************************************************************************/
void board_altmdm_gpio_int_control(uint32_t pin, bool en)
{
if (pin < NUM_OF_PINS)
{
if (pincfg[pin].input_enable == true)
{
if (en)
{
/* enable interrupt */
cxd56_gpioint_enable(pincfg[pin].pin);
}
else
{
/* disable interrupt */
cxd56_gpioint_disable(pincfg[pin].pin);
}
}
}
}
#endif

View File

@ -0,0 +1,255 @@
/****************************************************************************
* boards/arm/cxd56xx/common/src/cxd56_altmdm_spi.c
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_CXD56_SPI) && defined(CONFIG_MODEM_ALTMDM) && defined(CONFIG_CXD56_LTE)
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/board.h>
#include <nuttx/spi/spi.h>
#include <nuttx/modem/altmdm.h>
#include <arch/board/cxd56_altmdm.h>
#include "cxd56_spi.h"
#include "cxd56_pinconfig.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_CXD56_LTE_SPI4)
#define SPI_CH (4)
#if defined(CONFIG_CXD56_LTE_SPI4_DMAC)
# if defined(CONFIG_MODEM_ALTMDM_MAX_PACKET_SIZE)
# if (CONFIG_MODEM_ALTMDM_MAX_PACKET_SIZE > CONFIG_CXD56_DMAC_SPI4_TX_MAXSIZE)
# error CONFIG_CXD56_DMAC_SPI4_TX_MAXSIZE too small
# endif
# if (CONFIG_MODEM_ALTMDM_MAX_PACKET_SIZE > CONFIG_CXD56_DMAC_SPI4_RX_MAXSIZE)
# error CONFIG_CXD56_DMAC_SPI4_RX_MAXSIZE too small
# endif
# endif
#endif
#elif defined(CONFIG_CXD56_LTE_SPI5)
#define SPI_CH (5)
#if defined(CONFIG_CXD56_LTE_SPI5_DMAC)
# if defined(CONFIG_MODEM_ALTMDM_MAX_PACKET_SIZE)
# if (CONFIG_MODEM_ALTMDM_MAX_PACKET_SIZE > CONFIG_CXD56_DMAC_SPI5_TX_MAXSIZE)
# error CONFIG_CXD56_DMAC_SPI5_TX_MAXSIZE too small
# endif
# if (CONFIG_MODEM_ALTMDM_MAX_PACKET_SIZE > CONFIG_CXD56_DMAC_SPI5_RX_MAXSIZE)
# error CONFIG_CXD56_DMAC_SPI5_RX_MAXSIZE too small
# endif
# endif
#endif
#else
#error "Select LTE SPI 4 or 5"
#endif
/****************************************************************************
* Private Data
****************************************************************************/
static void *g_devhandle = NULL;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: spi_pincontrol
*
* Description:
* Configure the SPI pin
*
* Input Parameter:
* on - true: enable pin, false: disable pin
*
****************************************************************************/
static void spi_pincontrol(int bus, bool on)
{
switch (bus)
{
#ifdef CONFIG_CXD56_SPI4
case 4:
if (on)
{
CXD56_PIN_CONFIGS(PINCONFS_SPI4);
}
else
{
CXD56_PIN_CONFIGS(PINCONFS_SPI4_GPIO);
}
break;
#endif /* CONFIG_CXD56_SPI4 */
#ifdef CONFIG_CXD56_SPI5
case 5:
#ifdef CONFIG_CXD56_SPI5_PINMAP_EMMC
if (on)
{
CXD56_PIN_CONFIGS(PINCONFS_EMMCA_SPI5);
}
else
{
CXD56_PIN_CONFIGS(PINCONFS_EMMCA_GPIO);
}
#endif /* CONFIG_CXD56_SPI5_PINMAP_EMMC */
#ifdef CONFIG_CXD56_SPI5_PINMAP_SDIO
if (on)
{
CXD56_PIN_CONFIGS(PINCONFS_SDIOA_SPI5);
}
else
{
CXD56_PIN_CONFIGS(PINCONFS_SDIOA_GPIO);
}
#endif /* CONFIG_CXD56_SPI5_PINMAP_SDIO */
break;
#endif /* CONFIG_CXD56_SPI5 */
default:
break;
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_altmdm_initialize
*
* Description:
* Initialize Altair modem
*
****************************************************************************/
int board_altmdm_initialize(FAR const char *devpath)
{
FAR struct spi_dev_s *spi;
int spi_ch = SPI_CH;
m_info("Initializing ALTMDM..\n");
if (!g_devhandle)
{
/* Initialize spi deivce */
spi = cxd56_spibus_initialize(spi_ch);
if (!spi)
{
m_err("ERROR: Failed to initialize spi%d.\n", spi_ch);
return -ENODEV;
}
spi_pincontrol(spi_ch, false);
g_devhandle = altmdm_register(devpath, spi);
if (!g_devhandle)
{
m_err("ERROR: Failed to register altmdm driver.\n");
return -ENODEV;
}
board_altmdm_poweroff();
}
return OK;
}
/****************************************************************************
* Name: board_altmdm_uninitialize
*
* Description:
* Uninitialize Altair modem
*
****************************************************************************/
int board_altmdm_uninitialize(void)
{
m_info("Uninitializing ALTMDM..\n");
if (g_devhandle)
{
altmdm_unregister(g_devhandle);
g_devhandle = NULL;
}
return OK;
}
/****************************************************************************
* Name: board_altmdm_power_control
*
* Description:
* Power on/off the Altair modem device on the board.
*
****************************************************************************/
void board_altmdm_power_control(bool en)
{
int spi_ch = SPI_CH;
if (en)
{
/* power on altair modem device */
board_altmdm_poweron();
/* enable the SPI pin */
spi_pincontrol(spi_ch, true);
}
else
{
/* disable the SPI pin */
spi_pincontrol(spi_ch, false);
/* power off Altair modem device */
board_altmdm_poweroff();
}
}
#endif /* CONFIG_CXD56_SPI && CONFIG_MODEM_ALTMDM */

View File

@ -68,4 +68,47 @@ config LCD_ON_MAIN_BOARD
endchoice
endif
comment "LTE Options"
menuconfig CXD56_LTE
bool "LTE"
default n
if CXD56_LTE
choice
prompt "LTE SPI selection"
default CXD56_LTE_SPI4
config CXD56_LTE_SPI4
bool "Use SPI4"
select CXD56_SPI4
config CXD56_LTE_SPI5
bool "Use SPI5"
select CXD56_SPI5
endchoice
if CXD56_LTE_SPI4
config CXD56_LTE_SPI4_DMAC
bool "Use DMAC for SPI4"
default y
select CXD56_DMAC_SPI4_TX
select CXD56_DMAC_SPI4_RX
endif # CXD56_LTE_SPI4
if CXD56_LTE_SPI5
config CXD56_LTE_SPI5_DMAC
bool "Use DMAC for SPI5"
default y
select CXD56_DMAC_SPI5_TX
select CXD56_DMAC_SPI5_RX
endif # CXD56_LTE_SPI4
endif # CXD56_LTE
endif

View File

@ -0,0 +1,88 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_CXD56_I2C0_SCUSEQ is not set
# CONFIG_MMCSD_HAVE_WRITEPROTECT is not set
# CONFIG_MMCSD_SPI is not set
# CONFIG_MTD_SMART_WEAR_LEVEL is not set
# CONFIG_STANDARD_SERIAL is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="spresense"
CONFIG_ARCH_BOARD_SPRESENSE=y
CONFIG_ARCH_CHIP="cxd56xx"
CONFIG_ARCH_CHIP_CXD56XX=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARMV7M_USEBASEPRI=y
CONFIG_BOARD_LOOPSPERMSEC=5434
CONFIG_BOOT_RUNFROMISRAM=y
CONFIG_BUILTIN=y
CONFIG_CLOCK_MONOTONIC=y
CONFIG_CXD56_BINARY=y
CONFIG_CXD56_I2C0=y
CONFIG_CXD56_I2C=y
CONFIG_CXD56_LTE=y
CONFIG_CXD56_SDIO=y
CONFIG_CXD56_SPI5=y
CONFIG_CXD56_SPI=y
CONFIG_CXD56_USBDEV=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_FAT_LCNAMES=y
CONFIG_FAT_LFN=y
CONFIG_FAT_MAXFNAME=64
CONFIG_FS_FAT=y
CONFIG_FS_PROCFS=y
CONFIG_FS_PROCFS_REGISTER=y
CONFIG_FS_SMARTFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_I2C=y
CONFIG_MAX_TASKS=16
CONFIG_MAX_WDOGPARMS=2
CONFIG_MMCSD=y
CONFIG_MMCSD_SDIO=y
CONFIG_MODEM=y
CONFIG_MTD_BYTE_WRITE=y
CONFIG_MTD_PARTITION=y
CONFIG_MTD_SMART=y
CONFIG_MTD_SMART_ENABLE_CRC=y
CONFIG_MTD_SMART_SECTOR_SIZE=4096
CONFIG_NFILE_DESCRIPTORS=8
CONFIG_NFILE_STREAMS=8
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_MQ_MSGS=4
CONFIG_PREALLOC_TIMERS=4
CONFIG_PREALLOC_WDOGS=16
CONFIG_RAM_SIZE=1572864
CONFIG_RAM_START=0x0d000000
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_RR_INTERVAL=200
CONFIG_RTC=y
CONFIG_RTC_DRIVER=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_SMARTFS_ALIGNED_ACCESS=y
CONFIG_SMARTFS_MAXNAMLEN=30
CONFIG_SMARTFS_MULTI_ROOT_DIRS=y
CONFIG_SPI=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2011
CONFIG_SYSTEM_CLE=y
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_NSH_CXXINITIALIZE=y
CONFIG_SYSTEM_USBMSC=y
CONFIG_UART1_SERIAL_CONSOLE=y
CONFIG_USBDEV=y
CONFIG_USBDEV_DMA=y
CONFIG_USBDEV_DUALSPEED=y
CONFIG_USBMSC=y
CONFIG_USBMSC_EPBULKIN=1
CONFIG_USBMSC_REMOVABLE=y
CONFIG_USER_ENTRYPOINT="spresense_main"

View File

@ -57,6 +57,7 @@
#include "cxd56_gpioif.h"
#include "cxd56_audio.h"
#include "cxd56_altmdm.h"
#include "cxd56_ak09912.h"
#include "cxd56_apds9930.h"
#include "cxd56_apds9960.h"

View File

@ -0,0 +1,201 @@
/****************************************************************************
* boards/arm/cxd56xx/spresense/include/cxd56_altmdm.h
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation 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.
*
****************************************************************************/
#ifndef __BOARDS_ARM_CXD56XX_SPRESENSE_INCLUDE_CXD56_ALTMDM_H
#define __BOARDS_ARM_CXD56XX_SPRESENSE_INCLUDE_CXD56_ALTMDM_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/boardctl.h>
#include <stdbool.h>
#include <nuttx/irq.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Altair modem gpio definitions *******************************************/
#if defined(CONFIG_MODEM_ALTMDM) && defined(CONFIG_CXD56_GPIO_IRQ)
/* definitions of gpio pin number */
#define ALTMDM_GPIO_MODEM_WAKEUP (0)
#define ALTMDM_GPIO_MASTER_REQ (1)
#define ALTMDM_GPIO_SLAVE_REQ (2)
/* definitions of gpio interrupt polarity */
#define ALTMDM_GPIOINT_LEVEL_HIGH (0)
#define ALTMDM_GPIOINT_LEVEL_LOW (1)
#define ALTMDM_GPIOINT_EDGE_RISE (2)
#define ALTMDM_GPIOINT_EDGE_FALL (3)
#define ALTMDM_GPIOINT_EDGE_BOTH (4)
/* definitions of gpio interrupt noise filter */
#define ALTMDM_GPIOINT_NOISE_FILTER_ENABLE (0)
#define ALTMDM_GPIOINT_NOISE_FILTER_DISABLE (1)
#endif
/****************************************************************************
* Public Types
****************************************************************************/
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Data
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#if defined(CONFIG_MODEM_ALTMDM) && defined(CONFIG_CXD56_GPIO_IRQ)
/****************************************************************************
* Name: board_altmdm_initialize
*
* Description:
* Initialize Altair modem
*
****************************************************************************/
int board_altmdm_initialize(FAR const char *devpath);
/****************************************************************************
* Name: board_altmdm_uninitialize
*
* Description:
* Uninitialize Altair modem
*
****************************************************************************/
int board_altmdm_uninitialize(void);
/****************************************************************************
* Name: board_altmdm_power_control
*
* Description:
* Power on/off the Altair modem device on the board.
*
****************************************************************************/
void board_altmdm_power_control(bool en);
/****************************************************************************
* Name: board_altmdm_poweron
*
* Description:
* Power on the Altair modem device on the board.
*
****************************************************************************/
void board_altmdm_poweron(void);
/****************************************************************************
* Name: board_altmdm_poweroff
*
* Description:
* Power off the Altair modem device on the board.
*
****************************************************************************/
void board_altmdm_poweroff(void);
/****************************************************************************
* Name: board_altmdm_gpio_write
*
* Description:
* Write GPIO pin.
*
****************************************************************************/
void board_altmdm_gpio_write(uint32_t pin, bool value);
/****************************************************************************
* Name: board_altmdm_gpio_read
*
* Description:
* Read GPIO pin.
*
****************************************************************************/
bool board_altmdm_gpio_read(uint32_t pin);
/****************************************************************************
* Name: board_altmdm_gpio_irq
*
* Description:
* Register GPIO irq.
*
****************************************************************************/
void board_altmdm_gpio_irq(uint32_t pin, uint32_t polarity,
uint32_t noise_filter, xcpt_t irqhandler);
/****************************************************************************
* Name: board_altmdm_gpio_int_control
*
* Description:
* Enable or disable GPIO interrupt.
*
****************************************************************************/
void board_altmdm_gpio_int_control(uint32_t pin, bool en);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_ARM_CXD56XX_SPRESENSE_INCLUDE_CXD56_ALTMDM_H */

View File

@ -389,6 +389,14 @@ int cxd56_bringup(void)
usbdev_rndis_initialize(mac);
#endif
#ifdef CONFIG_MODEM_ALTMDM
ret = board_altmdm_initialize("/dev/altmdm");
if (ret < 0)
{
_err("ERROR: Failed to initialze Altair modem. \n");
}
#endif
#ifdef CONFIG_WL_GS2200M
ret = board_gs2200m_initialize("/dev/gs2200m", 5);
if (ret < 0)

View File

@ -18,3 +18,5 @@ config MODEM_U_BLOX_DEBUG
---help---
Allow the u-blox modem driver print debug information.
source "drivers/modem/altair/Kconfig"

View File

@ -39,6 +39,8 @@ ifeq ($(CONFIG_MODEM_U_BLOX),y)
CSRCS += u-blox.c
endif
include modem$(DELIM)altair$(DELIM)Make.defs
# Include modem driver build support
DEPPATH += --dep-path modem

View File

@ -0,0 +1,52 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
menuconfig MODEM_ALTMDM
bool "Altair modem support"
default y
---help---
Enable driver for the Altair modem.
if MODEM_ALTMDM
config MODEM_ALTMDM_PROTCOL_V2_1
bool "Enable SPI protocol version 2.1"
default y
depends on MODEM_ALTMDM
---help---
Support only this version.
config MODEM_ALTMDM_DEBUG
bool "Enable debug mode for Altair modem driver"
default n
depends on MODEM_ALTMDM
---help---
Allow the Altair modem driver print debug information.
config MODEM_ALTMDM_KEEP_WAKE_STATE
bool "Configuration to keep wake state of modem"
default n
depends on MODEM_ALTMDM
---help---
none
config MODEM_ALTMDM_MAX_PACKET_SIZE
int "Max size to be transfer in bytes"
default 2064
depends on MODEM_ALTMDM
---help---
none
config MODEM_ALTMDM_SLEEP_TIMER_VAL
int "Modem sleep timer"
default 20
depends on MODEM_ALTMDM
---help---
Modem sleep timer in milliseconds.
Modem may sleep if there is no data to be transferred
during specified time. Values smaller than 20 milliseconds
can not be specified.
endif

View File

@ -0,0 +1,50 @@
############################################################################
# lte/drivers/Make.defs
#
# Copyright 2018 Sony Semiconductor Solutions Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name of Sony Semiconductor Solutions Corporation 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.
#
############################################################################
ifeq ($(CONFIG_MODEM),y)
ifeq ($(CONFIG_MODEM_ALTMDM),y)
CSRCS += altmdm.c
CSRCS += altmdm_spi.c
CSRCS += altmdm_pm.c
CSRCS += altmdm_pm_state.c
CSRCS += altmdm_sys.c
endif
DEPPATH += --dep-path modem$(DELIM)altair
VPATH += :modem$(DELIM)altair
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)modem}
endif

View File

@ -0,0 +1,463 @@
/****************************************************************************
* drivers/modem/altair/altmdm.c
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/spi/spi.h>
#include <nuttx/modem/altmdm.h>
#include "altmdm_dev.h"
#include "altmdm_spi.h"
#include "altmdm_pm.h"
#include "altmdm_sys.h"
#if defined(CONFIG_MODEM_ALTMDM)
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/* Character driver methods. */
static int altmdm_open(FAR struct file *filep);
static int altmdm_close(FAR struct file *filep);
static ssize_t altmdm_read(FAR struct file *filep, FAR char *buffer,
size_t len);
static ssize_t altmdm_write(FAR struct file *filep, FAR const char *buffer,
size_t len);
static int altmdm_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
/****************************************************************************
* Private Data
****************************************************************************/
/* This the vtable that supports the character driver interface. */
static const struct file_operations g_altmdmfops =
{
altmdm_open, /* open */
altmdm_close, /* close */
altmdm_read, /* read */
altmdm_write, /* write */
0, /* seek */
altmdm_ioctl, /* ioctl */
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: is_poweron
*
* Description:
* Check ALTMDM power on.
*
****************************************************************************/
static int is_poweron(FAR struct altmdm_dev_s *priv)
{
int poweron;
altmdm_sys_lock(&priv->lock);
poweron = priv->poweron;
altmdm_sys_unlock(&priv->lock);
return poweron;
}
/****************************************************************************
* Name: altmdm_initialize
*
* Description:
* Initialize ALTMDM driver.
*
****************************************************************************/
static int altmdm_initialize(FAR struct altmdm_dev_s *priv)
{
int ret;
ret = altmdm_sys_initlock(&priv->lock);
if (ret == ERROR)
{
m_err("altmdm_sys_initlock() failed:%d\n", ret);
}
priv->poweron = 0;
/* Intialize ALTMDM SPI driver. */
ret = altmdm_spi_init(priv);
return ret;
}
/****************************************************************************
* Name: altmdm_uninitialize
*
* Description:
* Uninitialize ALTMDM driver.
*
****************************************************************************/
static int altmdm_uninitialize(FAR struct altmdm_dev_s *priv)
{
int ret;
/* Unintialize ALTMDM SPI driver */
altmdm_spi_uninit(priv);
ret = altmdm_sys_deletelock(&priv->lock);
if (ret == ERROR)
{
m_err("altmdm_sys_deletelock() failed:%d\n", ret);
}
return ret;
}
/****************************************************************************
* Name: altmdm_open
*
* Description:
* Standard character driver open method.
*
****************************************************************************/
static int altmdm_open(FAR struct file *filep)
{
return OK;
}
/****************************************************************************
* Name: altmdm_close
*
* Description:
* Standard character driver close method.
*
****************************************************************************/
static int altmdm_close(FAR struct file *filep)
{
return OK;
}
/****************************************************************************
* Name: altmdm_read
*
* Description:
* Standard character driver read method.
*
****************************************************************************/
static ssize_t altmdm_read(FAR struct file *filep,
FAR char *buffer,
size_t len)
{
FAR struct inode *inode = filep->f_inode;
FAR struct altmdm_dev_s *priv = inode->i_private;
ssize_t rsize = -EPERM;
rsize = altmdm_spi_read(priv, buffer, len);
return rsize;
}
/****************************************************************************
* Name: altmdm_write
*
* Description:
* Standard character driver write method.
*
****************************************************************************/
static ssize_t altmdm_write(FAR struct file *filep, FAR const char *buffer,
size_t len)
{
FAR struct inode *inode = filep->f_inode;
FAR struct altmdm_dev_s *priv = inode->i_private;
ssize_t wsize = -EPERM;
if (is_poweron(priv))
{
wsize = altmdm_spi_write(priv, buffer, len);
}
return wsize;
}
/****************************************************************************
* Name: altmdm_ioctl
*
* Description:
* Standard character driver ioctl method.
*
****************************************************************************/
static int altmdm_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct inode *inode = filep->f_inode;
FAR struct altmdm_dev_s *priv = inode->i_private;
int ret = -EPERM;
switch (cmd)
{
case MODEM_IOC_POWERON: /* Power on ALTMDM. */
{
altmdm_sys_lock(&priv->lock);
if (!priv->poweron)
{
altmdm_pm_poweron(priv);
priv->poweron = 1;
ret = altmdm_spi_enable(priv);
}
else
{
ret = -EBUSY;
}
altmdm_sys_unlock(&priv->lock);
}
break;
case MODEM_IOC_POWEROFF: /* Power off ALTMDM. */
{
altmdm_sys_lock(&priv->lock);
if (priv->poweron)
{
ret = altmdm_spi_disable(priv);
altmdm_pm_poweroff(priv);
priv->poweron = 0;
}
else
{
ret = -EBUSY;
}
altmdm_sys_unlock(&priv->lock);
}
break;
case MODEM_IOC_READABORT: /* Abort the read process. */
{
ret = altmdm_spi_readabort(priv);
}
break;
case MODEM_IOC_SLEEP: /* Make ALTMDM sleep. */
{
if (is_poweron(priv))
{
ret = altmdm_spi_sleepmodem(priv);
}
}
break;
case MODEM_IOC_PM_REGISTERCB: /* Register callback function. */
{
ret = altmdm_pm_registercb(MODEM_PM_CB_TYPE_NORMAL,
(altmdm_pm_cbfunc_t) arg);
}
break;
case MODEM_IOC_PM_DEREGISTERCB: /* Deregister callback function. */
{
ret = altmdm_pm_deregistercb(MODEM_PM_CB_TYPE_NORMAL);
}
break;
case MODEM_IOC_PM_ERR_REGISTERCB: /* Register error callback function. */
{
ret = altmdm_pm_registercb(MODEM_PM_CB_TYPE_ERROR,
(altmdm_pm_cbfunc_t) arg);
}
break;
case MODEM_IOC_PM_ERR_DEREGISTERCB: /* Deregister error callback
function.
*/
{
ret = altmdm_pm_deregistercb(MODEM_PM_CB_TYPE_ERROR);
}
break;
case MODEM_IOC_PM_GETSTATE: /* Get ALTMDM power management state. */
{
*(uint32_t *) arg = altmdm_pm_getstate();
ret = 0;
}
break;
case MODEM_IOC_PM_INITWAKELOCK: /* Initialze wakelock resource. */
{
ret = altmdm_pm_initwakelock((struct altmdm_pm_wakelock_s *)arg);
}
break;
case MODEM_IOC_PM_ACQUIREWAKELOCK: /* Acquire wakelock. */
{
ret = altmdm_pm_acquirewakelock((struct altmdm_pm_wakelock_s *)arg);
}
break;
case MODEM_IOC_PM_RELEASEWAKELOCK: /* Release wakelock. */
{
ret = altmdm_pm_releasewakelock((struct altmdm_pm_wakelock_s *)arg);
}
break;
case MODEM_IOC_PM_GETNUMOFWAKELOCK: /* Get number of wakelocks. */
{
ret = altmdm_pm_getnumofwakelock((struct altmdm_pm_wakelock_s *)arg);
}
break;
case MODEM_IOC_PM_GETWAKELOCKSTATE: /* Get wakelock state. */
{
ret = altmdm_pm_getwakelockstate();
}
break;
default:
m_err("Unrecognized cmd: 0x%08x\n", cmd);
break;
}
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: altmdm_register
*
* Description:
* Register the ALTMDM character device as 'devpath'.
*
* Input Parameters:
* devpath - The full path to the driver to register. E.g., "/dev/altmdm".
* dev - An instance of the SPI interface to use to communicate with
* ALTMDM.
*
* Returned Value:
* Not NULL on success; NULL on failure.
*
****************************************************************************/
FAR void *altmdm_register(FAR const char *devpath, FAR struct spi_dev_s *dev)
{
FAR struct altmdm_dev_s *priv;
int ret;
int size = sizeof(struct altmdm_dev_s);
priv = (FAR struct altmdm_dev_s *)kmm_malloc(size);
if (!priv)
{
m_err("Failed to allocate instance.\n");
return NULL;
}
priv->spi = dev;
priv->path = strdup(devpath);
ret = altmdm_initialize(priv);
if (ret < 0)
{
m_err("Failed to initialize ALTMDM driver.\n");
kmm_free(priv);
return NULL;
}
ret = register_driver(devpath, &g_altmdmfops, 0666, priv);
if (ret < 0)
{
m_err("Failed to register driver: %d\n", ret);
kmm_free(priv);
return NULL;
}
return (FAR void *)priv;
}
/****************************************************************************
* Name: altmdm_unregister
*
* Description:
* Unregister the ALTMDM character device.
*
* Input Parameters:
* handle - The pointer that getting from altmdm_register.
*
* Returned Value:
* None.
*
****************************************************************************/
void altmdm_unregister(FAR void *handle)
{
FAR struct altmdm_dev_s *priv;
if (handle)
{
priv = (FAR struct altmdm_dev_s *)handle;
altmdm_uninitialize(priv);
(void)unregister_driver(priv->path);
kmm_free(priv->path);
kmm_free(priv);
}
}
#endif

View File

@ -0,0 +1,194 @@
/****************************************************************************
* drivers/modem/altair/altmdm_dev.h
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation 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.
*
****************************************************************************/
#ifndef __DRIVERS_MODEM_ALTAIR_ALTMDM_DEV_H
#define __DRIVERS_MODEM_ALTAIR_ALTMDM_DEV_H
/****************************************************************************
* Included Files
****************************************************************************/
# include <nuttx/modem/altmdm.h>
# include "altmdm_spi.h"
# include "altmdm_sys.h"
# if defined(CONFIG_MODEM_ALTMDM)
/****************************************************************************
* Public Types
****************************************************************************/
struct altmdm_dev_s
{
FAR char *path; /* Registration path */
FAR struct spi_dev_s *spi;
struct altmdm_spi_dev_s spidev;
struct altmdm_sys_lock_s lock;
int poweron;
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: altmdm_spi_init
*
* Description:
* Initialize ALTMDM driver.
*
****************************************************************************/
int altmdm_spi_init(FAR struct altmdm_dev_s *priv);
/****************************************************************************
* Name: altmdm_spi_uninit
*
* Description:
* Uninitialize ALTMDM driver.
*
****************************************************************************/
int altmdm_spi_uninit(FAR struct altmdm_dev_s *priv);
/****************************************************************************
* Name: altmdm_spi_enable
*
* Description:
* Enable ALTMDM SPI driver.
*
****************************************************************************/
int altmdm_spi_enable(FAR struct altmdm_dev_s *priv);
/****************************************************************************
* Name: altmdm_spi_disable
*
* Description:
* Disable ALTMDM SPI driver.
*
****************************************************************************/
int altmdm_spi_disable(FAR struct altmdm_dev_s *priv);
/****************************************************************************
* Name: altmdm_spi_read
*
* Description:
* ALTMDM SPI driver read method.
*
****************************************************************************/
ssize_t altmdm_spi_read(FAR struct altmdm_dev_s *priv,
FAR const char *buffer, size_t readlen);
/****************************************************************************
* Name: altmdm_spi_write
*
* Description:
* ALTMDM SPI driver write method.
*
****************************************************************************/
ssize_t altmdm_spi_write(FAR struct altmdm_dev_s *priv,
FAR const char *buffer, size_t witelen);
/****************************************************************************
* Name: altmdm_spi_readabort
*
* Description:
* Abort the read process.
*
****************************************************************************/
int altmdm_spi_readabort(FAR struct altmdm_dev_s *priv);
/****************************************************************************
* Name: altmdm_spi_sleepmodem
*
* Description:
* Make ALTMDM sleep.
*
****************************************************************************/
int altmdm_spi_sleepmodem(FAR struct altmdm_dev_s *priv);
#ifdef CONFIG_MODEM_ALTMDM_PROTCOL_V2_1
/****************************************************************************
* Name: altmdm_spi_setreceiverready
*
* Description:
* Set receiver ready notification.
*
****************************************************************************/
int altmdm_spi_setreceiverready(FAR struct altmdm_dev_s *priv);
/****************************************************************************
* Name: altmdm_spi_isreceiverready
*
* Description:
* Check already notified or not by altmdm_spi_setreceiverready.
*
****************************************************************************/
int altmdm_spi_isreceiverready(FAR struct altmdm_dev_s *priv);
/****************************************************************************
* Name: altmdm_spi_clearreceiverready
*
* Description:
* Clear receiver ready notification.
*
****************************************************************************/
int altmdm_spi_clearreceiverready(FAR struct altmdm_dev_s *priv);
#endif
/****************************************************************************
* Name: altmdm_spi_gpioreadyisr
*
* Description:
* Interrupt handler for SLAVE_REQUEST GPIO line.
*
****************************************************************************/
int altmdm_spi_gpioreadyisr(int irq, FAR void *context, FAR void *arg);
#endif
#endif /* __DRIVERS_MODEM_ALTAIR_ALTMDM_DEV_H */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,239 @@
/****************************************************************************
* drivers/modem/altair/altmdm_pm.h
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation 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.
*
****************************************************************************/
#ifndef __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_H
#define __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_H
/****************************************************************************
* Included Files
****************************************************************************/
#include "altmdm_dev.h"
#include "altmdm_sys.h"
#include "altmdm_pm_state.h"
#if defined(CONFIG_MODEM_ALTMDM)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define MODEM_PM_WAKEUP_DONE (0)
#define MODEM_PM_WAKEUP_ALREADY (1)
#define MODEM_PM_WAKEUP_FAIL (2)
#define MODEM_PM_CB_SLEEP (0)
#define MODEM_PM_CB_WAKE (1)
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: altmdm_pm_init
*
* Description:
* Initialize the ALTMDM power manager driver.
*
****************************************************************************/
int altmdm_pm_init(FAR struct altmdm_dev_s *priv);
/****************************************************************************
* Name: altmdm_pm_uninit
*
* Description:
* Uninitialize the ALTMDM power manager driver.
*
****************************************************************************/
int altmdm_pm_uninit(FAR struct altmdm_dev_s *priv);
/****************************************************************************
* Name: altmdm_pm_wakeup
*
* Description:
* Make modem wake up.
*
****************************************************************************/
int altmdm_pm_wakeup(FAR struct altmdm_dev_s *priv);
/****************************************************************************
* Name: altmdm_pm_notify_reset
*
* Description:
* Notify reset has done.
*
****************************************************************************/
int altmdm_pm_notify_reset(FAR struct altmdm_dev_s *priv);
#ifdef CONFIG_MODEM_ALTMDM_PROTCOL_V2_1
/****************************************************************************
* Name: altmdm_pm_callgpiohandler
*
* Description:
* Call Device to Host GPIO interrupt handler.
*
****************************************************************************/
int altmdm_pm_callgpiohandler(FAR struct altmdm_dev_s *priv);
#endif
/****************************************************************************
* Name: altmdm_pm_registercb
*
* Description:
* Register callback for ALTMDM power manager driver.
*
****************************************************************************/
int altmdm_pm_registercb(uint32_t type, altmdm_pm_cbfunc_t cb);
/****************************************************************************
* Name: altmdm_pm_deregistercb
*
* Description:
* Deregister callback for ALTMDM power manager driver.
*
****************************************************************************/
int altmdm_pm_deregistercb(uint32_t type);
/****************************************************************************
* Name: altmdm_pm_sleepmodem
*
* Description:
* Make modem sleep.
*
****************************************************************************/
int altmdm_pm_sleepmodem(FAR struct altmdm_dev_s *priv);
/****************************************************************************
* Name: altmdm_pm_cansleep
*
* Description:
* Check if modem can sleep.
*
****************************************************************************/
int altmdm_pm_cansleep(FAR struct altmdm_dev_s *priv);
/****************************************************************************
* Name: altmdm_pm_initwakelock
*
* Description:
* Initialize the modem wakelock resource.
*
****************************************************************************/
int altmdm_pm_initwakelock(FAR struct altmdm_pm_wakelock_s *lock);
/****************************************************************************
* Name: altmdm_pm_acquirewakelock
*
* Description:
* Acquire the modem wakelock.
*
****************************************************************************/
int altmdm_pm_acquirewakelock(FAR struct altmdm_pm_wakelock_s *lock);
/****************************************************************************
* Name: altmdm_pm_releasewakelock
*
* Description:
* Release the modem wakelock.
*
****************************************************************************/
int altmdm_pm_releasewakelock(FAR struct altmdm_pm_wakelock_s *lock);
/****************************************************************************
* Name: altmdm_pm_getnumofwakelock
*
* Description:
* Get the lock count of the specified wakelock.
*
****************************************************************************/
int altmdm_pm_getnumofwakelock(FAR struct altmdm_pm_wakelock_s *lock);
/****************************************************************************
* Name: altmdm_pm_getwakelockstate
*
* Description:
* Get the wakelock status. If the return value is 0, it means that it is
* not locked. Otherwise it means that someone is locking.
*
****************************************************************************/
int altmdm_pm_getwakelockstate(void);
/****************************************************************************
* Name: altmdm_pm_poweron
*
* Description:
* Modem power on.
*
****************************************************************************/
int altmdm_pm_poweron(FAR struct altmdm_dev_s *priv);
/****************************************************************************
* Name: altmdm_pm_poweroff
*
* Description:
* Modem power off.
*
****************************************************************************/
int altmdm_pm_poweroff(FAR struct altmdm_dev_s *priv);
/****************************************************************************
* Name: altmdm_pm_set_bootstatus
*
* Description:
* Set boot status.
*
****************************************************************************/
int altmdm_pm_set_bootstatus(FAR struct altmdm_dev_s *priv, uint32_t status);
#endif
#endif /* __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_H */

View File

@ -0,0 +1,154 @@
/****************************************************************************
* drivers/modem/altair/altmdm_pm_state.c
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/irq.h>
#include <nuttx/modem/altmdm.h>
#include "altmdm_pm_state.h"
#if defined(CONFIG_MODEM_ALTMDM)
/****************************************************************************
* Private Data
****************************************************************************/
static uint32_t g_stateofmodem;
#ifdef CONFIG_MODEM_PM_PUTSTATE
static char *g_putstring[MODEM_PM_INTERNAL_STATE_MAX] =
{
"SLEEP",
"GOING_TO_WAKE",
"WAKE",
"GOING_TO_SLEEP"
};
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: altmdm_pm_getstate
*
* Description:
* Get current modem state.
*
****************************************************************************/
uint32_t altmdm_pm_getstate(void)
{
uint32_t get_state;
uint32_t internal_state;
internal_state = altmdm_pm_getinternalstate();
switch (internal_state)
{
case MODEM_PM_INTERNAL_STATE_SLEEP:
case MODEM_PM_INTERNAL_STATE_GOING_TO_WAKE:
get_state = MODEM_PM_STATE_SLEEP;
break;
case MODEM_PM_INTERNAL_STATE_WAKE:
case MODEM_PM_INTERNAL_STATE_GOING_TO_SLEEP:
get_state = MODEM_PM_STATE_WAKE;
break;
default:
get_state = MODEM_PM_STATE_WAKE;
break;
}
return get_state;
}
/****************************************************************************
* Name: altmdm_pm_getinternalstate
*
* Description:
* Get internal modem state.
*
****************************************************************************/
uint32_t altmdm_pm_getinternalstate(void)
{
uint32_t get_state;
irqstate_t flags;
flags = enter_critical_section();
get_state = g_stateofmodem;
leave_critical_section(flags);
return get_state;
}
/****************************************************************************
* Name: altmdm_pm_setinternalstate
*
* Description:
* Set internal modem state.
*
****************************************************************************/
void altmdm_pm_setinternalstate(uint32_t state)
{
irqstate_t flags;
#ifdef CONFIG_MODEM_PM_PUTSTATE
uint32_t prev_state;
#endif
if (state < MODEM_PM_INTERNAL_STATE_MAX)
{
flags = enter_critical_section();
#ifdef CONFIG_MODEM_PM_PUTSTATE
prev_state = g_stateofmodem;
#endif
g_stateofmodem = state;
leave_critical_section(flags);
#ifdef CONFIG_MODEM_PM_PUTSTATE
m_err("MODEM State [%d:%s]-->[%d:%s]\n",
prev_state, g_putstring[prev_state], state, g_putstring[state]);
#endif
}
}
#endif

View File

@ -0,0 +1,86 @@
/****************************************************************************
* drivers/modem/altmdm/altmdm_pm_state.h
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation 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.
*
****************************************************************************/
#ifndef __DRIVERS_MODEM_ALTMDM_ALTMDM_PM_STATE_H
#define __DRIVERS_MODEM_ALTMDM_ALTMDM_PM_STATE_H
#if defined(CONFIG_MODEM_ALTMDM)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define MODEM_PM_INTERNAL_STATE_SLEEP (0)
#define MODEM_PM_INTERNAL_STATE_GOING_TO_WAKE (1)
#define MODEM_PM_INTERNAL_STATE_WAKE (2)
#define MODEM_PM_INTERNAL_STATE_GOING_TO_SLEEP (3)
#define MODEM_PM_INTERNAL_STATE_MAX (4)
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: altmdm_pm_getstate
*
* Description:
* Get current modem state.
*
****************************************************************************/
uint32_t altmdm_pm_getstate(void);
/****************************************************************************
* Name: altmdm_pm_getinternalstate
*
* Description:
* Get internal modem state.
*
****************************************************************************/
uint32_t altmdm_pm_getinternalstate(void);
/****************************************************************************
* Name: altmdm_pm_setinternalstate
*
* Description:
* Set internal modem state.
*
****************************************************************************/
void altmdm_pm_setinternalstate(uint32_t state);
#endif
#endif /* __DRIVERS_MODEM_ALTMDM_ALTMDM_PM_STATE_H */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,182 @@
/****************************************************************************
* drivers/modem/altmdm/altmdm_spi.h
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation 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.
*
****************************************************************************/
#ifndef __DRIVERS_MODEM_ALTMDM_ALTMDM_ALTMDM_SPI_H
#define __DRIVERS_MODEM_ALTMDM_ALTMDM_ALTMDM_SPI_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <semaphore.h>
#include "altmdm_dev.h"
#include "altmdm_sys.h"
#if defined(CONFIG_MODEM_ALTMDM)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/* This structure describes the transfer header. */
struct altmdm_spi_xferhdr_s
{
uint8_t header[4]; /* Transfer header. */
};
/* This structure describes the buffer for data receive. */
struct altmdm_spi_rxbuff_s
{
char *buff_addr; /* Receive buffer address. */
uint32_t buff_size; /* Size of this buffer. */
uint32_t rx_size; /* Received data size. */
struct altmdm_spi_rxbuff_s *next; /* Link for next buffer. */
};
/* This structure describes the fifo for received buffer. */
struct altmdm_spi_rxbufffifo_s
{
struct altmdm_spi_rxbuff_s *head; /* Point to the head of fifo */
struct altmdm_spi_rxbuff_s *tail; /* Point to the tail of fifo */
struct altmdm_sys_csem_s csem; /* It is used for notification when
* data is put in fifo.
*/
};
/* This structure describes the parameters for receive buffer information. */
struct altmdm_spi_rxbuffinfo_s
{
struct altmdm_spi_rxbuff_s *free_buff; /* Free receive buffer address. */
struct altmdm_spi_rxbufffifo_s fifo; /* Receive buffer fifo. */
};
/* This structure describes the parameters for send data. */
struct altmdm_spi_tx_s
{
struct altmdm_sys_lock_s lock; /* Lock on accessing the following
* parameters.
*/
struct altmdm_sys_flag_s done_flag; /* Notify that tx request has been
* completed.
*/
struct altmdm_spi_xferhdr_s header; /* Tx header. */
char *buff_addr; /* Buffer address for data transmission
* speceified by the user.
*/
int32_t actual_size; /* Actual data size. */
int32_t total_size; /* Data size of 4byte alignment. */
int32_t result; /* Result of transfer. */
int32_t is_bufful; /* Indicates the slave is buffer full status. */
};
/* This structure describes the parameters for receive data. */
struct altmdm_spi_rx_s
{
struct altmdm_sys_lock_s lock; /* Lock on accessing the following
* parameters.
*/
struct altmdm_spi_xferhdr_s header; /* Rx header. */
int8_t status_info; /* Header status information */
int32_t actual_size; /* Actual data size */
int32_t total_size; /* Data size of 4byte alignment. */
struct altmdm_spi_rxbuff_s *rxbuff; /* Current recieve beffer. */
bool rxabort; /* Indicates whether the rx process is aborted. */
};
/* This structure describes the parameters for sleep modem. */
struct altmdm_spi_sleepmodem_s
{
struct altmdm_sys_lock_s lock; /* Lock on accessing the following
* parameters.
*/
struct altmdm_sys_flag_s done_flag; /* Notify that sleep request has been
* completed.
*/
int32_t result; /* Result of sleep request. */
bool requested; /* Indicates that sleep request has been requested. */
timer_t sv_timerid; /* Superviser timer. */
};
/* This structure describes the resource of the ALTMDM spi driver */
struct altmdm_spi_dev_s
{
/* Common fields */
bool is_not_run; /* Indicates xfer task is not run. */
int32_t task_id; /* xfer task ID. */
bool is_xferready; /* Indicates whether the modem is ready to xfer. */
struct altmdm_sys_flag_s xferready_flag; /* Used for wating ready to
* xfer.
*/
struct altmdm_sys_flag_s xfer_flag; /* Used for event handling of xfer
* task.
*/
struct altmdm_sys_flag_s dma_done_flag; /* Notify that DMA transfer has
* been completed.
*/
/* Parameter for recieve buffer */
struct altmdm_spi_rxbuffinfo_s rxbuffinfo;
/* Parameter for send data */
struct altmdm_spi_tx_s tx_param;
/* Parameter for recieve data */
struct altmdm_spi_rx_s rx_param;
/* Parameters for sleep modem */
struct altmdm_spi_sleepmodem_s sleep_param;
};
#endif
#endif /* __DRIVERS_MODEM_ALTMDM_ALTMDM_SPI_H */

View File

@ -0,0 +1,827 @@
/****************************************************************************
* drivers/modem/altmdm/altmdm_sys.c
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <errno.h>
#include <debug.h>
#include <nuttx/irq.h>
#include <signal.h>
#include "altmdm_dev.h"
#include "altmdm_sys.h"
#if defined(CONFIG_MODEM_ALTMDM)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
# define MY_TIMER_SIGNAL SIGUSR1
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: altmdm_sys_initlock
*
* Description:
* Initialize lock resource.
*
****************************************************************************/
int altmdm_sys_initlock(FAR struct altmdm_sys_lock_s *handle)
{
int ret;
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
int l_errno;
# endif
/* Check argument. */
if (handle == NULL)
{
return ERROR;
}
ret = sem_init(&handle->sem, 0, 1);
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
if (ret == ERROR)
{
l_errno = errno;
m_err("sem_init() failed:%d\n", l_errno);
}
# endif
return ret;
}
/****************************************************************************
* Name: altmdm_sys_deletelock
*
* Description:
* Delete lock resource
*
****************************************************************************/
int altmdm_sys_deletelock(FAR struct altmdm_sys_lock_s *handle)
{
int ret;
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
int l_errno;
# endif
/* Check argument. */
if (handle == NULL)
{
return ERROR;
}
ret = sem_destroy(&handle->sem);
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
if (ret == ERROR)
{
l_errno = errno;
m_err("sem_destroy() failed:%d\n", l_errno);
}
# endif
return ret;
}
/****************************************************************************
* Name: altmdm_sys_lock
*
* Description:
* Acquire lock.
*
****************************************************************************/
int altmdm_sys_lock(FAR struct altmdm_sys_lock_s *handle)
{
int ret;
int l_errno;
/* Check argument. */
if (handle == NULL)
{
return ERROR;
}
while (1)
{
ret = sem_wait(&handle->sem);
if (ret == ERROR)
{
l_errno = errno;
if (l_errno == EINTR)
{
continue;
}
m_err("sem_wait() failed:%d\n", l_errno);
}
break;
}
return ret;
}
/****************************************************************************
* Name: altmdm_sys_unlock
*
* Description:
* Relese lock.
*
****************************************************************************/
int altmdm_sys_unlock(FAR struct altmdm_sys_lock_s *handle)
{
int ret;
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
int l_errno;
# endif
/* Check argument. */
if (handle == NULL)
{
return ERROR;
}
ret = sem_post(&handle->sem);
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
if (ret == ERROR)
{
l_errno = errno;
m_err("sem_post() failed:%d\n", l_errno);
}
# endif
return ret;
}
/****************************************************************************
* Name: altmdm_sys_initcsem
*
* Description:
* Initialize counting semaphore.
*
****************************************************************************/
int altmdm_sys_initcsem(FAR struct altmdm_sys_csem_s *handle)
{
int ret;
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
int l_errno;
# endif
/* Check argument. */
if (handle == NULL)
{
return ERROR;
}
ret = sem_init(&handle->sem, 0, 0);
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
if (ret == ERROR)
{
l_errno = errno;
m_err("sem_init() failed:%d\n", l_errno);
}
# endif
return ret;
}
/****************************************************************************
* Name: altmdm_sys_deletecsem
*
* Description:
* Delete counting semaphore.
*
****************************************************************************/
int altmdm_sys_deletecsem(FAR struct altmdm_sys_csem_s *handle)
{
int ret;
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
int l_errno;
# endif
/* Check argument. */
if (handle == NULL)
{
return ERROR;
}
ret = sem_destroy(&handle->sem);
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
if (ret == ERROR)
{
l_errno = errno;
m_err("sem_destroy() failed:%d\n", l_errno);
}
# endif
return ret;
}
/****************************************************************************
* Name: altmdm_sys_waitcsem
*
* Description:
* Wait counting semaphore.
*
****************************************************************************/
int altmdm_sys_waitcsem(FAR struct altmdm_sys_csem_s *handle)
{
int ret;
int l_errno;
/* Check argument. */
if (handle == NULL)
{
return ERROR;
}
while (1)
{
ret = sem_wait(&handle->sem);
if (ret == ERROR)
{
l_errno = errno;
if (l_errno == EINTR)
{
continue;
}
m_err("sem_wait() failed:%d\n", l_errno);
}
break;
}
return ret;
}
/****************************************************************************
* Name: altmdm_sys_postcsem
*
* Description:
* Post counting semaphore.
*
****************************************************************************/
int altmdm_sys_postcsem(FAR struct altmdm_sys_csem_s *handle)
{
int ret;
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
int l_errno;
# endif
/* Check argument. */
if (handle == NULL)
{
return ERROR;
}
ret = sem_post(&handle->sem);
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
if (ret == ERROR)
{
l_errno = errno;
m_err("sem_post() failed:%d\n", l_errno);
}
# endif
return ret;
}
/****************************************************************************
* Name: altmdm_sys_getcsemvalue
*
* Description:
* Get value of counting semaphore.
*
****************************************************************************/
int altmdm_sys_getcsemvalue(FAR struct altmdm_sys_csem_s *handle,
FAR int *value)
{
int ret;
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
int l_errno;
# endif
/* Check argument. */
if ((handle == NULL) || (value == NULL))
{
return ERROR;
}
ret = sem_getvalue(&handle->sem, value);
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
if (ret == ERROR)
{
l_errno = errno;
m_err("sem_getvalue() failed:%d\n", l_errno);
}
# endif
return ret;
}
/****************************************************************************
* Name: altmdm_sys_initflag
*
* Description:
* Initialize event flag resource.
*
****************************************************************************/
int altmdm_sys_initflag(FAR struct altmdm_sys_flag_s *handle)
{
int ret;
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
int l_errno;
# endif
/* Check argument. */
if (handle == NULL)
{
return ERROR;
}
handle->flag = 0;
ret = sem_init(&handle->sem, 0, 0);
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
if (ret == ERROR)
{
l_errno = errno;
m_err("sem_init() failed:%d\n", l_errno);
}
# endif
return ret;
}
/****************************************************************************
* Name: altmdm_sys_deleteflag
*
* Description:
* Delete event flag resource.
*
****************************************************************************/
int altmdm_sys_deleteflag(FAR struct altmdm_sys_flag_s *handle)
{
int ret;
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
int l_errno;
# endif
/* Check argument. */
if (handle == NULL)
{
return ERROR;
}
ret = sem_destroy(&handle->sem);
# ifdef CONFIG_MODEM_ALTMDM_DEBUG
if (ret == ERROR)
{
l_errno = errno;
m_err("sem_destroy() failed:%d\n", l_errno);
}
# endif
return ret;
}
/****************************************************************************
* Name: altmdm_sys_waitflag
*
* Description:
* Wait event flag.
*
****************************************************************************/
int altmdm_sys_waitflag(FAR struct altmdm_sys_flag_s *handle,
uint32_t wait_pattern, uint32_t wait_mode,
FAR uint32_t * pattern, uint32_t timeout_ms)
{
int ret = OK;
int ret2;
int l_errno;
struct timespec abs_time;
struct timespec curr_time;
irqstate_t flags;
uint32_t ptn;
/* Check argument. */
if ((handle == NULL) || (pattern == NULL))
{
m_err("invalid parameter\n");
return ERROR;
}
switch (wait_mode)
{
case ALTMDM_SYS_FLAG_WMODEOR:
case ALTMDM_SYS_FLAG_WMODEAND:
break;
default:
m_err("invalid wait mode:%d\n", wait_mode);
return ERROR;
}
if (timeout_ms != ALTMDM_SYS_FLAG_TMOFEVR)
{
/* Get current time. */
ret = clock_gettime(CLOCK_REALTIME, &curr_time);
if (ret != OK)
{
return ret;
}
abs_time.tv_sec = timeout_ms / 1000;
abs_time.tv_nsec = (timeout_ms - (abs_time.tv_sec * 1000)) * 1000 * 1000;
abs_time.tv_sec += curr_time.tv_sec;
abs_time.tv_nsec += curr_time.tv_nsec;
/* Check more than 1 sec. */
if (abs_time.tv_nsec >= (1000 * 1000 * 1000))
{
abs_time.tv_sec += 1;
abs_time.tv_nsec -= (1000 * 1000 * 1000);
}
}
*pattern = 0;
while (1)
{
if (wait_mode == ALTMDM_SYS_FLAG_WMODEOR)
{
flags = enter_critical_section();
ptn = (handle->flag & wait_pattern);
if (ptn != 0)
{
/* Wait pattern matched. */
*pattern = ptn;
handle->flag = (handle->flag & ~ptn);
/* Clear the semaphore posted by altmdm_sys_setflag. */
while (1)
{
ret2 = sem_trywait(&handle->sem);
if (ret2 == ERROR)
{
break;
}
}
leave_critical_section(flags);
ret = OK;
break;
}
leave_critical_section(flags);
}
else
{
flags = enter_critical_section();
ptn = (handle->flag & wait_pattern);
if (ptn == wait_pattern)
{
/* Wait pattern matched. */
*pattern = ptn;
handle->flag = (handle->flag & ~ptn);
/* Clear the semaphore posted by altmdm_sys_setflag. */
while (1)
{
ret2 = sem_trywait(&handle->sem);
if (ret2 == ERROR)
{
break;
}
}
leave_critical_section(flags);
ret = OK;
break;
}
leave_critical_section(flags);
}
if (timeout_ms != ALTMDM_SYS_FLAG_TMOFEVR)
{
/* Wait for the semaphore to be posted until timeout occurs. */
ret = sem_timedwait(&handle->sem, &abs_time);
if (ret == ERROR)
{
l_errno = errno;
if (l_errno == EINTR)
{
continue;
}
m_err("sem_timedwait() failed:%d\n", l_errno);
break;
}
}
else
{
/* Wait for the semaphore to be posted forever. */
ret = sem_wait(&handle->sem);
if (ret == ERROR)
{
l_errno = errno;
if (l_errno == EINTR)
{
continue;
}
m_err("sem_wait() failed:%d\n", l_errno);
break;
}
}
}
return ret;
}
/****************************************************************************
* Name: altmdm_sys_setflag
*
* Description:
* Set event flag.
*
****************************************************************************/
int altmdm_sys_setflag(FAR struct altmdm_sys_flag_s *handle, uint32_t pattern)
{
int ret;
irqstate_t flags;
/* Check argument. */
if (handle == NULL)
{
return ERROR;
}
flags = enter_critical_section();
handle->flag = (handle->flag | pattern);
leave_critical_section(flags);
ret = sem_post(&handle->sem);
return ret;
}
/****************************************************************************
* Name: altmdm_sys_clearflag
*
* Description:
* Clear event flag.
*
****************************************************************************/
int altmdm_sys_clearflag(FAR struct altmdm_sys_flag_s *handle,
uint32_t pattern)
{
irqstate_t flags;
/* Check argument. */
if (handle == NULL)
{
return ERROR;
}
flags = enter_critical_section();
handle->flag = (handle->flag & ~pattern);
leave_critical_section(flags);
return OK;
}
/****************************************************************************
* Name: altmdm_sys_referflag
*
* Description:
* Refer event flag.
*
****************************************************************************/
int altmdm_sys_referflag(FAR struct altmdm_sys_flag_s *handle,
FAR struct altmdm_sys_flagstate_s *status)
{
irqstate_t flags;
/* Check argument. */
if ((handle == NULL) || (status == NULL))
{
return ERROR;
}
flags = enter_critical_section();
status->flag_pattern = handle->flag;
leave_critical_section(flags);
return OK;
}
/****************************************************************************
* Name: altmdm_sys_starttimer
*
* Description:
* Start timer.
*
****************************************************************************/
timer_t altmdm_sys_starttimer(int first_ms, int interval_ms,
FAR void *handler, int int_param,
FAR void *ptr_param)
{
int ret;
sigset_t mask;
struct sigaction sa;
struct sigevent sev;
struct itimerspec timer;
timer_t timerid;
/* Check argument. */
if (handler == NULL)
{
return NULL;
}
sigemptyset(&mask);
sigaddset(&mask, MY_TIMER_SIGNAL);
ret = sigprocmask(SIG_UNBLOCK, &mask, NULL);
if (ret != OK)
{
m_err("sigprocmask() failed:%d\n", ret);
return NULL;
}
sa.sa_sigaction = handler;
sa.sa_flags = SA_SIGINFO;
sigfillset(&sa.sa_mask);
sigdelset(&sa.sa_mask, MY_TIMER_SIGNAL);
ret = sigaction(MY_TIMER_SIGNAL, &sa, NULL);
if (ret != OK)
{
m_err("sigaction() failed:%d\n", ret);
return NULL;
}
sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = MY_TIMER_SIGNAL;
sev.sigev_value.sival_int = int_param;
sev.sigev_value.sival_ptr = ptr_param;
ret = timer_create(CLOCK_REALTIME, &sev, &timerid);
if (ret != OK)
{
m_err("timer_create() failed:%d\n", ret);
return NULL;
}
timer.it_value.tv_sec = first_ms / 1000;
timer.it_value.tv_nsec = (first_ms % 1000) * 1000 * 1000;
timer.it_interval.tv_sec = interval_ms / 1000;
timer.it_interval.tv_nsec = (interval_ms % 1000) * 1000 * 1000;
ret = timer_settime(timerid, 0, &timer, NULL);
if (ret != OK)
{
m_err("timer_settime() failed:%d\n", ret);
return NULL;
}
return timerid;
}
/****************************************************************************
* Name: altmdm_sys_restarttimer
*
* Description:
* Restart timer.
*
****************************************************************************/
int altmdm_sys_restarttimer(timer_t timerid, int first_ms, int interval_ms)
{
int ret;
struct itimerspec timer;
timer.it_value.tv_sec = first_ms / 1000;
timer.it_value.tv_nsec = (first_ms % 1000) * 1000 * 1000;
timer.it_interval.tv_sec = interval_ms / 1000;
timer.it_interval.tv_nsec = (interval_ms % 1000) * 1000 * 1000;
ret = timer_settime(timerid, 0, &timer, NULL);
if (ret != OK)
{
m_err("timer_settime() failed:%d\n", ret);
return ret;
}
return ret;
}
/****************************************************************************
* Name: altmdm_sys_stoptimer
*
* Description:
* Stop timer.
*
****************************************************************************/
void altmdm_sys_stoptimer(timer_t timerid)
{
sigset_t mask;
timer_delete(timerid);
sigfillset(&mask);
sigprocmask(SIG_SETMASK, &mask, NULL);
}
#endif

View File

@ -0,0 +1,274 @@
/****************************************************************************
* drivers/modem/altmdm/altmdm_sys.h
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation 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.
*
****************************************************************************/
#ifndef __DRIVERS_MODEM_ALTMDM_ALTMDM_SYS_H
#define __DRIVERS_MODEM_ALTMDM_ALTMDM_SYS_H
#if defined(CONFIG_MODEM_ALTMDM)
/****************************************************************************
* Included Files
****************************************************************************/
#include <time.h>
#include <semaphore.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ALTMDM_SYS_FLAG_WMODEOR 0
#define ALTMDM_SYS_FLAG_WMODEAND 1
#define ALTMDM_SYS_FLAG_TMOFEVR 0
/****************************************************************************
* Public Types
****************************************************************************/
struct altmdm_sys_lock_s
{
sem_t sem;
};
struct altmdm_sys_csem_s
{
sem_t sem;
};
struct altmdm_sys_flag_s
{
sem_t sem;
uint32_t flag;
};
struct altmdm_sys_flagstate_s
{
uint32_t flag_pattern;
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: altmdm_sys_initlock
*
* Description:
* Initialize lock resource.
*
****************************************************************************/
int altmdm_sys_initlock(FAR struct altmdm_sys_lock_s *handle);
/****************************************************************************
* Name: altmdm_sys_deletelock
*
* Description:
* Delete lock resource
*
****************************************************************************/
int altmdm_sys_deletelock(FAR struct altmdm_sys_lock_s *handle);
/****************************************************************************
* Name: altmdm_sys_lock
*
* Description:
* Acquire lock.
*
****************************************************************************/
int altmdm_sys_lock(FAR struct altmdm_sys_lock_s *handle);
/****************************************************************************
* Name: altmdm_sys_unlock
*
* Description:
* Relese lock.
*
****************************************************************************/
int altmdm_sys_unlock(FAR struct altmdm_sys_lock_s *handle);
/****************************************************************************
* Name: altmdm_sys_initcsem
*
* Description:
* Initialize counting semaphore.
*
****************************************************************************/
int altmdm_sys_initcsem(FAR struct altmdm_sys_csem_s *handle);
/****************************************************************************
* Name: altmdm_sys_deletecsem
*
* Description:
* Delete counting semaphore.
*
****************************************************************************/
int altmdm_sys_deletecsem(FAR struct altmdm_sys_csem_s *handle);
/****************************************************************************
* Name: altmdm_sys_waitcsem
*
* Description:
* Wait counting semaphore.
*
****************************************************************************/
int altmdm_sys_waitcsem(FAR struct altmdm_sys_csem_s *handle);
/****************************************************************************
* Name: altmdm_sys_postcsem
*
* Description:
* Post counting semaphore.
*
****************************************************************************/
int altmdm_sys_postcsem(FAR struct altmdm_sys_csem_s *handle);
/****************************************************************************
* Name: altmdm_sys_getcsemvalue
*
* Description:
* Get value of counting semaphore.
*
****************************************************************************/
int altmdm_sys_getcsemvalue(FAR struct altmdm_sys_csem_s *handle,
FAR int *value);
/****************************************************************************
* Name: altmdm_sys_initflag
*
* Description:
* Initialize event flag resource.
*
****************************************************************************/
int altmdm_sys_initflag(FAR struct altmdm_sys_flag_s *handle);
/****************************************************************************
* Name: altmdm_sys_deleteflag
*
* Description:
* Delete event flag resource.
*
****************************************************************************/
int altmdm_sys_deleteflag(FAR struct altmdm_sys_flag_s *handle);
/****************************************************************************
* Name: altmdm_sys_waitflag
*
* Description:
* Wait event flag.
*
****************************************************************************/
int altmdm_sys_waitflag(FAR struct altmdm_sys_flag_s *handle,
uint32_t wait_pattern, uint32_t wait_mode,
FAR uint32_t * pattern, uint32_t timeout_ms);
/****************************************************************************
* Name: altmdm_sys_setflag
*
* Description:
* Set event flag.
*
****************************************************************************/
int altmdm_sys_setflag(FAR struct altmdm_sys_flag_s *handle,
uint32_t pattern);
/****************************************************************************
* Name: altmdm_sys_clearflag
*
* Description:
* Clear event flag.
*
****************************************************************************/
int altmdm_sys_clearflag(FAR struct altmdm_sys_flag_s *handle,
uint32_t pattern);
/****************************************************************************
* Name: altmdm_sys_referflag
*
* Description:
* Refer event flag.
*
****************************************************************************/
int altmdm_sys_referflag(FAR struct altmdm_sys_flag_s *handle,
FAR struct altmdm_sys_flagstate_s *status);
/****************************************************************************
* Name: altmdm_sys_starttimer
*
* Description:
* Start timer.
*
****************************************************************************/
timer_t altmdm_sys_starttimer(int first_ms, int interval_ms,
FAR void *handler, int int_param,
FAR void *ptr_param);
/****************************************************************************
* Name: altmdm_sys_restarttimer
*
* Description:
* Restart timer.
*
****************************************************************************/
int altmdm_sys_restarttimer(timer_t timerid, int first_ms, int interval_ms);
/****************************************************************************
* Name: altmdm_sys_stoptimer
*
* Description:
* Stop timer.
*
****************************************************************************/
void altmdm_sys_stoptimer(timer_t timerid);
#endif
#endif /* __DRIVERS_MODEM_ALTMDM_ALTMDM_SYS_H */

View File

@ -0,0 +1,152 @@
/****************************************************************************
* include/nuttx/modem/altmdm.h
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation 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.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_MODEM_ALTMDM_H
#define __INCLUDE_NUTTX_MODEM_ALTMDM_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/spi/spi.h>
#include <queue.h>
#include <debug.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Debug ********************************************************************/
/* Non-standard debug that may be enabled just for testing the modem driver */
#ifdef CONFIG_MODEM_ALTMDM_DEBUG
# define m_err logerr
# define m_info loginfo
#else
# define m_err(x...)
# define m_info(x...)
#endif
#define MODEM_IOC_POWERON _MODEMIOC(1)
#define MODEM_IOC_POWEROFF _MODEMIOC(2)
#define MODEM_IOC_READABORT _MODEMIOC(3)
#define MODEM_IOC_SLEEP _MODEMIOC(4)
#define MODEM_IOC_PM_REGISTERCB _MODEMIOC(5)
#define MODEM_IOC_PM_DEREGISTERCB _MODEMIOC(6)
#define MODEM_IOC_PM_GETSTATE _MODEMIOC(7)
#define MODEM_IOC_PM_INITWAKELOCK _MODEMIOC(8)
#define MODEM_IOC_PM_ACQUIREWAKELOCK _MODEMIOC(9)
#define MODEM_IOC_PM_RELEASEWAKELOCK _MODEMIOC(10)
#define MODEM_IOC_PM_GETNUMOFWAKELOCK _MODEMIOC(11)
#define MODEM_IOC_PM_GETWAKELOCKSTATE _MODEMIOC(12)
#define MODEM_IOC_PM_ERR_REGISTERCB _MODEMIOC(13)
#define MODEM_IOC_PM_ERR_DEREGISTERCB _MODEMIOC(14)
#define MODEM_PM_CB_TYPE_NORMAL 0
#define MODEM_PM_CB_TYPE_ERROR 1
#define MODEM_PM_STATE_SLEEP 0
#define MODEM_PM_STATE_WAKE 1
#define MODEM_PM_ERR_RESET_BOOTSTAT_NONE 0x00
#define MODEM_PM_ERR_RESET_BOOTSTAT_BOOTING 0x01
#define MODEM_PM_ERR_RESET_BOOTSTAT_UPDATING 0x02
#define MODEM_PM_ERR_RESET_BOOTSTAT_DONE 0x10
/****************************************************************************
* Public Types
****************************************************************************/
struct altmdm_pm_wakelock_s
{
sq_entry_t queue;
int count;
};
typedef void (*altmdm_pm_cbfunc_t) (uint32_t state);
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: altmdm_register
*
* Description:
* Register the ALTMDM character device as 'devpath'.
*
* Input Parameters:
* devpath - The full path to the driver to register. E.g., "/dev/altmdm".
* dev - An instance of the SPI interface to use to communicate with
* ALTMDM.
*
* Returned Value:
* Not NULL on success; NULL on failure.
*
****************************************************************************/
FAR void *altmdm_register(FAR const char *devpath, FAR struct spi_dev_s *dev);
/****************************************************************************
* Name: altmdm_unregister
*
* Description:
* Unregister the ALTMDM character device.
*
* Input Parameters:
* handle - The pointer that getting from altmdm_register.
*
* Returned Value:
* None.
*
****************************************************************************/
void altmdm_unregister(FAR void *handle);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __INCLUDE_NUTTX_MODEM_ALTMDM_H */