From 378c40b4da456d487fb92d9ed0e82ad8222d48e9 Mon Sep 17 00:00:00 2001 From: Bander Ajba Date: Sun, 26 Feb 2017 11:14:17 +0300 Subject: [PATCH] did required modification to merge the temperature sensore module --- nrf5/boards/nrf51822_ac_s110.ld | 2 +- nrf5/boards/pca10000/mpconfigboard.h | 1 + nrf5/boards/pca10000/nrf51_hal_conf.h | 1 + nrf5/boards/pca10001/mpconfigboard.h | 4 +- nrf5/boards/pca10001/nrf51_hal_conf.h | 5 +++ nrf5/boards/pca10028/mpconfigboard.h | 2 +- nrf5/boards/pca10031/mpconfigboard.h | 1 + nrf5/boards/pca10031/nrf51_hal_conf.h | 1 + nrf5/boards/pca10040/mpconfigboard.h | 1 + nrf5/boards/pca10040/nrf52_hal_conf.h | 1 + nrf5/boards/pca10056/mpconfigboard.h | 1 + nrf5/boards/pca10056/nrf52_hal_conf.h | 1 + nrf5/hal/hal_temp.c | 40 +++++++++++--------- nrf5/hal/hal_temp.h | 54 ++++++++++++--------------- nrf5/modules/machine/temp.c | 41 +++----------------- nrf5/modules/machine/temp.h | 11 +----- 16 files changed, 69 insertions(+), 98 deletions(-) diff --git a/nrf5/boards/nrf51822_ac_s110.ld b/nrf5/boards/nrf51822_ac_s110.ld index 90d76ec57e..5df19da487 100644 --- a/nrf5/boards/nrf51822_ac_s110.ld +++ b/nrf5/boards/nrf51822_ac_s110.ld @@ -9,7 +9,7 @@ MEMORY FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x040000 /* entire flash, 256 KiB */ FLASH_ISR (rx) : ORIGIN = 0x00018000, LENGTH = 0x000400 /* sector 0, 1 KiB */ FLASH_TEXT (rx) : ORIGIN = 0x00018400, LENGTH = 0x027c00 /* 159 KiB */ - RAM (xrw) : ORIGIN = 0x20001800, LENGTH = 0x002800 /* 12 KiB */ + RAM (xrw) : ORIGIN = 0x20002000, LENGTH = 0x006000 /* 12 KiB */ } /* produce a link error if there is not this amount of RAM for these sections */ diff --git a/nrf5/boards/pca10000/mpconfigboard.h b/nrf5/boards/pca10000/mpconfigboard.h index ac955eb61b..9646ced77c 100644 --- a/nrf5/boards/pca10000/mpconfigboard.h +++ b/nrf5/boards/pca10000/mpconfigboard.h @@ -32,6 +32,7 @@ #define MICROPY_PY_MACHINE_HW_SPI (0) #define MICROPY_PY_MACHINE_PWM (0) +#define MICROPY_PY_MACHINE_TEMP (1) #define MICROPY_HW_HAS_SWITCH (0) #define MICROPY_HW_HAS_FLASH (0) diff --git a/nrf5/boards/pca10000/nrf51_hal_conf.h b/nrf5/boards/pca10000/nrf51_hal_conf.h index 1848c81034..c1ac8268ea 100644 --- a/nrf5/boards/pca10000/nrf51_hal_conf.h +++ b/nrf5/boards/pca10000/nrf51_hal_conf.h @@ -3,5 +3,6 @@ #define HAL_UART_MODULE_ENABLED #define HAL_TIME_MODULE_ENABLED +#define HAL_TEMP_MODULE_ENABLED #endif // NRF51_HAL_CONF_H__ diff --git a/nrf5/boards/pca10001/mpconfigboard.h b/nrf5/boards/pca10001/mpconfigboard.h index 8380dcf76d..985eb31a29 100644 --- a/nrf5/boards/pca10001/mpconfigboard.h +++ b/nrf5/boards/pca10001/mpconfigboard.h @@ -32,6 +32,7 @@ #define MICROPY_PY_MACHINE_HW_SPI (0) #define MICROPY_PY_MACHINE_PWM (0) +#define MICROPY_PY_MACHINE_TEMP (1) #define MICROPY_HW_HAS_SWITCH (0) #define MICROPY_HW_HAS_FLASH (0) @@ -46,6 +47,7 @@ #define MICROPY_HW_ENABLE_DAC (0) #define MICROPY_HW_ENABLE_CAN (0) + #define MICROPY_HW_LED_COUNT (2) #define MICROPY_HW_LED_PULLUP (0) @@ -57,6 +59,6 @@ #define MICROPY_HW_UART1_TX (pin_A9) #define MICROPY_HW_UART1_CTS (pin_A10) #define MICROPY_HW_UART1_RTS (pin_A8) -#define MICROPY_HW_UART1_HWFC (1) +#define MICROPY_HW_UART1_HWFC (0) #define HELP_TEXT_BOARD_LED "1,2" diff --git a/nrf5/boards/pca10001/nrf51_hal_conf.h b/nrf5/boards/pca10001/nrf51_hal_conf.h index 8ea72b4107..f5a1c6adb8 100644 --- a/nrf5/boards/pca10001/nrf51_hal_conf.h +++ b/nrf5/boards/pca10001/nrf51_hal_conf.h @@ -4,5 +4,10 @@ #define HAL_UART_MODULE_ENABLED // #define HAL_SPI_MODULE_ENABLED #define HAL_TIME_MODULE_ENABLED +#define HAL_RTC_MODULE_ENABLED +#define HAL_TIMER_MODULE_ENABLED +#define HAL_TWI_MODULE_ENABLED +#define HAL_ADC_MODULE_ENABLED +#define HAL_TEMP_MODULE_ENABLED #endif // NRF51_HAL_CONF_H__ diff --git a/nrf5/boards/pca10028/mpconfigboard.h b/nrf5/boards/pca10028/mpconfigboard.h index 814351168f..e69de00951 100644 --- a/nrf5/boards/pca10028/mpconfigboard.h +++ b/nrf5/boards/pca10028/mpconfigboard.h @@ -73,7 +73,7 @@ #define MICROPY_HW_UART1_TX (pin_A9) #define MICROPY_HW_UART1_CTS (pin_A10) #define MICROPY_HW_UART1_RTS (pin_A8) -#define MICROPY_HW_UART1_HWFC (0) +#define MICROPY_HW_UART1_HWFC (1) // SPI0 config #define MICROPY_HW_SPI0_NAME "SPI0" diff --git a/nrf5/boards/pca10031/mpconfigboard.h b/nrf5/boards/pca10031/mpconfigboard.h index e28112c69b..43c0693f7f 100644 --- a/nrf5/boards/pca10031/mpconfigboard.h +++ b/nrf5/boards/pca10031/mpconfigboard.h @@ -31,6 +31,7 @@ #define MICROPY_PY_SYS_PLATFORM "nrf51-dongle" #define MICROPY_PY_MACHINE_PWM (0) +#define MICROPY_PY_MACHINE_TEMP (1) #define MICROPY_HW_HAS_SWITCH (0) #define MICROPY_HW_HAS_FLASH (0) diff --git a/nrf5/boards/pca10031/nrf51_hal_conf.h b/nrf5/boards/pca10031/nrf51_hal_conf.h index 67cbc983ba..ecc150fe9e 100644 --- a/nrf5/boards/pca10031/nrf51_hal_conf.h +++ b/nrf5/boards/pca10031/nrf51_hal_conf.h @@ -4,5 +4,6 @@ #define HAL_UART_MODULE_ENABLED #define HAL_SPI_MODULE_ENABLED #define HAL_TIME_MODULE_ENABLED +#define HAL_TEMP_MODULE_ENABLED #endif // NRF51_HAL_CONF_H__ diff --git a/nrf5/boards/pca10040/mpconfigboard.h b/nrf5/boards/pca10040/mpconfigboard.h index fcb62a5fe6..12f0cb5d35 100644 --- a/nrf5/boards/pca10040/mpconfigboard.h +++ b/nrf5/boards/pca10040/mpconfigboard.h @@ -36,6 +36,7 @@ #define MICROPY_PY_MACHINE_RTC (1) #define MICROPY_PY_MACHINE_I2C (1) #define MICROPY_PY_MACHINE_ADC (1) +#define MICROPY_PY_MACHINE_TEMP (1) #define MICROPY_PY_DISPLAY (1) #define MICROPY_PY_DISPLAY_EPAPER_SLD00200P (1) diff --git a/nrf5/boards/pca10040/nrf52_hal_conf.h b/nrf5/boards/pca10040/nrf52_hal_conf.h index 7ae58853c4..585506b8d6 100644 --- a/nrf5/boards/pca10040/nrf52_hal_conf.h +++ b/nrf5/boards/pca10040/nrf52_hal_conf.h @@ -9,6 +9,7 @@ #define HAL_TIMER_MODULE_ENABLED #define HAL_TWI_MODULE_ENABLED #define HAL_ADCE_MODULE_ENABLED +#define HAL_TEMP_MODULE_ENABLED // #define HAL_UARTE_MODULE_ENABLED // #define HAL_SPIE_MODULE_ENABLED // #define HAL_TWIE_MODULE_ENABLED diff --git a/nrf5/boards/pca10056/mpconfigboard.h b/nrf5/boards/pca10056/mpconfigboard.h index 308c9a1c9f..a4673057f5 100644 --- a/nrf5/boards/pca10056/mpconfigboard.h +++ b/nrf5/boards/pca10056/mpconfigboard.h @@ -34,6 +34,7 @@ #define MICROPY_PY_MACHINE_HW_SPI (1) #define MICROPY_PY_MACHINE_I2C (1) #define MICROPY_PY_MACHINE_ADC (1) +#define MICROPY_PY_MACHINE_TEMP (1) #define MICROPY_PY_DISPLAY (1) #define MICROPY_PY_DISPLAY_EPAPER_SLD00200P (1) diff --git a/nrf5/boards/pca10056/nrf52_hal_conf.h b/nrf5/boards/pca10056/nrf52_hal_conf.h index 7ae58853c4..585506b8d6 100644 --- a/nrf5/boards/pca10056/nrf52_hal_conf.h +++ b/nrf5/boards/pca10056/nrf52_hal_conf.h @@ -9,6 +9,7 @@ #define HAL_TIMER_MODULE_ENABLED #define HAL_TWI_MODULE_ENABLED #define HAL_ADCE_MODULE_ENABLED +#define HAL_TEMP_MODULE_ENABLED // #define HAL_UARTE_MODULE_ENABLED // #define HAL_SPIE_MODULE_ENABLED // #define HAL_TWIE_MODULE_ENABLED diff --git a/nrf5/hal/hal_temp.c b/nrf5/hal/hal_temp.c index c885fdc66f..7d6015e1af 100644 --- a/nrf5/hal/hal_temp.c +++ b/nrf5/hal/hal_temp.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2017 Bander F. Ajba * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,28 +30,32 @@ #ifdef HAL_TEMP_MODULE_ENABLED -/** - * @brief Function for preparing the temp module for temperature measurement. - * - * This function initializes the TEMP module and writes to the hidden configuration register. - */ void hal_temp_init(void) { - /**@note Workaround for PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module */ + // @note Workaround for PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module *(uint32_t *) 0x4000C504 = 0; } -/** - * @brief Function for reading temperature measurement. - * - * The function reads the 10 bit 2's complement value and transforms it to a 32 bit 2's complement value. - */ int32_t hal_temp_read(void) -{ +{ + int32_t volatile temp; hal_temp_init(); - /**@note Workaround for PAN_028 rev2.0A anomaly 28 - TEMP: Negative measured values are not represented correctly */ - return ((NRF_TEMP->TEMP & MASK_SIGN) != 0) ? (NRF_TEMP->TEMP | MASK_SIGN_EXTENSION) : (NRF_TEMP->TEMP); -} -/**@endcond */ -#endif // HAL_ADC_MODULE_ENABLED + NRF_TEMP->TASKS_START = 1; // Start the temperature measurement. + + while (NRF_TEMP->EVENTS_DATARDY == 0) + { + // Do nothing. + } + + NRF_TEMP->EVENTS_DATARDY = 0; + + // @note Workaround for PAN_028 rev2.0A anomaly 29 - TEMP: Stop task clears the TEMP register. + temp = (((NRF_TEMP->TEMP & MASK_SIGN) != 0) ? (NRF_TEMP->TEMP | MASK_SIGN_EXTENSION) : (NRF_TEMP->TEMP) / 4); + + // @note Workaround for PAN_028 rev2.0A anomaly 30 - TEMP: Temp module analog front end does not power down when DATARDY event occurs. + NRF_TEMP->TASKS_STOP = 1; // Stop the temperature measurement. + return temp; +} + +#endif // HAL_TEMP_MODULE_ENABLED diff --git a/nrf5/hal/hal_temp.h b/nrf5/hal/hal_temp.h index fbab6ebc4d..4ae5d15b05 100644 --- a/nrf5/hal/hal_temp.h +++ b/nrf5/hal/hal_temp.h @@ -1,47 +1,39 @@ -/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. +/* + * This file is part of the Micro Python project, http://micropython.org/ * - * The information contained herein is property of Nordic Semiconductor ASA. - * Terms and conditions of usage are described in detail in NORDIC - * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * The MIT License (MIT) * - * Licensees are granted free, non-transferable use of the information. NO - * WARRANTY of ANY KIND is provided. This heading must NOT be removed from - * the file. + * Copyright (c) 2017 Bander F. Ajba * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ -#ifndef NRF_TEMP_H__ -#define NRF_TEMP_H__ +#ifndef HAL_TEMP_H__ +#define HAL_TEMP_H__ #include "nrf.h" -/** -* @defgroup nrf_temperature TEMP (temperature) abstraction -* @{ -* @ingroup nrf_drivers temperature_example -* @brief Temperature module init and read functions. -* -*/ - -/**@cond NO_DOXYGEN */ #define MASK_SIGN (0x00000200UL) #define MASK_SIGN_EXTENSION (0xFFFFFC00UL) -/** - * @brief Function for preparing the temp module for temperature measurement. - * - * This function initializes the TEMP module and writes to the hidden configuration register. - */ void hal_temp_init(void); -/** - * @brief Function for reading temperature measurement. - * - * The function reads the 10 bit 2's complement value and transforms it to a 32 bit 2's complement value. - */ int32_t hal_temp_read(void); -/**@endcond */ - -/** @} */ #endif \ No newline at end of file diff --git a/nrf5/modules/machine/temp.c b/nrf5/modules/machine/temp.c index 02ae73b894..1f5687f6ab 100644 --- a/nrf5/modules/machine/temp.c +++ b/nrf5/modules/machine/temp.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2017 Bander F. Ajba * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -35,22 +35,12 @@ #if MICROPY_PY_MACHINE_TEMP -typedef struct _machine_temp_obj_t { - mp_obj_base_t base; - TEMP_HandleTypeDef *temp; -} machine_temp_obj_t; - -TEMP_HandleTypeDef TEMPHandle0 = {.instance = NULL }; - - -STATIC const machine_temp_obj_t machine_temp_obj = { - {&machine_temp_type}, &TEMPHandle0 -}; +typedef mp_obj_type_t machine_temp_type_t; /// \method __str__() /// Return a string describing the ADC object. STATIC void machine_temp_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { - machine_temp_obj_t *self = o; + machine_temp_type_t *self = o; (void)self; @@ -69,10 +59,7 @@ STATIC mp_obj_t machine_temp_make_new(const mp_obj_type_t *type, size_t n_args, mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - memset(&TEMPHandle0, 0, sizeof(TEMP_HandleTypeDef)); - TEMPHandle0.instance = TEMP_BASE; - - const machine_temp_obj_t *self = &machine_temp_obj; + const machine_temp_type_t *self = (machine_temp_type_t*) NRF_TEMP_BASE; return MP_OBJ_FROM_PTR(self); } @@ -80,25 +67,7 @@ STATIC mp_obj_t machine_temp_make_new(const mp_obj_type_t *type, size_t n_args, /// \method read() /// Get temperature. mp_obj_t machine_temp_read(void) { - int32_t volatile temp; - - NRF_TEMP->TASKS_START = 1; /** Start the temperature measurement. */ - - /* Busy wait while temperature measurement is not finished, you can skip waiting if you enable interrupt for DATARDY event and read the result in the interrupt. */ - /*lint -e{845} // A zero has been given as right argument to operator '|'" */ - while (NRF_TEMP->EVENTS_DATARDY == 0) - { - // Do nothing. - } - NRF_TEMP->EVENTS_DATARDY = 0; - - /**@note Workaround for PAN_028 rev2.0A anomaly 29 - TEMP: Stop task clears the TEMP register. */ - temp = (hal_temp_read() / 4); - - /**@note Workaround for PAN_028 rev2.0A anomaly 30 - TEMP: Temp module analog front end does not power down when DATARDY event occurs. */ - NRF_TEMP->TASKS_STOP = 1; /** Stop the temperature measurement. */ - - return MP_OBJ_NEW_SMALL_INT(temp); + return MP_OBJ_NEW_SMALL_INT(hal_temp_read()); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_machine_temp_read_obj, machine_temp_read); diff --git a/nrf5/modules/machine/temp.h b/nrf5/modules/machine/temp.h index 4d84d5e892..588d93107d 100644 --- a/nrf5/modules/machine/temp.h +++ b/nrf5/modules/machine/temp.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2017 Bander F. Ajba * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,17 +27,8 @@ #ifndef TEMP_H__ #define TEMP_H__ -#include "hal_temp.h" - extern const mp_obj_type_t machine_temp_type; -#define TEMP_BASE (NRF_TEMP_Type *)NRF_TEMP - -typedef struct __TEMP_HandleTypeDef -{ - NRF_TEMP_Type *instance; /* RTC registers base address */ -} TEMP_HandleTypeDef; - int32_t temp_read(void); #endif // TEMP_H__