diff --git a/arch/arm/src/cxd56xx/Make.defs b/arch/arm/src/cxd56xx/Make.defs index aad532cdda..3be6dd357b 100644 --- a/arch/arm/src/cxd56xx/Make.defs +++ b/arch/arm/src/cxd56xx/Make.defs @@ -86,6 +86,7 @@ endif CHIP_ASRCS += cxd56_farapistub.S CHIP_CSRCS = cxd56_allocateheap.c cxd56_idle.c +CHIP_CSRCS += cxd56_uid.c CHIP_CSRCS += cxd56_serial.c cxd56_uart.c cxd56_irq.c CHIP_CSRCS += cxd56_start.c CHIP_CSRCS += cxd56_timerisr.c diff --git a/arch/arm/src/cxd56xx/cxd56_uid.c b/arch/arm/src/cxd56xx/cxd56_uid.c new file mode 100644 index 0000000000..e56190cc4a --- /dev/null +++ b/arch/arm/src/cxd56xx/cxd56_uid.c @@ -0,0 +1,61 @@ +/**************************************************************************** + * arch/arm/src/cxd56xx/cxd56_uid.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 + +#include "chip.h" +#include "up_arch.h" +#include "cxd56_uid.h" +#include "hardware/cxd5602_topreg.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void cxd56_get_uniqueid(uint8_t uniqueid[]) +{ + uint32_t cuid0 = getreg32(CXD56_TOPREG_CUID0); + uint32_t cuid1 = getreg32(CXD56_TOPREG_CUID1); + + uniqueid[0] = (uint8_t)((cuid1 >> 0) & 0xff); + uniqueid[1] = (uint8_t)((cuid0 >> 24) & 0xff); + uniqueid[2] = (uint8_t)((cuid0 >> 16) & 0xff); + uniqueid[3] = (uint8_t)((cuid0 >> 8) & 0xff); + uniqueid[4] = (uint8_t)((cuid0 >> 0) & 0xff); +} diff --git a/arch/arm/src/cxd56xx/cxd56_uid.h b/arch/arm/src/cxd56xx/cxd56_uid.h new file mode 100644 index 0000000000..a8e3057b7a --- /dev/null +++ b/arch/arm/src/cxd56xx/cxd56_uid.h @@ -0,0 +1,53 @@ +/**************************************************************************** + * arch/arm/src/cxd56xx/cxd56_uid.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 __ARCH_ARM_SRC_CXD56XX_CXD56_UID_H +#define __ARCH_ARM_SRC_CXD56XX_CXD56_UID_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void cxd56_get_uniqueid(uint8_t uniqueid[]); + +#endif /* __ARCH_ARM_SRC_CXD56XX_CXD56_UID_H */ diff --git a/configs/spresense/include/board.h b/configs/spresense/include/board.h index 07c895aaac..6a13990566 100644 --- a/configs/spresense/include/board.h +++ b/configs/spresense/include/board.h @@ -119,12 +119,16 @@ #define BOARD_LED1 (0) #define BOARD_LED2 (1) -#define BOARD_NLEDS (2) +#define BOARD_LED3 (2) +#define BOARD_LED4 (3) +#define BOARD_NLEDS (4) /* LED bits for use with board_userled_all() */ #define BOARD_LED1_BIT (1 << BOARD_LED1) #define BOARD_LED2_BIT (1 << BOARD_LED2) +#define BOARD_LED3_BIT (1 << BOARD_LED3) +#define BOARD_LED4_BIT (1 << BOARD_LED4) /* LED pattern for use with board_autoled_on() and board_autoled_off() * ON OFF diff --git a/configs/spresense/src/Makefile b/configs/spresense/src/Makefile index 57703a3170..e1fd83c38d 100644 --- a/configs/spresense/src/Makefile +++ b/configs/spresense/src/Makefile @@ -58,6 +58,10 @@ endif ifeq ($(CONFIG_ARCH_LEDS),y) CSRCS += cxd56_leds.c +else +ifeq ($(CONFIG_USERLED),y) +CSRCS += cxd56_userleds.c +endif endif ifeq ($(CONFIG_CXD56_PWM),y) diff --git a/configs/spresense/src/cxd56_bringup.c b/configs/spresense/src/cxd56_bringup.c index 892ccfd3b9..143eeffd70 100644 --- a/configs/spresense/src/cxd56_bringup.c +++ b/configs/spresense/src/cxd56_bringup.c @@ -268,6 +268,14 @@ int cxd56_bringup(void) } #endif +#ifdef CONFIG_USERLED_LOWER + ret = userled_lower_initialize("/dev/userleds"); + if (ret < 0) + { + _err("ERROR: Failed to initialze led. \n"); + } +#endif + #ifdef CONFIG_CXD56_SFC ret = board_flash_initialize(); if (ret < 0) diff --git a/configs/spresense/src/cxd56_userleds.c b/configs/spresense/src/cxd56_userleds.c new file mode 100644 index 0000000000..60bb3d2250 --- /dev/null +++ b/configs/spresense/src/cxd56_userleds.c @@ -0,0 +1,118 @@ +/**************************************************************************** + * configs/spresense/src/cxd56_userleds.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 + +#include +#include +#include + +#include + +#ifdef CONFIG_USERLED_LOWER +#include +#endif + +#include "cxd56_gpio.h" +#include "cxd56_pinconfig.h" + +#ifndef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Check if the following are defined in the board.h */ + +#ifndef BOARD_LED1_BIT +#error "BOARD_LED1_BIT must be defined in board.h !!" +#endif +#ifndef BOARD_LED2_BIT +#error "BOARD_LED2_BIT must be defined in board.h !!" +#endif +#ifndef BOARD_LED3_BIT +#error "BOARD_LED3_BIT must be defined in board.h !!" +#endif +#ifndef BOARD_LED4_BIT +#error "BOARD_LED4_BIT must be defined in board.h !!" +#endif + +#define GPIO_LED1 (PIN_I2S1_BCK) +#define GPIO_LED2 (PIN_I2S1_LRCK) +#define GPIO_LED3 (PIN_I2S1_DATA_IN) +#define GPIO_LED4 (PIN_I2S1_DATA_OUT) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_userled_initialize + ****************************************************************************/ + +void board_userled_initialize(void) +{ + cxd56_gpio_write(GPIO_LED1, false); + cxd56_gpio_write(GPIO_LED2, false); + cxd56_gpio_write(GPIO_LED3, false); + cxd56_gpio_write(GPIO_LED4, false); +} + +/**************************************************************************** + * Name: board_userled + ****************************************************************************/ + +void board_userled(int led, bool ledon) +{ + board_gpio_write(ledcfg, ledon); +} + +/**************************************************************************** + * Name: board_userled_all + ****************************************************************************/ + +void board_userled_all(uint8_t ledset) +{ + cxd56_gpio_write(GPIO_LED1, (ledset & BOARD_LED1_BIT) != 0); + cxd56_gpio_write(GPIO_LED2, (ledset & BOARD_LED2_BIT) != 0); + cxd56_gpio_write(GPIO_LED3, (ledset & BOARD_LED3_BIT) != 0); + cxd56_gpio_write(GPIO_LED4, (ledset & BOARD_LED4_BIT) != 0); +} + +#endif /* !CONFIG_ARCH_LEDS */