MYNEWT-741 Lora cleanup * Combine lora_misc.c and timer.c --> utilities.c * Use existing swap_buf() instead of new memcpyr(). * Add Apache header to utilities.c
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/1eb96f4d Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1eb96f4d Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1eb96f4d Branch: refs/heads/bluetooth5 Commit: 1eb96f4dc3d034bfd6584238713ce15a471a77f0 Parents: 3fe2ef7 Author: Christopher Collins <ccoll...@apache.org> Authored: Thu Apr 27 15:43:37 2017 -0700 Committer: Christopher Collins <ccoll...@apache.org> Committed: Fri Apr 28 17:27:52 2017 -0700 ---------------------------------------------------------------------- net/lora/node/include/node/mac/LoRaMac.h | 2 +- net/lora/node/include/node/timer.h | 38 --------------- net/lora/node/include/node/utilities.h | 25 ++++++---- net/lora/node/src/mac/LoRaMac.c | 6 +-- net/lora/node/src/misc.c | 45 ------------------ net/lora/node/src/timer.c | 15 ------ net/lora/node/src/utilities.c | 67 +++++++++++++++++++++++++++ 7 files changed, 87 insertions(+), 111 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1eb96f4d/net/lora/node/include/node/mac/LoRaMac.h ---------------------------------------------------------------------- diff --git a/net/lora/node/include/node/mac/LoRaMac.h b/net/lora/node/include/node/mac/LoRaMac.h index 4613f8d..5619387 100644 --- a/net/lora/node/include/node/mac/LoRaMac.h +++ b/net/lora/node/include/node/mac/LoRaMac.h @@ -48,7 +48,7 @@ // Includes board dependent definitions such as channels frequencies #include "LoRaMac-definitions.h" -#include "node/timer.h" +#include "node/utilities.h" /*! http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1eb96f4d/net/lora/node/include/node/timer.h ---------------------------------------------------------------------- diff --git a/net/lora/node/include/node/timer.h b/net/lora/node/include/node/timer.h deleted file mode 100644 index 424dc32..0000000 --- a/net/lora/node/include/node/timer.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - / _____) _ | | -((____ _____ ____ _| |_ _____ ____| |__ - \____ \| ___ | (_ _) ___ |/ ___) _ \ - _____)) ____| | | || |_| ____((___| | | | -(______/|_____)_|_|_| \__)_____)\____)_| |_| - (C)2013 Semtech - -Description: Timer objects and scheduling management - -License: Revised BSD License, see LICENSE.TXT file include in the project - -Maintainer: Miguel Luis and Gregory Cristian -*/ -#ifndef __TIMER_H__ -#define __TIMER_H__ - -#include <inttypes.h> -#include <stdbool.h> -struct hal_timer; - -/*! - * \brief Return the Time elapsed since a fix moment in Time - * - * \param [IN] savedTime fix moment in Time - * \retval time returns elapsed time - */ -uint32_t TimerGetElapsedTime(uint32_t savedTime); - -/*! - * \brief Return the Time elapsed since a fix moment in Time - * - * \param [IN] eventInFuture fix moment in the future - * \retval time returns difference between now and future event - */ -uint32_t TimerGetFutureTime(uint32_t eventInFuture); - -#endif // __TIMER_H__ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1eb96f4d/net/lora/node/include/node/utilities.h ---------------------------------------------------------------------- diff --git a/net/lora/node/include/node/utilities.h b/net/lora/node/include/node/utilities.h index 8816351..44ab629 100644 --- a/net/lora/node/include/node/utilities.h +++ b/net/lora/node/include/node/utilities.h @@ -53,15 +53,6 @@ Maintainer: Miguel Luis and Gregory Cristian int32_t randr( int32_t min, int32_t max ); /*! - * \brief Copies size elements of src array to dst array reversing the byte order - * - * \param [OUT] dst Destination array - * \param [IN] src Source array - * \param [IN] size Number of bytes to be copied - */ -void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size ); - -/*! * \brief Converts a nibble to an hexadecimal character * * \param [IN] a Nibble to be converted @@ -69,4 +60,20 @@ void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size ); */ int8_t Nibble2HexChar( uint8_t a ); +/*! + * \brief Return the Time elapsed since a fix moment in Time + * + * \param [IN] savedTime fix moment in Time + * \retval time returns elapsed time + */ +uint32_t TimerGetElapsedTime( uint32_t savedTime ); + +/*! + * \brief Return the Time elapsed since a fix moment in Time + * + * \param [IN] eventInFuture fix moment in the future + * \retval time returns difference between now and future event + */ +uint32_t TimerGetFutureTime( uint32_t eventInFuture ); + #endif // __UTILITIES_H__ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1eb96f4d/net/lora/node/src/mac/LoRaMac.c ---------------------------------------------------------------------- diff --git a/net/lora/node/src/mac/LoRaMac.c b/net/lora/node/src/mac/LoRaMac.c index 473e56e..cb8f942 100644 --- a/net/lora/node/src/mac/LoRaMac.c +++ b/net/lora/node/src/mac/LoRaMac.c @@ -28,8 +28,8 @@ Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jä #include "node/mac/LoRaMac.h" #include "node/mac/LoRaMacTest.h" +#include "os/os.h" #include "hal/hal_timer.h" -#include "os/os_cputime.h" #include "lora_priv.h" @@ -3120,9 +3120,9 @@ LoRaMacStatus_t PrepareFrame( LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl LoRaMacBufferPktLen = pktHeaderLen; - memcpyr( LoRaMacBuffer + LoRaMacBufferPktLen, LoRaMacAppEui, 8 ); + swap_buf( LoRaMacBuffer + LoRaMacBufferPktLen, LoRaMacAppEui, 8 ); LoRaMacBufferPktLen += 8; - memcpyr( LoRaMacBuffer + LoRaMacBufferPktLen, LoRaMacDevEui, 8 ); + swap_buf( LoRaMacBuffer + LoRaMacBufferPktLen, LoRaMacDevEui, 8 ); LoRaMacBufferPktLen += 8; LoRaMacDevNonce = Radio.Random( ); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1eb96f4d/net/lora/node/src/misc.c ---------------------------------------------------------------------- diff --git a/net/lora/node/src/misc.c b/net/lora/node/src/misc.c deleted file mode 100644 index 3d4576a..0000000 --- a/net/lora/node/src/misc.c +++ /dev/null @@ -1,45 +0,0 @@ -#include <stdlib.h> - -#include "syscfg/syscfg.h" -#include "node/utilities.h" -#include "lora_priv.h" - -int32_t -randr(int32_t min, int32_t max) -{ - return rand() % (max - min + 1) + min; -} - -void -memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size ) -{ - dst = dst + ( size - 1 ); - while( size-- ) - { - *dst-- = *src++; - } -} - -double -ceil(double d) -{ - int64_t i; - - i = d; - if (d == i) { - return i; - } - return i + 1; -} - -double -floor(double d) -{ - return (int64_t)d; -} - -double -round(double d) -{ - return (int64_t)(d + 0.5); -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1eb96f4d/net/lora/node/src/timer.c ---------------------------------------------------------------------- diff --git a/net/lora/node/src/timer.c b/net/lora/node/src/timer.c deleted file mode 100644 index d445b01..0000000 --- a/net/lora/node/src/timer.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "os/os.h" -#include "node/timer.h" -#include "node/utilities.h" - -uint32_t -TimerGetElapsedTime(uint32_t savedTime) -{ - return savedTime - os_cputime_get32(); -} - -uint32_t -TimerGetFutureTime(uint32_t eventInFuture) -{ - return os_cputime_get32() + eventInFuture; -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1eb96f4d/net/lora/node/src/utilities.c ---------------------------------------------------------------------- diff --git a/net/lora/node/src/utilities.c b/net/lora/node/src/utilities.c new file mode 100644 index 0000000..2122a86 --- /dev/null +++ b/net/lora/node/src/utilities.c @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +#include <stdlib.h> + +#include "syscfg/syscfg.h" +#include "os/os.h" +#include "node/utilities.h" +#include "lora_priv.h" + +int32_t +randr(int32_t min, int32_t max) +{ + return rand() % (max - min + 1) + min; +} + +double +ceil(double d) +{ + int64_t i; + + i = d; + if (d == i) { + return i; + } + return i + 1; +} + +double +floor(double d) +{ + return (int64_t)d; +} + +double +round(double d) +{ + return (int64_t)(d + 0.5); +} + +uint32_t +TimerGetElapsedTime(uint32_t savedTime) +{ + return savedTime - os_cputime_get32(); +} + +uint32_t +TimerGetFutureTime(uint32_t eventInFuture) +{ + return os_cputime_get32() + eventInFuture; +}