diff --git a/boards/m4a-24g/include/board.h b/boards/m4a-24g/include/board.h index 2e30b2c04..010923813 100644 --- a/boards/m4a-24g/include/board.h +++ b/boards/m4a-24g/include/board.h @@ -23,22 +23,11 @@ #include "cpu.h" #include "periph_conf.h" -#include "periph_cpu.h" -#include "periph/cpuid.h" #ifdef __cplusplus extern "C" { #endif -/** - * @brief Get the CPU unique ID of this platform - * This function gets base cpu address using cpuid_get - * - * @param id pointer to char array with CPUID_LEN size. - * - */ -#define CPUID(id) cpuid_get(id); - /** * @name xtimer configuration * @{ diff --git a/boards/m4a-mb/include/board.h b/boards/m4a-mb/include/board.h index 09a37a0e1..2cc150507 100644 --- a/boards/m4a-mb/include/board.h +++ b/boards/m4a-mb/include/board.h @@ -20,23 +20,12 @@ #include "cpu.h" #include "periph_conf.h" -#include "periph_cpu.h" -#include "periph/cpuid.h" #ifdef __cplusplus extern "C" { #endif -/** - * @brief Get the CPU unique ID of this platform - * This function gets base cpu address using cpuid_get - * - * @param id pointer to char array with CPUID_LEN size. - * - */ -#define CPUID(id) cpuid_get(id); - /** * @name xTimer configuration * @{ diff --git a/boards/meshme/Kconfig b/boards/meshme/Kconfig new file mode 100644 index 000000000..b9b39cc78 --- /dev/null +++ b/boards/meshme/Kconfig @@ -0,0 +1,21 @@ +# Copyright (c) 2020 HAW Hamburg +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +config BOARD + default "meshme" if BOARD_MESHME + +config BOARD_MESHME + bool + default y + select CPU_MODEL_CC2538SF53 + select HAS_PERIPH_ADC + select HAS_PERIPH_I2C + select HAS_PERIPH_RTT + select HAS_PERIPH_SPI + select HAS_PERIPH_TIMER + select HAS_PERIPH_UART + # Others + select HAS_RIOTBOOT diff --git a/boards/meshme/Makefile b/boards/meshme/Makefile new file mode 100644 index 000000000..f8fcbb53a --- /dev/null +++ b/boards/meshme/Makefile @@ -0,0 +1,3 @@ +MODULE = board + +include $(RIOTBASE)/Makefile.base diff --git a/boards/meshme/Makefile.dep b/boards/meshme/Makefile.dep new file mode 100644 index 000000000..4c3b9b35e --- /dev/null +++ b/boards/meshme/Makefile.dep @@ -0,0 +1,8 @@ +ifneq (,$(filter netdev_default,$(USEMODULE))) + USEMODULE += cc2538_rf + USEMODULE += cc2538_rf_obs_sig +endif + +ifneq (,$(filter saul_default,$(USEMODULE))) + USEMODULE += saul_gpio +endif diff --git a/boards/meshme/Makefile.features b/boards/meshme/Makefile.features new file mode 100644 index 000000000..7c0122998 --- /dev/null +++ b/boards/meshme/Makefile.features @@ -0,0 +1,13 @@ +CPU = cc2538 +CPU_MODEL = cc2538sf53 + +# Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_adc +FEATURES_PROVIDED += periph_i2c +FEATURES_PROVIDED += periph_rtt +FEATURES_PROVIDED += periph_spi +FEATURES_PROVIDED += periph_timer +FEATURES_PROVIDED += periph_uart + +# Put other features for this board (in alphabetical order) +FEATURES_PROVIDED += riotboot diff --git a/boards/meshme/Makefile.include b/boards/meshme/Makefile.include new file mode 100644 index 000000000..179cd1c7e --- /dev/null +++ b/boards/meshme/Makefile.include @@ -0,0 +1,10 @@ +# setup the default port depending on the host OS +PORT_LINUX ?= $(firstword $(sort $(wildcard /dev/ttyUSB*))) +# for MacOS +PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbserial*))) + +PROGRAMMER ?= cc2538-bsl +CC2538_BSL_FLAGS_OPTS ?= --bootloader-invert-lines +CC2538_BSL_FLASHFILE ?= $(HEXFILE) + +include $(RIOTBOARD)/common/cc2538/Makefile.include diff --git a/boards/meshme/board.c b/boards/meshme/board.c new file mode 100644 index 000000000..0e9798623 --- /dev/null +++ b/boards/meshme/board.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 Mesh4all + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * @brief Board specific implementations for the MeshMe board + * @copyright Copyright (c) 2022 Mesh for All (Mesh4all) + */ +#include "board.h" +#include "cpu.h" +#include "periph/gpio.h" + +void board_init(void) { + + // initialize the on-board LED 0 + gpio_init(LED0_PIN, GPIO_OUT); + + // initialize the on-board LED 1 + gpio_init(LED1_PIN, GPIO_OUT); + + // initialize the on-board LED 2 + gpio_init(LED2_PIN, GPIO_OUT); + + // initialize the on-board LED 3 + gpio_init(LED3_PIN, GPIO_OUT); + + // initialize the on-board user-button SW0 + gpio_init(BTN0_PIN, BTN0_MODE); + + // initialize the on-board user-button SW0 + gpio_init(BTN1_PIN, BTN1_MODE); + + if (IS_USED(MODULE_CC2538_RF)) { + gpio_init(HGM_PIN, GPIO_OUT); + HGM_ON; + } +// Compilation error +// workaround for lower RIOT versions, +#if RIOT_VERSION_CODE < RIOT_VERSION_NUM(2021, 10, 0, 0) + cpu_init(); +#endif +} diff --git a/boards/meshme/doc.txt b/boards/meshme/doc.txt new file mode 100644 index 000000000..10da9c55e --- /dev/null +++ b/boards/meshme/doc.txt @@ -0,0 +1,55 @@ +/** +@defgroup boards_meshme MeshMe CC2538 +20dBm PA +@ingroup boards +@brief Mesh4All 2.4 GHz board + 20dBm PA + +# Overview +MeshMe is a complete communications system based on TI's CC2538 system on chip (SoC) and +the CC2592 front end, featuring an ARM Cortex-M3 with 512KiB flash, 32KiB RAM and 2.4 GHz RF interface. + +## Hardware + +### Brain and RF, CC2538SF53 + +The CC2538 SoC combines an ARM Cortex-M3 microcontroller with an IEEE802.15.4 radio +plus a bunch of peripherals as you can see in the following table. + +| MCU | CC2538SF53 | +|:----------------- |:------------------------- | +| Family | ARM Cortex-M3 | +| Vendor | Texas Instruments | +| RAM | 32KiB | +| Flash | 512KiB | +| Frequency | 32MHz | +| FPU | no | +| Timers | 4 | +| ADCs | 1x 12-bit (8 channels) | +| UARTs | 2 | +| SPIs | 2 | +| I2Cs | 1 | +| Vcc | 2V - 3.6V | +| Datasheet | [Datasheet](http://www.ti.com/lit/gpn/cc2538) (pdf file) | +| Reference Manual | [Reference Manual](http://www.ti.com/lit/pdf/swru319) | + +### Power Amplifier, CC2592 + +The TI's CC2592 is front end (FE) designed for the CC25XX family, it contains PA, LNA, switches, RF-matching, and balun. + +| CC2592 | Min | Max | +|:------------------|:--------:|:---------:| +| Vcc | 2V | 3.7V | +| Frequency range | 2400MHz | 2483.5MHz | +| Output power (PA) | | 22 dBm | +| LNA Gain | 6 dB | 11 dB | +| Datasheet | [Datasheet](https://www.ti.com/lit/ds/symlink/cc2592.pdf) (pdf file) | + +The device is controlled by three digital terminals, PA_EN, LNA_EN, and HGM. +The control logic is shown in the following table: + +| PA_EN | LNA_EN | HGM | Mode of operation | +|:-----:|:------:|:---:|:------------------| +| 0 | 0 | X | Power down | +| X | 1 | 0 | Rx mode Low Gain | +| X | 1 | 1 | Rx mode High Gain | +| 1 | 0 | X | Tx mode | +*/ diff --git a/boards/meshme/include/board.h b/boards/meshme/include/board.h new file mode 100644 index 000000000..9de9c2c24 --- /dev/null +++ b/boards/meshme/include/board.h @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2014 Loci Controls Inc. + * Copyright (C) 2022 Mesh4all + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_meshme + * @{ + * + * @file + * @brief Board specific definitions for the MeshMe 24G20P + * + * @author Ian Martin + * @author Luis A. Ruiz + */ +#ifndef BOARD_H +#define BOARD_H + +#include "cpu.h" +#include "periph/gpio.h" +#include "cc2538_eui_primary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name LED pin definitions and handlers + * @{ + */ +#define LED0_PIN GPIO_PIN(PORT_C, 5) /*!< LED-0 (?) routed to PC5 pin */ +#define LED0_ON gpio_set(LED0_PIN) /*!< LED-0 On handler */ +#define LED0_OFF gpio_clear(LED0_PIN) /*!< LED-0 Off handler */ +#define LED0_TOGGLE gpio_toggle(LED0_PIN) /*!< LED-0 Toggle handler */ + +#define LED1_PIN GPIO_PIN(PORT_C, 4) /*!< LED-1 (green) routed to PC4 pin */ +#define LED1_ON gpio_set(LED1_PIN) /*!< LED-1 On handler */ +#define LED1_OFF gpio_clear(LED1_PIN) /*!< LED-1 Off handler */ +#define LED1_TOGGLE gpio_toggle(LED1_PIN) /*!< LED-1 Toggle handler */ + +#define LED2_PIN GPIO_PIN(PORT_C, 1) /*!< LED 2 (orange) routed to PC1 pin */ +#define LED2_ON gpio_set(LED2_PIN) /*!< LED2 On handler */ +#define LED2_OFF gpio_clear(LED2_PIN) /*!< LED2 Off handler */ +#define LED2_TOGGLE gpio_toggle(LED2_PIN) /*!< LED2 Toggle handler */ + +#define LED3_PIN GPIO_PIN(PORT_C, 0) /*!< LED 3 (red) routed to PC0 pin */ +#define LED3_ON gpio_set(LED3_PIN) /*!< LED3 On handler */ +#define LED3_OFF gpio_clear(LED3_PIN) /*!< LED3 Off handler */ +#define LED3_TOGGLE gpio_toggle(LED3_PIN) /*!< LED3 Toggle handler */ +/** @} */ + +/** + * @name User button SW0 pin definition, labeled K1 on the board + * @{ + */ +#define BTN0_PIN GPIO_PIN(PORT_C, 7) /*!< It's routed to PC7 pin */ +#define BTN0_MODE GPIO_IN_PU /*!< Pin mode */ +/** @} */ + +/** + * @name User button SW1 pin definition, labeled K2 on the board + * @{ + */ +#define BTN1_PIN GPIO_PIN(PORT_C, 6) /*!< It's routed to PC6 pin */ +#define BTN1_MODE GPIO_IN_PU /*!< Pin mode */ +/** @} */ + +/** + * @name Flash Customer Configuration Area (CCA) parameters + * @{ + */ +#ifndef UPDATE_CCA +#define UPDATE_CCA 1 /*!< On/Off Customer Configuration Area should be updated */ +#endif + +#define CCA_BACKDOOR_ENABLE 1 /*!< On/Off the backdoor on boot */ +#define CCA_BACKDOOR_PORT_A_PIN 3 /*!< Boot button is PORT_A, 3 (PA3) */ +#define CCA_BACKDOOR_ACTIVE_LEVEL 0 /*!< Active when signal is low: 0 */ +/** @} */ + +/** + * @name xtimer configuration + * @{ + */ +#define XTIMER_WIDTH (16) /*!< ToDo */ +#define XTIMER_BACKOFF (50) /*!< ToDo */ +#define XTIMER_ISR_BACKOFF (40) /*!< ToDo */ +/** @} */ + +/** + * @name RF Front-End configuration + * + * @brief The FE CC2592 is controlled by the CC2538 with 3 pins, both are connected as follow: + * + * | CC2538 (MCU) | CC2592 (FE) | Description | + * |--------------|-------------|----------------------------------------| + * | PORT_D, 2 | HGM_EN | High Gain Mode (enabled/disabled) | + * | PORT_C, 2 | LNA_EN | Low Noise Amplifier (enabled/disabled) | + * | PORT_C, 3 | PA_EN | Power Amplifier (enabled/disabled) | + * + * The CC2538 RF Core needs to use "observable signals" to drive the LNA_EN and the PA_EN pins + * @{ + */ +#define CONFIG_CC2538_RF_OBS_SIG_0_PCX 3 /*!< tx active to PC3, it controls the PA */ +#define CONFIG_CC2538_RF_OBS_SIG_1_PCX 2 /*!< rx active to PC2, it controls the LNA */ +#define CONFIG_CC2538_RF_OBS_SIG_2_PCX 0 /*!< rssi valid, routed to the on board red LED PC0 */ + +#define HGM_PIN GPIO_PIN(PORT_D, 2) /*!< High Gain Mode (HGM) pin */ +#define HGM_ON gpio_set(HGM_PIN) /*!< HGM on handler */ +#define HGM_OFF gpio_clear(HGM_PIN) /*!< HGM off handler */ +#define HGM_TOGGLE gpio_toggle(HGM_PIN) /*!< HGM toggle handler */ +/** @} */ + +/** + * @brief Initialize board specific hardware, including clock, LEDs and std-IO + */ +void board_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* BOARD_H */ +/** @} */ diff --git a/boards/meshme/include/gpio_params.h b/boards/meshme/include/gpio_params.h new file mode 100644 index 000000000..01feaff4f --- /dev/null +++ b/boards/meshme/include/gpio_params.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2017 DAI Labor Technische Universität Berlin + * Copyright (C) 2022 Mesh4all + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_meshme + * @{ + * + * @file + * @brief Board specific configuration of direct mapped GPIOs + * + * @author Anon Mall + */ + +#ifndef GPIO_PARAMS_H +#define GPIO_PARAMS_H + +#include "board.h" +#include "saul/periph.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief GPIO pin configuration + */ +static const saul_gpio_params_t saul_gpio_params[] = { + { + .name = "LED0 (?)", + .pin = LED0_PIN, + .mode = GPIO_OUT, + .flags = SAUL_GPIO_INIT_CLEAR, + }, + { + .name = "LED1 (Green)", + .pin = LED1_PIN, + .mode = GPIO_OUT, + .flags = SAUL_GPIO_INIT_CLEAR, + }, + { + .name = "LED2 (Orange)", + .pin = LED2_PIN, + .mode = GPIO_OUT, + .flags = SAUL_GPIO_INIT_CLEAR, + }, + { + .name = "LED3 (Red)", + .pin = LED3_PIN, + .mode = GPIO_OUT, + .flags = SAUL_GPIO_INIT_CLEAR, + }, + { + .name = "SW0/K1 button", + .pin = BTN0_PIN, + .mode = BTN0_MODE, + }, + { + .name = "SW1/K2 button", + .pin = BTN1_PIN, + .mode = BTN1_MODE, + }, +}; + +#ifdef __cplusplus +} +#endif + +#endif /* GPIO_PARAMS_H */ +/** @} */ diff --git a/boards/meshme/include/periph_conf.h b/boards/meshme/include/periph_conf.h new file mode 100644 index 000000000..8d1a4e015 --- /dev/null +++ b/boards/meshme/include/periph_conf.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2017 DAI Labor Technische Universität Berlin + * Copyright (C) 2022 Mesh4all + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @ingroup boards_meshme + * @{ + * + * @file + * @brief Peripheral MCU configuration for the MeshMe board + * + * @author Anon Mall + * @author luisan00 + */ + +#ifndef PERIPH_CONF_H +#define PERIPH_CONF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include "cpu.h" +#include "periph_cpu.h" +#include "periph/cpuid.h" + +#include "cfg_clk_default.h" +#include "cfg_timer_default.h" + +/** + * @name UART configuration + * @{ + */ + +/** + * @brief List of available UART ports, pins are mapped as follows: + * + * | UART Dev | TX pin | RX pin | CTS pin| RTS pin | + * |----------|--------|--------|--------|---------| + * | 0 | PA0 | PA1 | Undef. | Undef. | + * + */ +static const uart_conf_t uart_config[] = { + { + .dev = UART0_BASEADDR, + .rx_pin = GPIO_PIN(PORT_A, 0), + .tx_pin = GPIO_PIN(PORT_A, 1), +#ifdef MODULE_PERIPH_UART_HW_FC + .cts_pin = GPIO_UNDEF, + .rts_pin = GPIO_UNDEF, +#endif + }, +}; + +#define UART_0_ISR isr_uart0 /*!< interrupt function name mapping */ +#define UART_NUMOF ARRAY_SIZE(uart_config) /*!< Number of UARTs */ +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* PERIPH_CONF_H */ +/** @} */ diff --git a/doc/doxygen/src/media/Analog_moisture_sensor_001.jpeg b/doc/doxygen/src/media/Analog_moisture_sensor_001.jpeg new file mode 100644 index 000000000..bedfc79ed Binary files /dev/null and b/doc/doxygen/src/media/Analog_moisture_sensor_001.jpeg differ diff --git a/doc/doxygen/src/media/DS18B20-Sensor-Pinout.jpg b/doc/doxygen/src/media/DS18B20-Sensor-Pinout.jpg new file mode 100644 index 000000000..f6da40f30 Binary files /dev/null and b/doc/doxygen/src/media/DS18B20-Sensor-Pinout.jpg differ diff --git a/doc/doxygen/src/media/Electronic-sheme-analog_moisture_sensor.png b/doc/doxygen/src/media/Electronic-sheme-analog_moisture_sensor.png new file mode 100644 index 000000000..102a7b267 Binary files /dev/null and b/doc/doxygen/src/media/Electronic-sheme-analog_moisture_sensor.png differ diff --git a/firmware/doc.txt b/firmware/doc.txt index ca42c1042..88c31e663 100644 --- a/firmware/doc.txt +++ b/firmware/doc.txt @@ -1,18 +1,47 @@ /** @defgroup m4a-firmware Reference firmware -### What goes here? -Specific documentation for our reference firmware ; m4a-firmware +### Firmware -You can find specific documentation for the sys, peripherals, and network folders. +This is the core of Mesh4All, you can find specific documentation for the sys, peripherals, and network folders. +### Network -### network -UDP client, UDP server. +This section has modules like: -### peripherals -Humidity and temperature sensors. + - UDP client: Make use of Internet Protocol of the TCP/IP suit. -### sys -AT commands, udp serialization, storage, ipv6 address. + - UDP server: Process all request sent by an udp client device. + + - RPL protocol: The functions to start RPL and add a node dodag (Root) +or dag (Slave). + + - Radio: Module that handles all low power and low consumption wireless devices. + + - Net tools: Contains all about networks tools. + + - Chamos (Communication Handler for Addressing Management | Origin Server): It's used for +server-side communication. + + - Border Router: The module sets an IPV6 address in a wireless or wired interface. + +### Peripherals + + - Moisture sensor: Gets humidity and temperature data of a certain environment. + + - Temperature sensor (DS18): Get the data of the temperature sensor. + +### Sys + + - AT commands: Establish a connection with a wifi-subsystem, which handles AT commands +sent through the shell. + + - Serialization: Get and decode a data of the sensors arrived from udp server and decodes +the message before sending it to udp client. This implementation uses a library tinycbor. + + - Storage: Saves data in the flash memory in pages that we can write and read, the max size +to save is 16 page. + + - Unique_id: Get a specific id for each device and you have three options to get an unique +IPV6 address (static, random, custom). */ diff --git a/firmware/network/radio/Makefile.dep b/firmware/network/radio/Makefile.dep index 5186279ed..94bb09697 100644 --- a/firmware/network/radio/Makefile.dep +++ b/firmware/network/radio/Makefile.dep @@ -2,4 +2,3 @@ USEMODULE += netdev_default USEMODULE += gnrc_ipv6_default USEMODULE += gnrc_netif_ieee802154 USEMODULE += auto_init_gnrc_netif -USEMODULE += uniqueid diff --git a/firmware/network/radio/doc.txt b/firmware/network/radio/doc.txt index 6058c791b..94da19891 100644 --- a/firmware/network/radio/doc.txt +++ b/firmware/network/radio/doc.txt @@ -5,7 +5,7 @@ ### Radio -In this module are all low power and low consumption wireless device, +In this module are all low power and low consumption wireless devices, it can find devices based on the zigbee and 6lowpan protocols, In addition to that, these devices can follow the guidelines established in the IEEE802.14.5 standard. @@ -16,11 +16,11 @@ it's between the range of 11 to 26 and in the case of the radio device is multib you could works in the band under to 2.4GHz these channels are between 0 and 10. The functionalities of the radio module allow to obtain and configure the characteristics of -the wireless networkInterface. This allows knowing the current state of the physical +the wireless network interface. This allows knowing the current state of the physical configuration and manipulating it to obtain the better optimization. The radio module includes a kconfig setup, this means to could be obtained an statically setup -of any device, also the kconfig, and the module it's adjusted to the specified device. this features +of any device, also the kconfig, and the module it's adjusted to the specified device. These features are provided by the following table: | Driver |TX_POWER_MIN (dBm) | TX_POWER_MAX (dBm)|Dual band | channel range || diff --git a/firmware/network/udp_client/include/udp_client.h b/firmware/network/udp_client/include/udp_client.h index e0c9abb4d..01f3a160e 100644 --- a/firmware/network/udp_client/include/udp_client.h +++ b/firmware/network/udp_client/include/udp_client.h @@ -39,7 +39,7 @@ extern "C" { * @param payload_len [int] size of the message * @return int */ -int udp_send(int *port, char *address, uint8_t *message, size_t *payload_len); +int udp_send(const uint16_t port, char *address, uint8_t *message, size_t *payload_len); #ifdef __cplusplus } diff --git a/firmware/network/udp_client/udp_client.c b/firmware/network/udp_client/udp_client.c index 03277ea89..4c3c3a643 100644 --- a/firmware/network/udp_client/udp_client.c +++ b/firmware/network/udp_client/udp_client.c @@ -25,7 +25,7 @@ #include "net/ipv6/addr.h" #include "udp_client.h" -int udp_send(const int port, char *address, uint8_t *message, size_t *payload_len) { +int udp_send(const uint16_t port, char *address, uint8_t *message, size_t *payload_len) { int res; sock_udp_ep_t remote = {.family = AF_INET6}; diff --git a/firmware/peripherals/doc.txt b/firmware/peripherals/doc.txt index 30f3d6f97..e9479804e 100644 --- a/firmware/peripherals/doc.txt +++ b/firmware/peripherals/doc.txt @@ -2,16 +2,35 @@ @defgroup peripherals Peripherals @ingroup m4a-firmware -### What goes here? +### Peripherals Specific documentation for our reference peripherals; In the next module you can find: -### ds18_sensor +### Kconfig Setup -Module to get temperature data. +The peripherals has an effect in each board. a property of the board is periph_conf where is all +specifications of each communication protocol used, converters analog to digital, and PWM parameters. +So, peripherals actually provides support to manage de VREF of ADC channels, This will give more precision +with the measurements. -### moisture_sensor + | Macro of the periph_conf | Voltage Referenced | type | + |:-------------------------------:|:------------------------------------:|:---------------:| + | CONFIG_ADC_VREF_DEFAULT | 1.0V | Internal | + | CONFIG_ADC_VREF_INTVCC0 | 1/1.48 VDDANA | Internal | + | CONFIG_ADC_VREF_INTVCC1 | 1/2 VDDANA (only for VDDANA > 2.0V) | Internal | + | CONFIG_ADC_VREF_EXT1 | External reference #1 | External | + | CONFIG_ADC_VREF_EXT2 | External reference #2 | External | -Module to get moisture data. +### Ds18_sensor + +This is a soil temperature sensor that could provide the current measurement +in degrees centigrades "°C". this works with any digital pin, but needs to use the +one wire protocol to obtain the data from itself. + +### Moisture_sensor + +A peripheral that could read through adc pins, getting an analog measurement, this works with a +10-bit resolution, and it's adjustable to work with 3.3V (in low consumption) and 5V for more +information about the peripheral see @ref moisture_sensor module */ \ No newline at end of file diff --git a/firmware/peripherals/ds18_sensor/doc.txt b/firmware/peripherals/ds18_sensor/doc.txt index ed10df2d3..cbe57e5dc 100644 --- a/firmware/peripherals/ds18_sensor/doc.txt +++ b/firmware/peripherals/ds18_sensor/doc.txt @@ -2,10 +2,29 @@ @defgroup ds18_sensor Ds18 sensor @ingroup peripherals -### What goes here? +### Ds18 soil sensor -This module is used to get the data of the temperature sensor. The function -``` init_temperature_sensor ```initialize the sensor and the function -``` get_temperature_value ``` gets the values. +The ds18b20 is a temperature sensor with a range between -55 °C and 125 °C, its operative +voltage is 3V or 5V respectively, only needs a data pin to transfer data an a MCU using one-wire communication. +Has an acurracy of 0.5 °C. The output resolution is programmable between 9 - 12 bits, conversion time of 750 ms +at 12-bit resolution. + +### Pinout scheme + +\image html DS18B20-Sensor-Pinout.jpg Ds18b20 Pinout scheme width=40% + +This module works with the ds18b20 peripheral, this implement two steps, +`init_temperature_sensor()` and `get_temperature_value()`. the first function checks +if the peripheral is connected to a designed pin. when the initialization it's successfully returns `DS18_OK` +in case that the peripheral was not found returns a `DS18_ERROR`. + +To the function `get_temperature_value()` needs receive a int16_t variable as parameter (Signed Integer variable), because the +peripheral could operates with positive and negative values. when you are reading the received data it could be observed +in this way: + + | Value read |Integer part | Decimal part | Temp read in °C | + |:-----------:|:-----------------:|:-----------------:|:---------------:| + | 1517 | 15 | 17 | 15.17 °C | + | -1517 | -15 | 17 | -15.17 °C | */ \ No newline at end of file diff --git a/firmware/peripherals/moisture_sensor/doc.txt b/firmware/peripherals/moisture_sensor/doc.txt index cb091ed28..ced1cad52 100644 --- a/firmware/peripherals/moisture_sensor/doc.txt +++ b/firmware/peripherals/moisture_sensor/doc.txt @@ -2,11 +2,23 @@ @defgroup moisture_sensor Moisture sensor @ingroup peripherals -### What goes here? +### Analog Capacitive Moisture sensor V1.2 -This module gets the data of the moisture sensor. +This module contains all about the manage the read data from the Moisture sensor. It's an Analog +sensor that operates betwwen 3.3V and 5.0V, has three pins VCC (Red wire), GND (Black wire), DATA (Yellow Wire), +There is a fixed frequency oscillator that is built with a 555 Timer IC. The square wave generated is then fed +to the sensor like a capacitor. To a square wave signal that capacitor, however, has a certain reactance, or +for argument’s sake a resistance that forms a voltage divider with a pure ohm type resistor (the 10k one on pin 3). +The greater is the soil moisture, the higher the capacitance of the sensor. Consequently, there is a smaller reactance +to the square wave, thus lowering the voltage on the signal line. The voltage on the Analog signalpin can be measured by +an analog pin of a MCU. -Note: This is an adc device, for the correct functioning of this module you have to use 3.3V -and 10bits resolution. +@image html Electronic-sheme-analog_moisture_sensor.png Fig. 1.1 Electronical scheme of the Analog Capacitive Moisture Sensor V1.2 width=40% +@note The resolution supported is 10 bit. + +@warning There a line drawn on the analog sensor, this represent the operating zone to get the humidity from the soil and +the circuit zone of the device (This limits could affect the sensor and its functionality). + +@image html Analog_moisture_sensor_001.jpeg Fig. 1.2 Representation of limits to use the moisture sensor. width=20% */ \ No newline at end of file diff --git a/firmware/sys/at_client/doc.txt b/firmware/sys/at_client/doc.txt index ef8f9d951..223958c01 100644 --- a/firmware/sys/at_client/doc.txt +++ b/firmware/sys/at_client/doc.txt @@ -4,7 +4,7 @@ ### At client -You have at command handler, which can be send with the shell, the following list has the command options: +You have AT commands handler, which can be send with the shell, the following list has the command options: ### Shell commands diff --git a/firmware/sys/uniqueid/Kconfig b/firmware/sys/uniqueid/Kconfig index 851eaf964..7949edc59 100644 --- a/firmware/sys/uniqueid/Kconfig +++ b/firmware/sys/uniqueid/Kconfig @@ -33,10 +33,5 @@ menu "Subnet" default "1111:2222" depends on MODE_MANUAL - config SEED_XTIMER - bool "Using xtimer to seed" - default y - depends on MODE_RANDOM - endmenu # Prefix endmenu diff --git a/firmware/sys/uniqueid/Makefile.dep b/firmware/sys/uniqueid/Makefile.dep index f4f2ec4ca..3cdf49152 100644 --- a/firmware/sys/uniqueid/Makefile.dep +++ b/firmware/sys/uniqueid/Makefile.dep @@ -1,3 +1,11 @@ USEMODULE += random -USEMODULE += xtimer USEMODULE += ipv6_addr +USEMODULE += netdev_default +USEMODULE += gnrc_ipv6_default +USEMODULE += auto_init_gnrc_netif + +ifneq (,$(filter m4a-24g m4a-mb,$(BOARD))) + USEMODULE += radio +else + USEMODULE += periph_hwrng +endif diff --git a/firmware/sys/uniqueid/doc.txt b/firmware/sys/uniqueid/doc.txt index 40065f41d..f9ee03be5 100644 --- a/firmware/sys/uniqueid/doc.txt +++ b/firmware/sys/uniqueid/doc.txt @@ -3,20 +3,15 @@ @ingroup sys ### Unique Id -You have 3 options to get the unique ipv6 address, which can be edited in the config menu: -1) Static: It is make with the cpu id and it is the same between reboots, -unique for each device. -2) Random: A random address that is generated with the same fixed header -as the first option. -3) Custom: This option allows you to edit both the header and the default -address is "1111:2222". - -Note: The default header is "2001:db8". +In this module you get a specific Id for each device and you have three options to get an unique IPV6 address, +which can be edited in the config menu: +1) Static: It is made with the cpu id and it is the same between reboots and unique for each device. +2) Random: A random address that is generated with the same fixed header. This option has a seed +cryptographically secure using NETOPT_RANDOM. +3) Custom: This option allows you to edit both the header and the address. The default address is "1111:2222". -### TO DO: -Use of ``` _xtimer_now ``` as seed is not cryptographically secure. +Note: The default header is "2001:db8". -Use of ``` seed = 0``` as seed is not cryptographically secure. */ \ No newline at end of file diff --git a/firmware/sys/uniqueid/include/uniqueid.h b/firmware/sys/uniqueid/include/uniqueid.h index be833c9d0..545326a2d 100644 --- a/firmware/sys/uniqueid/include/uniqueid.h +++ b/firmware/sys/uniqueid/include/uniqueid.h @@ -32,6 +32,15 @@ #ifdef __cplusplus extern "C" { #endif +/** + * @brief Get the CPU unique ID of this platform + * This function gets base cpu address using cpuid_get + * + * @param id pointer to char array with CPUID_LEN size. + * + */ +#define CPUID(id) cpuid_get(id); + /** * @brief union to get 32 bit random number and convert to a byte array. */ diff --git a/firmware/sys/uniqueid/uniqueid.c b/firmware/sys/uniqueid/uniqueid.c index bd206830a..a1ed233e9 100644 --- a/firmware/sys/uniqueid/uniqueid.c +++ b/firmware/sys/uniqueid/uniqueid.c @@ -17,6 +17,7 @@ * @brief This function gets ipv6 address (mode: static (default), random, manual) * * @author RocioRojas + * @author eduazocar */ #include @@ -24,8 +25,13 @@ #include #include "uniqueid.h" #include "random.h" -#include "xtimer.h" - +#include "net/netdev/ieee802154.h" +#include "net/gnrc.h" +#if MODULE_AT86RF2XX || MODULE_AT86RF215 +#include "radio.h" +#else +#include "periph/hwrng.h" +#endif void subnet_to_ipv6(ipv6_addr_t *addr) { #ifdef CONFIG_MODE_STATIC @@ -44,19 +50,20 @@ void subnet_to_ipv6(ipv6_addr_t *addr) { ipv6_addr_t header = { .u8 = {0}, }; + union random_buff random_number; ipv6_addr_from_str(&header, CONFIG_HEADER_ADDRESS_ID); memcpy((char *)addr->u8, (char *)header.u8, 4); - union random_buff random_number; - #ifdef CONFIG_SEED_XTIMER - int seed = _xtimer_now(); // TO DO: This is not cryptographically secure (default) - #else - int seed = 0; // TO DO: this is an example, here put a seed cryptographically secure - #endif - random_init(seed); +#if (MODULE_AT86RF2XX || MODULE_AT86RF215) + int index = get_ieee802154_iface(); + netif_t *iface = netif_get_by_id(index); + netif_get_opt(iface, NETOPT_RANDOM, 0, &random_number, sizeof(random_number)); +#else + hwrng_init(); + hwrng_read(&random_number, sizeof(random_number)); +#endif + random_init(random_number.u32); random_number.u32 = random_uint32(); - (void)random_number.u32; strncat((char *)addr->u8, (char *)random_number.u8, 4); - #endif #ifdef CONFIG_MODE_MANUAL diff --git a/tests/udp_client/main.c b/tests/udp_client/main.c index d608c68a0..8bba4e7e2 100644 --- a/tests/udp_client/main.c +++ b/tests/udp_client/main.c @@ -46,21 +46,13 @@ static void setup(void) { void send_udp_message_to_ipv6(void) { char message[] = "hello world"; size_t len = strlen(message) + 1; - int err = udp_send(&port, "::1", (uint8_t *)message, &len); + int err = udp_send(port, "::1", (uint8_t *)message, &len); TEST_ASSERT_EQUAL_INT(0, err); } -void send_udp_message_to_ipv4(void) { - char message[] = "hello world"; - size_t len = strlen(message) + 1; - int err = udp_send(&port, "192.168.1.2", (uint8_t *)message, &len); - TEST_ASSERT_EQUAL_INT(1, err); -} - Test *tests_udp_client(void) { EMB_UNIT_TESTFIXTURES(fixtures){ new_TestFixture(send_udp_message_to_ipv6), - new_TestFixture(send_udp_message_to_ipv4), }; EMB_UNIT_TESTCALLER(tests_udp_client, NULL, NULL, fixtures); diff --git a/tests/udp_server/main.c b/tests/udp_server/main.c index b996f9cea..a501fdd45 100644 --- a/tests/udp_server/main.c +++ b/tests/udp_server/main.c @@ -49,7 +49,7 @@ static void start_udp(void) { void send_udp_message_to_ipv6(void) { char message[] = "hello world"; size_t len = strlen(message) + 1; - int err = udp_send(&port, "::1", (uint8_t *)message, &len); + int err = udp_send(port, "::1", (uint8_t *)message, &len); TEST_ASSERT_EQUAL_INT(0, err); } diff --git a/tests/uniqueid/Kconfig b/tests/uniqueid/Kconfig index 60192d352..7949edc59 100644 --- a/tests/uniqueid/Kconfig +++ b/tests/uniqueid/Kconfig @@ -1,4 +1,4 @@ -menu "uniqueid" +menu "Uniqueid" config SELECT_HEADER_IPV6 bool "Edit IPV6 Header" @@ -33,10 +33,5 @@ menu "Subnet" default "1111:2222" depends on MODE_MANUAL - config SEED_XTIMER - bool "Using xtimer to seed" - default y - depends on MODE_RANDOM - endmenu # Prefix endmenu diff --git a/tests/uniqueid/main.c b/tests/uniqueid/main.c index 10e2ffb0a..fa900744c 100644 --- a/tests/uniqueid/main.c +++ b/tests/uniqueid/main.c @@ -15,17 +15,21 @@ */ /** - * @brief storage file + * @brief uniqueid file * - * @author xkevin190 + * @author xkevin190 + * @author RocioRojas + * @author eduazocar */ +#include #include #include #include "embUnit.h" #include "uniqueid.h" +#include "unique_random.h" -void get_unique_since_mac(ipv6_addr_t *output) { +void get_unique_from_mac(ipv6_addr_t *output) { ipv6_addr_t header = { .u8 = {0}, }; @@ -34,22 +38,42 @@ void get_unique_since_mac(ipv6_addr_t *output) { ipv6_addr_from_str(&header, CONFIG_HEADER_ADDRESS_ID); memcpy((char *)output->u8, (char *)header.u8, 4); strncat((char *)output->u8, addr_cpu, 4); + ipv6_addr_print(output); } void test_get_ipv6Address(void) { ipv6_addr_t ipv6 = { .u8 = {0}, }; - subnet_to_ipv6(&ipv6); + subnet_to_ipv6(&ipv6); #ifdef CONFIG_MODE_STATIC ipv6_addr_t output = { .u8 = {0}, }; ipv6_addr_print(&ipv6); - get_unique_since_mac(&output); + get_unique_from_mac(&output); TEST_ASSERT_EQUAL_INT(1, ipv6_addr_equal(&ipv6, &output)); #endif + +#ifdef CONFIG_MODE_RANDOM + ipv6_addr_t output1 = { + .u8 = {0}, + }; + ipv6_addr_t output2 = { + .u8 = {0}, + }; + + subnet_to_ipv6(&output1); + subnet_to_ipv6(&output2); + printf("\nFirst random IPv6\n"); + ipv6_addr_print(&output1); + printf("\nSecond random IPv6\n"); + ipv6_addr_print(&output2); + TEST_ASSERT_EQUAL_INT(0, ipv6_addr_equal(&output1, &output2)); + printf("\n\nBinary data printed\n"); + random_generator(64); +#endif } Test *tests_get_unique_id(void) { diff --git a/tests/uniqueid/random_gen.c b/tests/uniqueid/random_gen.c new file mode 100644 index 000000000..0280a142a --- /dev/null +++ b/tests/uniqueid/random_gen.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 Mesh4all + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author eduazocar + */ +#include +#include +#include + +#include "embUnit.h" +#include "uniqueid.h" +#include "random.h" +#include "unique_random.h" + +#if (MODULE_AT86RF2XX || MODULE_AT86RF215) +#include "radio.h" +#endif +#define BIT_ON_MASK (0x01) + +void random_generator(uint8_t bit_ref) { + +#if (MODULE_AT86RF2XX || MODULE_AT86RF215) + int index = get_ieee802154_iface(); + netif_t *iface = netif_get_by_id(index); +#endif + uint8_t avg_bit32 = bit_ref / 32; + if (bit_ref % 32 != 0) { + avg_bit32++; + } + uint32_t random_byte_block = 0; + for (uint8_t i = 0; i < bit_ref; i++) { + printf("ref %u", (uint8_t)(i + 1)); + for (uint8_t j = 0; j < avg_bit32; j++) { +#if (MODULE_AT86RF2XX || MODULE_AT86RF215) + netif_get_opt(iface, NETOPT_RANDOM, 0, &random_byte_block, sizeof(uint32_t)); +#endif + random_init(random_byte_block); + random_byte_block = random_uint32(); + printf(" Block: %d\t%" PRIx32 " \t", j, random_byte_block); + print_binary(random_byte_block, bit_ref / avg_bit32); + printf("\t"); + } + printf("\n"); + } +} + +void print_binary(uint32_t val, uint8_t len) { + for (int16_t i = len - 1; i >= 0; i--) { + printf("%u", (uint8_t)((val >> i) & BIT_ON_MASK)); + } +} diff --git a/tests/uniqueid/unique_random.h b/tests/uniqueid/unique_random.h new file mode 100644 index 000000000..ef556db2d --- /dev/null +++ b/tests/uniqueid/unique_random.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 Mesh4all + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Randomizer to obtain values hex in binary + * + * @author eduazocar + */ +#ifndef UNIQUE_RANDOM_H +#define UNIQUE_RANDOM_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Random Generator to gets a block of random values + * + * @param bit_ref this is a reference to create a matrix of the reads + * e.g bit_ref = 9 -> 9x9 (This mean that could obtain 9 measures of 9 + * random bits generated ) + */ +void random_generator(uint8_t bit_ref); + +/** + * @brief Printer to random values + * + * @param val Any input value in the range of 32 bits + * @param len length of the bits int @p val + */ +void print_binary(uint32_t val, uint8_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* UNIQUE_RANDOM_H */ +/** @} */