http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/antfs.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/antfs.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/antfs.h deleted file mode 100644 index 1b3140f..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/antfs.h +++ /dev/null @@ -1,358 +0,0 @@ -/* -This software is subject to the license described in the license.txt file included with this software distribution. -You may not use this file except in compliance with this license. -Copyright � Dynastream Innovations Inc. 2012 -All rights reserved. -*/ - -/**@file - * @brief The ANT-FS client protocol interface. - * This file is based on implementation originally made by Dynastream Innovations Inc. - August 2012 - * @defgroup ant_fs_client_main ANT-FS client device simulator - * @{ - * @ingroup ant_sdk_utils - * - * @brief The ANT-FS client device simulator. - * - * @note The ANT-FS Network Key is available for ANT+ Adopters. Please refer to http://thisisant.com to become an ANT+ Adopter and access the key. - */ - -#ifndef ANTFS_H__ -#define ANTFS_H__ - -#include <stdint.h> -#include <stdbool.h> -#include "defines.h" -#include "antfs_config.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define ANTFS_VERSION_MAJOR 1u /**< Version major number. */ -#define ANTFS_VERSION_MINOR 0 /**< Version minor number. */ -#define ANTFS_VERSION_ITERATION 0 /**< Version iteration. */ -#define ANTFS_VERSION_TYPE 'R' /**< Version type is release. */ -#define ANTFS_VERSION_SPEC '0.AK' /**< Version of the ANT-FS Technology Specification. */ -#define ANTFS_DIR_STRUCT_VERSION 1u /**< Version of the directory file structure. */ -#define ANTFS_VERSION_DATE 20090522u /**< Version date. */ - -// ANT-FS options. -#define ANTFS_NETWORK_NUMBER 0 /**< ANT-FS Network Number. */ -#define ANTFS_CHANNEL 0 /**< ANT Channel Number. */ -#define ANTFS_LINK_FREQ 50u /**< RF Frequency (+2400MHz). */ -#define ANTFS_PAIRING_TIMEOUT 120u /**< Pairing timeout (time the UI will wait for a response to the pairing request before switching to the link layer, in seconds). */ -#define ANTFS_LINK_COMMAND_TIMEOUT 10u /**< Command timeout (time the client will wait without receiving any commands before switching to the link layer, in seconds). */ -#define ANTFS_TRANS_TYPE 5u /**< ANT-FS Transmission Type. */ -#define ANTFS_CHANNEL_TYPE CHANNEL_TYPE_MASTER /**< ANT-FS Client Channel Type. */ -#define ANTFS_BEACON_PERIOD_STATUS BEACON_PERIOD_4_HZ /**< ANT-FS Beacon Message Period. */ -#define ANTFS_TRANSMIT_POWER 3u /**< ANT Transmit Power (0dBm). */ -#define ANTFS_CUSTOM_TRANSMIT_POWER 0u /**< ANT Custom Transmit Power (0dBm). */ -#define ANTFS_AUTH_STRING_MAX 255u /**< Maximum size of authentication strings (passkey/friendly name). */ -#define ANTFS_PASSKEY_SIZE 16u /**< Passkey size. */ -#define ANTFS_FRIENDLY_NAME_MAX 16u /**< Maximum size of friendly name received from host. */ -#define ANTFS_REMOTE_FRIENDLY_NAME_MAX 16u /**< Maximum size of client's friendly name. */ - -// Beacon definitions. -#define BEACON_PERIOD_SHIFT 0x00 /**< Shift value for masking out beacon period. */ -#define BEACON_PERIOD_MASK (0x07u << BEACON_PERIOD_SHIFT) /**< Beacon period bitmask. */ -#define BEACON_PERIOD_0_5_HZ (0x00 << BEACON_PERIOD_SHIFT) /**< Value for 0,5Hz beacon period. */ -#define BEACON_PERIOD_1_HZ (0x01u << BEACON_PERIOD_SHIFT) /**< Value for 1Hz beacon period. */ -#define BEACON_PERIOD_2_HZ (0x02u << BEACON_PERIOD_SHIFT) /**< Value for 2Hz beacon period. */ -#define BEACON_PERIOD_4_HZ (0x03u << BEACON_PERIOD_SHIFT) /**< Value for 4Hz beacon period. */ -#define BEACON_PERIOD_8_HZ (0x04u << BEACON_PERIOD_SHIFT) /**< Value for 8Hz beacon period. */ -#define PAIRING_AVAILABLE_FLAG_SHIFT 0x03u /**< Shift value for masking out pairing enabled bit. */ -#define PAIRING_AVAILABLE_FLAG_MASK (0x01u << PAIRING_AVAILABLE_FLAG_SHIFT) /**< Pairing enabled bitmask. */ -#define UPLOAD_ENABLED_FLAG_SHIFT 0x04u /**< Shift value for masking out upload enabled bit. */ -#define UPLOAD_ENABLED_FLAG_MASK (0x01u << UPLOAD_ENABLED_FLAG_SHIFT) /**< Upload enabled bitmask. */ -#define DATA_AVAILABLE_FLAG_SHIFT 0x05u /**< Shift value for masking out data available bit. */ -#define DATA_AVAILABLE_FLAG_MASK (0x01u << DATA_AVAILABLE_FLAG_SHIFT) /**< Data available bitmask. */ - -// Build the default beacon settings. -#if defined (ANTFS_AUTH_TYPE_PAIRING) - #define ANTFS_PAIRING_BIT PAIRING_AVAILABLE_FLAG_MASK /**< Build pairing enabled default beacon setting. */ -#else - #define ANTFS_PAIRING_BIT 0x00u /**< Build pairing disabled default beacon setting. */ -#endif // ANTFS_INCLUDE_PAIRING -#if defined (ANTFS_INCLUDE_UPLOAD) - #define ANTFS_UPLOAD_BIT UPLOAD_ENABLED_FLAG_MASK /**< Build upload enabled default beacon setting. */ -#else - #define ANTFS_UPLOAD_BIT 0x00u /**< Build upload disabled default beacon setting. */ -#endif // ANTFS_INCLUDE_UPLOAD - -#define ANTFS_DEFAULT_BEACON (ANTFS_BEACON_PERIOD_STATUS | ANTFS_UPLOAD_BIT | ANTFS_PAIRING_BIT | DATA_AVAILABLE_FLAG_MASK) /**< Define the default beacon setting. */ - -// Download/Upload responses. -#define RESPONSE_MESSAGE_OK 0x00u /**< Download request ok. */ -#define RESPONSE_MESSAGE_NOT_EXIST 0x01u /**< File does not exist. */ -#define RESPONSE_MESSAGE_NOT_AVAILABLE 0x02u /**< File can not be read/written to (download/upload respectively). */ -#define RESPONSE_INVALID_OPERATION 0x04u /**< Request invalid. */ -// Download responses. -#define RESPONSE_MESSAGE_NOT_READY 0x03u /**< Not ready to download. */ -#define RESPONSE_INVALID_CRC 0x05u /**< CRC incorrect. */ -// Upload responses. -#define RESPONSE_MESSAGE_NOT_ENOUGH_SPACE 0x03u /**< Not enough space to to complete write. */ -#define RESPONSE_MESSAGE_UPLOAD_NOT_READY 0x05u /**< Not ready to upload */ -// Upload/Erase responses. -#define RESPONSE_MESSAGE_FAIL 0x01u /**< Data File Index does not exist / Erase failed. */ - -// Directory general file flags. -#define ANTFS_DIR_READ_MASK 0x80u /**< Read (can download). */ -#define ANTFS_DIR_WRITE_MASK 0x40u /**< Write (can upload). */ -#define ANTFS_DIR_ERASE_MASK 0x20u /**< Erase (can erase). */ -#define ANTFS_DIR_ARCHIVE_MASK 0x10u /**< Archive (has been downloaded). */ -#define ANTFS_DIR_APPEND_MASK 0x08u /**< Append (can append to file only). */ - -#define ANTFS_MAX_FILE_SIZE 0xFFFFFFFFu /**< Maximum file size, as specified by directory structure. */ -#define ANTFS_BURST_BLOCK_SIZE 16u /**< Size of each block of burst data that the client attempts to send when it processes a data request event. */ - -/**@brief ANT-FS beacon status. */ -typedef union -{ - uint32_t status; /**< Beacon status byte 1. */ - - struct - { - uint32_t link_period : 3; /**< Beacon period (0.5 - 8 Hz). */ - bool is_pairing_enabled : 1; /**< Pairing is enabled/disabled. */ - bool is_upload_enabled : 1; /**< Upload is enabled/disabled. */ - bool is_data_available : 1; /**< Data is available for download / no data available. */ - bool reserved : 2; /**< Reserved. */ - } parameters; -} antfs_beacon_status_byte1_t; - -// ANT-FS states. -typedef enum -{ - ANTFS_STATE_OFF, /**< Off state. */ - ANTFS_STATE_INIT, /**< Init state. */ - ANTFS_STATE_LINK, /**< Link state. */ - ANTFS_STATE_AUTH, /**< Authenticate state. */ - ANTFS_STATE_TRANS /**< Transport state. */ -} antfs_state_t; - -// ANT-FS link layer substates. -typedef enum -{ - ANTFS_LINK_SUBSTATE_NONE /**< None state. */ -} antfs_link_substate_t; - -// ANT-FS authenticate layer substates. */ -typedef enum -{ - ANTFS_AUTH_SUBSTATE_NONE, /**< None state. */ - ANTFS_AUTH_SUBSTATE_PAIR, /**< Pairing state. */ - ANTFS_AUTH_SUBSTATE_PASSKEY, /**< Passkey state. */ - ANTFS_AUTH_SUBSTATE_ACCEPT, /**< Authenticate accept state. */ - ANTFS_AUTH_SUBSTATE_REJECT /**< Authenticate reject state. */ -} antfs_authenticate_substate_t; - -// ANT-FS transport layer substates. */ -typedef enum -{ - ANTFS_TRANS_SUBSTATE_NONE, /**< None state. */ - ANTFS_TRANS_SUBSTATE_VERIFY_CRC, /**< Verify CRC state. */ - ANTFS_TRANS_SUBSTATE_DOWNLOADING, /**< Downloading state. */ - ANTFS_TRANS_SUBSTATE_UPLOAD_WAIT_FOR_DATA, /**< Wait for upload data request state. */ - ANTFS_TRANS_SUBSTATE_UPLOADING, /**< Ready / receiving upload data state. */ - ANTFS_TRANS_SUBSTATE_UPLOAD_RESUME /**< RX failure upon receiving upload data state. */ -} antfs_transport_substate_t; - -// ANT-FS Events. -typedef enum -{ - ANTFS_EVENT_PAIRING_REQUEST = 0xB0, /**< Pairing request event. */ - ANTFS_EVENT_PAIRING_TIMEOUT = 0xB1, /**< Pairing timeout event. */ - ANTFS_EVENT_OPEN_COMPLETE = 0xB2, /**< Channel setup complete event. */ - ANTFS_EVENT_CLOSE_COMPLETE = 0xB4, /**< Channel closed event. */ - ANTFS_EVENT_LINK = 0xB6, /**< Enter link layer event. */ - ANTFS_EVENT_AUTH = 0xB7, /**< Enter authenticate layer event. */ - ANTFS_EVENT_TRANS = 0xB8, /**< Enter transport layer event. */ - ANTFS_EVENT_DOWNLOAD_REQUEST = 0xB9, /**< Download request event. */ - ANTFS_EVENT_DOWNLOAD_REQUEST_DATA = 0xBA, /**< Download request data event. */ - ANTFS_EVENT_DOWNLOAD_START = 0xBB, /**< Download started event. */ - ANTFS_EVENT_DOWNLOAD_COMPLETE = 0xBC, /**< Download completed event. */ - ANTFS_EVENT_DOWNLOAD_FAIL = 0xBD, /**< Download failed event. */ - ANTFS_EVENT_UPLOAD_REQUEST = 0xBE, /**< Upload request event. */ - ANTFS_EVENT_UPLOAD_DATA = 0xBF, /**< Upload data available for read event. */ - ANTFS_EVENT_UPLOAD_START = 0xC0, /**< Upload begin event. */ - ANTFS_EVENT_UPLOAD_COMPLETE = 0xC1, /**< Upload completed event. */ - ANTFS_EVENT_UPLOAD_FAIL = 0xC2, /**< Upload process failed event. */ - ANTFS_EVENT_ERASE_REQUEST = 0xC3 /**< Erase request event. */ -} antfs_event_t; - -/**@brief ANT-FS <-> application event communication object. */ -typedef struct -{ - antfs_event_t event; /**< ANT-FS event. */ - uint16_t file_index; /**< File index (download/upload/erase). */ - uint32_t offset; /**< Current offset (download/upload). */ - uint32_t bytes; /**< Number of bytes in block (download/upload). */ - uint16_t crc; /**< Current CRC (upload). */ - uint8_t data[8]; /**< Block of data (upload). */ -} antfs_event_return_t; - -/**@brief ANT-FS parameters. */ -typedef struct -{ - uint32_t client_serial_number; /**< Client serial number. */ - uint16_t beacon_device_type; /**< Client device type. */ - uint16_t beacon_device_manufacturing_id; /**< Client manufacturing ID. */ - uint8_t beacon_frequency; /**< Beacon RF Frequency. */ - antfs_beacon_status_byte1_t beacon_status_byte1; /**< Beacon status byte 1. */ - const uint8_t * p_pass_key; /**< Pass Key. */ - const uint8_t * p_remote_friendly_name; /**< Friendly Name. */ -} antfs_params_t; - -/**@brief ANT-FS directory header. */ -typedef struct -{ - uint8_t version; /**< Version of the directory file structure. */ - uint8_t length; /**< Length of each structure, in bytes. */ - uint8_t time_format; /**< Defines how system keeps track of date/time stamps. */ - uint8_t reserved01; - uint8_t reserved02; - uint8_t reserved03; - uint8_t reserved04; - uint8_t reserved05; - uint32_t system_time; /**< Number of seconds elapsed since system power up. */ - uint32_t date; /**< Number of seconds elapsed since 00:00 hrs Dec 31, 1989. If system time is unknown, used as counter. */ -} antfs_dir_header_t; - -/**@brief ANT-FS directory entry. */ -typedef struct -{ - uint16_t data_file_index; /**< Data file index. */ - uint8_t file_data_type; /**< File data type. */ - uint8_t user_defined1; /**< Identifier, first byte (structure defined by data type). */ - uint16_t user_defined2; /**< Identifier, last two bytes (structure defined by data type). */ - uint8_t user_flags; /**< File data type specific flags (bits defined by data type). */ - uint8_t general_flags; /**< Bit mapped flags of flag permissions. */ - uint32_t file_size_in_bytes; /**< File size, in bytes. */ - uint32_t date; /**< Number of seconds elapsed since 00:00 hrs Dec 31, 1980, if supported. */ -} antfs_dir_struct_t; - -/**@brief ANT-FS download/upload request context. */ -typedef struct -{ - ulong_union_t file_size; /**< Size of a file to download when reading, or the size of a partially completed upload when writing. */ - uint32_t max_file_size; /**< The maximum size of the file specified, this is the file size when reading, and the maximum allowed file size when writing. */ - ulong_union_t max_burst_block_size; /**< Maximum burst block size. */ - ushort_union_t file_index; /**< File index. */ - uint16_t file_crc; /**< CRC (uploads). */ -} antfs_request_info_t; - -/**@brief The burst wait handler can be configured by the application to customize the code that is - * executed while waiting for the burst busy flag. */ -typedef void(*antfs_burst_wait_handler_t)(void); - -/**@brief Function for setting initial ANT-FS configuration parameters. - * - * @param[in] p_params The initial ANT-FS configuration parameters. - * @param[in] burst_wait_handler Burst wait handler. - */ -void antfs_init(const antfs_params_t * const p_params, - antfs_burst_wait_handler_t burst_wait_handler); - -/**@brief Function for getting host name if received. - * - * @return Pointer to host name buffer if a host name was recieved, NULL otherwise. - */ -const char * antfs_hostname_get(void); - -/**@brief Function for transmitting a response to a pairing request issued by ANT-FS host. - * - * @param[in] accept The pairing response, true if pairing accepted. - * - * @retval true Operation success. Response to a pairing request was transmitted. - * @retval false Operation failure. Not in pairing mode or pairing not supported by the - * implementation. - */ -bool antfs_pairing_resp_transmit(bool accept); - -/**@brief Function for doing calculations prior downloading the data to the ANT-FS host. - * - * Function does the necessary pre processing calculations, which are required prior downloading the - * data, and also transmits the download request response right away in case of the download request - * was rejected or there is no data to send. - * - * @param[in] response The download request response code. - * @param[in] p_request_info ANT-FS request info structure. - */ -void antfs_download_req_resp_prepare(uint8_t response, - const antfs_request_info_t * const p_request_info); - -/**@brief Function for downloading requested data. - * - * @param[in] index Index of the current file downloaded. - * @param[in] offset Offset specified by client. - * @param[in] num_bytes Number of bytes requested to be transmitted from the buffer. - * @param[in] p_message Data buffer to be transmitted. - * - * @return Number of data bytes transmitted. - */ -uint32_t antfs_input_data_download(uint16_t index, - uint32_t offset, - uint32_t num_bytes, - const uint8_t * const p_message); - -/**@brief Function for transmitting upload request response to a upload request command by ANT-FS - * host. - * - * @param[in] response The upload response code. - * @param[in] p_request_info ANT-FS request info structure. - * - * @retval true Operation success. Response to upload request command was transmitted. - * @retval false Operation failure. Upload not supported by the implementation or not in correct - * state or application is sending a response for a different file - * than requested. - */ -bool antfs_upload_req_resp_transmit(uint8_t response, - const antfs_request_info_t * const p_request_info); - -/**@brief Function for transmitting upload data response to a upload data command by ANT-FS host. - * - * @param[in] data_upload_success The upload response code, true for success. - * - * @retval true Operation success. Response to upload data command was transmitted. - * @retval false Operation failure. Upload not supported by the implementation or not in correct - * state. - */ -bool antfs_upload_data_resp_transmit(bool data_upload_success); - -/**@brief Function for transmitting erase response to a erase request. - * - * @param[in] response The erase response code. - */ -void antfs_erase_req_resp_transmit(uint8_t response); - -/**@brief Function for extracting possible pending ANT-FS event. - * - * @param[out] p_event The output event structure. - * - * @retval true Operation success. Pending ANT-FS event available and it was copied to the output - * event structure. - * @retval false Operation failure. No pending ANT-FS event available. - */ -bool antfs_event_extract(antfs_event_return_t * const p_event); - -/**@brief Function for processing ANT events and data received from the ANT-FS channel. - * - * @param[in] p_message The message buffer containing the message received from the ANT-FS - * channel. - */ -void antfs_message_process(uint8_t * p_message); - -/**@brief Function for setting up the ANT-FS channel. - */ -void antfs_channel_setup(void); - -#ifdef __cplusplus -} -#endif - -#endif // ANTFS_H__ - -/** - *@} - **/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/crc.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/crc.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/crc.c deleted file mode 100644 index 9a1aa75..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/crc.c +++ /dev/null @@ -1,55 +0,0 @@ -/* -This software is subject to the license described in the license.txt file included with this software distribution. -You may not use this file except in compliance with this license. -Copyright � Dynastream Innovations Inc. 2012 -All rights reserved. -*/ - -#include "crc.h" -#include "compiler_abstraction.h" - - -/**@brief Function for updating the current CRC-16 value for a single byte input. - * - * @param[in] current_crc The current calculated CRC-16 value. - * @param[in] byte The input data byte for the computation. - * - * @return The updated CRC-16 value, based on the input supplied. - */ -static __INLINE uint16_t crc16_get(uint16_t current_crc, uint8_t byte) -{ - static const uint16_t crc16_table[16] = - { - 0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401, - 0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400 - }; - - uint16_t temp; - - // Compute checksum of lower four bits of a byte. - temp = crc16_table[current_crc & 0xF]; - current_crc = (current_crc >> 4u) & 0x0FFFu; - current_crc = current_crc ^ temp ^ crc16_table[byte & 0xF]; - - // Now compute checksum of upper four bits of a byte. - temp = crc16_table[current_crc & 0xF]; - current_crc = (current_crc >> 4u) & 0x0FFFu; - current_crc = current_crc ^ temp ^ crc16_table[(byte >> 4u) & 0xF]; - - return current_crc; -} - - -uint16_t crc_crc16_update(uint16_t current_crc, const volatile void * p_data, uint32_t size) -{ - uint8_t * p_block = (uint8_t *)p_data; - - while (size != 0) - { - current_crc = crc16_get(current_crc, *p_block); - p_block++; - size--; - } - - return current_crc; -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/crc.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/crc.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/crc.h deleted file mode 100644 index 59642e8..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/crc.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -This software is subject to the license described in the license.txt file included with this software distribution. -You may not use this file except in compliance with this license. -Copyright � Dynastream Innovations Inc. 2012 -All rights reserved. -*/ - -/** @file - * @brief The CRC-16 interface. - * This file is based on implementation originally made by Dynastream Innovations Inc. - August 2012 - * @defgroup ant_fs_client_main ANT-FS client device simulator - * @{ - * @ingroup nrf_ant_fs_client - * - * @brief The ANT-FS client device simulator. - * - */ - -#ifndef CRC_H__ -#define CRC_H__ - -#include <stdint.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/**@brief Function for calculating CRC-16 in blocks. - * - * Feed each consecutive data block into this function, along with the current value of current_crc - * as returned by the previous call of this function. The first call of this function should pass - * the initial value (usually 0) of the crc in current_crc. - - * @param[in] current_crc The current calculated CRC-16 value. - * @param[in] p_data The input data block for computation. - * @param[in] size The size of the input data block in bytes. - * - * @return The updated CRC-16 value, based on the input supplied. - */ -uint16_t crc_crc16_update(uint16_t current_crc, const volatile void * p_data, uint32_t size); - -#ifdef __cplusplus -} -#endif - -#endif // CRC_H__ - -/** - *@} - **/ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/defines.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/defines.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/defines.h deleted file mode 100644 index 2ddc8c1..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/defines.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -This software is subject to the license described in the license.txt file included with this software distribution. -You may not use this file except in compliance with this license. -Copyright � Dynastream Innovations Inc. 2012 -All rights reserved. -*/ - -/**@file - * @brief Definitions. - * This file is based on implementation originally made by Dynastream Innovations Inc. - August 2012 - * @defgroup ant_fs_client_main ANT-FS client device simulator - * @{ - * @ingroup nrf_ant_fs_client - * - * @brief The ANT-FS client device simulator. - * - */ - -#ifndef DEFINES_H__ -#define DEFINES_H__ - -#include <stdint.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#define MAX_ULONG 0xFFFFFFFFu /**< The Max value for the type. */ - -/**@brief uint16_t type presentation as an union. */ -typedef union -{ - uint16_t data; /**< The data content. */ - - struct - { - uint8_t low; /**< The low byte of the data content. */ - uint8_t high; /**< The high byte of the data content. */ - } bytes; -} ushort_union_t; - -/**@brief uint32_t type presentation as an union. */ -typedef union -{ - uint32_t data; /**< The data content as a single variable. */ - uint8_t data_bytes[sizeof(uint32_t)]; /**< The data content as a byte array. */ - - struct - { - // The least significant byte of the uint32_t in this structure is referenced by byte0. - uint8_t byte0; /**< Byte 0 of the data content. */ - uint8_t byte1; /**< Byte 1 of the data content. */ - uint8_t byte2; /**< Byte 2 of the data content. */ - uint8_t byte3; /**< Byte 3 of the data content. */ - } bytes; -} ulong_union_t; - -#define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */ - -#ifdef __cplusplus -} -#endif - -#endif // DEFINES_H__ - -/** - *@} - **/ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ecc/ecc.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ecc/ecc.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ecc/ecc.c deleted file mode 100644 index 5542dc9..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ecc/ecc.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2016 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is confidential property of Nordic Semiconductor. The use, - * copying, transfer or disclosure of such information is prohibited except by express written - * agreement with Nordic Semiconductor. - * - */ - -/** - * @brief Elliptic Curve Cryptography Interface - * - */ - -#include <stdint.h> -#include <stdio.h> -#include <string.h> -#include "nordic_common.h" -#include "app_timer.h" -#include "app_trace.h" -#include "app_uart.h" -#include "app_util.h" -#include "nrf_log.h" -#include "nrf_drv_rng.h" -#include "ecc.h" - -#include "uECC.h" - - -static int ecc_rng(uint8_t *dest, unsigned size) -{ - uint32_t errcode; - - errcode = nrf_drv_rng_block_rand(dest, (uint32_t) size); - - return errcode == NRF_SUCCESS ? 1 : 0; -} - -void ecc_init(void) -{ - uECC_set_rng(ecc_rng); -} - -ret_code_t ecc_p256_keypair_gen(uint8_t *p_le_sk, uint8_t *p_le_pk) -{ - const struct uECC_Curve_t * p_curve; - - if(!p_le_sk || !p_le_pk) - { - return NRF_ERROR_NULL; - } - - if(!is_word_aligned(p_le_sk) || !is_word_aligned(p_le_pk)) - { - return NRF_ERROR_INVALID_ADDR; - } - - p_curve = uECC_secp256r1(); - - int ret = uECC_make_key((uint8_t *) p_le_pk, (uint8_t *) p_le_sk, p_curve); - if(!ret) - { - return NRF_ERROR_INTERNAL; - } - - return NRF_SUCCESS; -} - -ret_code_t ecc_p256_public_key_compute(uint8_t const *p_le_sk, uint8_t *p_le_pk) -{ - const struct uECC_Curve_t * p_curve; - - if(!p_le_sk || !p_le_pk) - { - return NRF_ERROR_NULL; - } - - if(!is_word_aligned(p_le_sk) || !is_word_aligned(p_le_pk)) - { - return NRF_ERROR_INVALID_ADDR; - } - - p_curve = uECC_secp256r1(); - - NRF_LOG_PRINTF("uECC_compute_public_key\n"); - int ret = uECC_compute_public_key((uint8_t *) p_le_sk, (uint8_t *) p_le_pk, p_curve); - if(!ret) - { - return NRF_ERROR_INTERNAL; - } - - NRF_LOG_PRINTF("uECC_compute_public_key complete: %d\n", ret); - return NRF_SUCCESS; -} - -ret_code_t ecc_p256_shared_secret_compute(uint8_t const *p_le_sk, uint8_t const *p_le_pk, uint8_t *p_le_ss) -{ - const struct uECC_Curve_t * p_curve; - - if(!p_le_sk || !p_le_pk || !p_le_ss) - { - return NRF_ERROR_NULL; - } - - if(!is_word_aligned(p_le_sk) || !is_word_aligned(p_le_pk) || !is_word_aligned(p_le_ss)) - { - return NRF_ERROR_INVALID_ADDR; - } - - p_curve = uECC_secp256r1(); - - NRF_LOG_PRINTF("uECC_shared_secret\n"); - int ret = uECC_shared_secret((uint8_t *) p_le_pk, (uint8_t *) p_le_sk, p_le_ss, p_curve); - if(!ret) - { - return NRF_ERROR_INTERNAL; - } - - NRF_LOG_PRINTF("uECC_shared_secret complete: %d\n", ret); - return NRF_SUCCESS; -} - - http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ecc/ecc.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ecc/ecc.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ecc/ecc.h deleted file mode 100644 index ebbb4d6..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ecc/ecc.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2016 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is confidential property of Nordic Semiconductor. The use, - * copying, transfer or disclosure of such information is prohibited except by express written - * agreement with Nordic Semiconductor. - * - */ - -/** - * @brief Elliptic Curve Cryptography Interface - * - */ - -#include <stdint.h> -#include "nordic_common.h" -#include "nrf_error.h" - -#define ECC_P256_SK_LEN 32 -#define ECC_P256_PK_LEN 64 - -/**@brief Initialize the ECC module. */ -void ecc_init(void); - -/**@brief Create a public/private key pair. - * - * @param[out] p_le_sk Private key. Pointer must be aligned to a 4-byte boundary. - * @param[out] p_le_pk Public key. Pointer must be aligned to a 4-byte boundary. - * - * @retval NRF_SUCCESS Key pair successfuly created. - * @retval NRF_ERROR_NULL NULL pointer provided. - * @retval NRF_ERROR_INVALID_ADDR Unaligned pointer provided. - * @retval NRF_ERROR_INTERNAL Internal error during key generation. - */ -ret_code_t ecc_p256_keypair_gen(uint8_t *p_le_sk, uint8_t* p_le_pk); - -/**@brief Create a public key from a provided private key. - * - * @param[in] p_le_sk Private key. Pointer must be aligned to a 4-byte boundary. - * @param[out] p_le_pk Public key. Pointer must be aligned to a 4-byte boundary. - * - * @retval NRF_SUCCESS Public key successfuly created. - * @retval NRF_ERROR_NULL NULL pointer provided. - * @retval NRF_ERROR_INVALID_ADDR Unaligned pointer provided. - * @retval NRF_ERROR_INTERNAL Internal error during key generation. - */ -ret_code_t ecc_p256_public_key_compute(uint8_t const *p_le_sk, uint8_t* p_le_pk); - -/**@brief Create a shared secret from a provided public/private key pair. - * - * @param[in] p_le_sk Private key. Pointer must be aligned to a 4-byte boundary. - * @param[in] p_le_pk Public key. Pointer must be aligned to a 4-byte boundary. - * @param[out] p_le_ss Shared secret. Pointer must be aligned to a 4-byte boundary. - * - * @retval NRF_SUCCESS Shared secret successfuly created. - * @retval NRF_ERROR_NULL NULL pointer provided. - * @retval NRF_ERROR_INVALID_ADDR Unaligned pointer provided. - * @retval NRF_ERROR_INTERNAL Internal error during key generation. - */ -ret_code_t ecc_p256_shared_secret_compute(uint8_t const *p_le_sk, uint8_t const * p_le_pk, uint8_t *p_le_ss); - http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/timer/app_timer_rtx.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/timer/app_timer_rtx.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/timer/app_timer_rtx.c deleted file mode 100644 index 8186870..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/timer/app_timer_rtx.c +++ /dev/null @@ -1,239 +0,0 @@ -#include "app_timer.h" -#include <stdlib.h> -#include "nrf.h" -#include "nrf_soc.h" -#include "app_error.h" -#include "app_util.h" -#include "cmsis_os.h" -#include "app_util_platform.h" - -#define RTC1_IRQ_PRI APP_IRQ_PRIORITY_LOW /**< Priority of the RTC1 interrupt. */ - -#define MAX_RTC_COUNTER_VAL 0x00FFFFFF /**< Maximum value of the RTC counter. */ - -/**@brief This structure keeps information about osTimer.*/ -typedef struct -{ - osTimerDef_t timerDef; - uint32_t buffer[5]; - osTimerId id; -}app_timer_info_t; - -/**@brief Store an array of timers with configuration. */ -typedef struct -{ - uint8_t max_timers; /**< The maximum number of timers*/ - uint32_t prescaler; - app_timer_info_t * app_timers; /**< Pointer to table of timers*/ -}app_timer_control_t; -app_timer_control_t app_timer_control; - -/**@brief This structure is defined by RTX. It keeps information about created osTimers. It is used in app_timer_start(). */ -typedef struct os_timer_cb_ -{ - struct os_timer_cb_ * next; - uint8_t state; - uint8_t type; - uint16_t reserved; - uint16_t tcnt; - uint16_t icnt; - void * arg; - const osTimerDef_t * timer; -} os_timer_cb; - -/**@brief This functions are defined by RTX.*/ -//lint --save -e10 -e19 -e526 -extern osStatus svcTimerStop(osTimerId timer_id); /**< Used in app_timer_stop(). */ -extern osStatus svcTimerStart(osTimerId timer_id, uint32_t millisec); /**< Used in app_timer_start(). */ -// lint --restore -static void * rt_id2obj(void *id) /**< Used in app_timer_start(). This function gives information if osTimerID is valid */ -{ - - if ((uint32_t)id & 3) - return NULL; - -#ifdef OS_SECTIONS_LINK_INFO - - if ((os_section_id$$Base != 0) && (os_section_id$$Limit != 0)) - { - if (id < (void *)os_section_id$$Base) - return NULL; - - if (id >= (void *)os_section_id$$Limit) - return NULL; - } -#endif - - return id; -} - - -uint32_t app_timer_init(uint32_t prescaler, - uint8_t op_queues_size, - void * p_buffer, - app_timer_evt_schedule_func_t evt_schedule_func) -{ - if (p_buffer == NULL) - { - return NRF_ERROR_INVALID_PARAM; - } - - app_timer_control.prescaler = prescaler; - app_timer_control.app_timers = p_buffer; - NVIC_SetPriority(RTC1_IRQn, RTC1_IRQ_PRI); - - return NRF_SUCCESS; -} - - -uint32_t app_timer_create(app_timer_id_t const * p_timer_id, - app_timer_mode_t mode, - app_timer_timeout_handler_t timeout_handler) -{ - - if ((timeout_handler == NULL) || (p_timer_id == NULL)) - { - return NRF_ERROR_INVALID_PARAM; - } - - app_timer_info_t * p_timer_info = (app_timer_info_t *)*p_timer_id; - p_timer_info->timerDef.timer = p_timer_info->buffer; - p_timer_info->timerDef.ptimer = (os_ptimer)timeout_handler; - - p_timer_info->id = osTimerCreate(&(p_timer_info->timerDef), (os_timer_type)mode, NULL); - - if (p_timer_info->id) - return NRF_SUCCESS; - else - { - return NRF_ERROR_INVALID_PARAM; // This error is unspecified by rtx - } -} - -#define osTimerRunning 2 -uint32_t app_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void * p_context) -{ - if ((timeout_ticks < APP_TIMER_MIN_TIMEOUT_TICKS)) - { - return NRF_ERROR_INVALID_PARAM; - } - uint32_t timeout_ms = - ((uint32_t)ROUNDED_DIV(timeout_ticks * 1000 * (app_timer_control.prescaler + 1), - (uint32_t)APP_TIMER_CLOCK_FREQ)); - - app_timer_info_t * p_timer_info = (app_timer_info_t *)timer_id; - if (rt_id2obj((void *)p_timer_info->id) == NULL) - return NRF_ERROR_INVALID_PARAM; - - // Pass p_context to timer_timeout_handler - ((os_timer_cb *)(p_timer_info->id))->arg = p_context; - - if (((os_timer_cb *)(p_timer_info->id))->state == osTimerRunning) - { - return NRF_SUCCESS; - } - // osTimerStart() returns osErrorISR if it is called in interrupt routine. - switch (osTimerStart((osTimerId)p_timer_info->id, timeout_ms) ) - { - case osOK: - return NRF_SUCCESS; - - case osErrorISR: - break; - - case osErrorParameter: - return NRF_ERROR_INVALID_PARAM; - - default: - return NRF_ERROR_INVALID_PARAM; - } - - // Start timer without svcCall - switch (svcTimerStart((osTimerId)p_timer_info->id, timeout_ms)) - { - case osOK: - return NRF_SUCCESS; - - case osErrorISR: - return NRF_ERROR_INVALID_STATE; - - case osErrorParameter: - return NRF_ERROR_INVALID_PARAM; - - default: - return NRF_ERROR_INVALID_PARAM; - } -} - -uint32_t app_timer_stop(app_timer_id_t timer_id) -{ - app_timer_info_t * p_timer_info = (app_timer_info_t *)timer_id; - switch (osTimerStop((osTimerId)p_timer_info->id) ) - { - case osOK: - return NRF_SUCCESS; - - case osErrorISR: - break; - - case osErrorParameter: - return NRF_ERROR_INVALID_PARAM; - - case osErrorResource: - return NRF_SUCCESS; - - default: - return NRF_ERROR_INVALID_PARAM; - } - - // Stop timer without svcCall - switch (svcTimerStop((osTimerId)p_timer_info->id)) - { - case osOK: - return NRF_SUCCESS; - - case osErrorISR: - return NRF_ERROR_INVALID_STATE; - - case osErrorParameter: - return NRF_ERROR_INVALID_PARAM; - - case osErrorResource: - return NRF_SUCCESS; - - default: - return NRF_ERROR_INVALID_PARAM; - } -} - - -uint32_t app_timer_stop_all(void) -{ - for (int i = 0; i < app_timer_control.max_timers; i++) - { - if (app_timer_control.app_timers[i].id) - { - (void)app_timer_stop((app_timer_id_t)app_timer_control.app_timers[i].id); - } - } - return 0; -} - - -extern uint32_t os_tick_val(void); -uint32_t app_timer_cnt_get(uint32_t * p_ticks) -{ - *p_ticks = os_tick_val(); - return NRF_SUCCESS; -} - - -uint32_t app_timer_cnt_diff_compute(uint32_t ticks_to, - uint32_t ticks_from, - uint32_t * p_ticks_diff) -{ - *p_ticks_diff = ((ticks_to - ticks_from) & MAX_RTC_COUNTER_VAL); - return NRF_SUCCESS; -} - - http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/trace/app_trace.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/trace/app_trace.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/trace/app_trace.h deleted file mode 100644 index 144b15e..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/trace/app_trace.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef __DEBUG_H_ -#define __DEBUG_H_ - -#include <stdint.h> -#include <stdio.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup app_trace Debug Logger - * @ingroup app_common - * @{ - * @brief Enables debug logs/ trace over UART. - * @details Enables debug logs/ trace over UART. Tracing is enabled only if - * ENABLE_DEBUG_LOG_SUPPORT is defined in the project. - */ -#ifdef ENABLE_DEBUG_LOG_SUPPORT -#include "nrf_log.h" -/** - * @brief Module Initialization. - * - * @details Initializes the module to use UART as trace output. - * - * @warning This function will configure UART using default board configuration. - * Do not call this function if UART is configured from a higher level in the application. - */ -void app_trace_init(void); - -/** - * @brief Log debug messages. - * - * @details This API logs messages over UART. The module must be initialized before using this API. - * - * @note Though this is currently a macro, it should be used used and treated as function. - */ -#define app_trace_log NRF_LOG_PRINTF - -/** - * @brief Dump auxiliary byte buffer to the debug trace. - * - * @details This API logs messages over UART. The module must be initialized before using this API. - * - * @param[in] p_buffer Buffer to be dumped on the debug trace. - * @param[in] len Size of the buffer. - */ -void app_trace_dump(uint8_t * p_buffer, uint32_t len); - -#else // ENABLE_DEBUG_LOG_SUPPORT - -#define app_trace_init(...) -#define app_trace_log(...) -#define app_trace_dump(...) - -#endif // ENABLE_DEBUG_LOG_SUPPORT - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif //__DEBUG_H_ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_assert.h ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_assert.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_assert.h deleted file mode 100644 index 08758fd..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_assert.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2006 Nordic Semiconductor. All Rights Reserved. - * - * The information contained herein is confidential property of Nordic Semiconductor. The use, - * copying, transfer or disclosure of such information is prohibited except by express written - * agreement with Nordic Semiconductor. - * - */ - -/** @file - * @brief Utilities for verifying program logic - */ - -#ifndef NRF_ASSERT_H_ -#define NRF_ASSERT_H_ - -#include <stdint.h> -#include "nrf.h" -#include "app_error.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER) - -/** @brief Function for handling assertions. - * - * - * @note - * This function is called when an assertion has triggered. - * - * - * @post - * All hardware is put into an idle non-emitting state (in particular the radio is highly - * important to switch off since the radio might be in a state that makes it send - * packets continiously while a typical final infinit ASSERT loop is executing). - * - * - * @param line_num The line number where the assertion is called - * @param file_name Pointer to the file name - */ -void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name); - -/*lint -emacro(506, ASSERT) */ /* Suppress "Constant value Boolean */ -/*lint -emacro(774, ASSERT) */ /* Suppress "Boolean within 'if' always evaluates to True" */ \ - -/** @brief Function for checking intended for production code. - * - * Check passes if "expr" evaluates to true. */ -#define ASSERT(expr) \ -if (expr) \ -{ \ -} \ -else \ -{ \ - assert_nrf_callback((uint16_t)__LINE__, (uint8_t *)__FILE__); \ -} -#else -#define ASSERT(expr) //!< Assert empty when disabled -__WEAK void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name); -#endif /* defined(DEBUG_NRF) || defined(DEBUG_NRF_USER) */ - -#ifdef __cplusplus -} -#endif - -#endif /* NRF_ASSERT_H_ */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_log.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_log.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_log.c deleted file mode 100644 index 480d7b5..0000000 --- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_log.c +++ /dev/null @@ -1,425 +0,0 @@ -#include "nrf.h" -#include "nrf_log.h" -#include "nrf_error.h" -#include <stdarg.h> -#include <string.h> -#include <stdio.h> - -#if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1 - -#include <SEGGER_RTT_Conf.h> -#include <SEGGER_RTT.h> - -static char buf_normal_up[BUFFER_SIZE_UP]; -static char buf_down[BUFFER_SIZE_DOWN]; - -uint32_t log_rtt_init(void) -{ - static bool initialized = false; - if (initialized) - { - return NRF_SUCCESS; - } - - if (SEGGER_RTT_ConfigUpBuffer(LOG_TERMINAL_NORMAL, - "Normal", - buf_normal_up, - BUFFER_SIZE_UP, - SEGGER_RTT_MODE_NO_BLOCK_TRIM - ) - != 0) - { - return NRF_ERROR_INVALID_STATE; - } - - if (SEGGER_RTT_ConfigDownBuffer(LOG_TERMINAL_INPUT, - "Input", - buf_down, - BUFFER_SIZE_DOWN, - SEGGER_RTT_MODE_NO_BLOCK_SKIP - ) - != 0) - { - return NRF_ERROR_INVALID_STATE; - } - - initialized = true; - - return NRF_SUCCESS; -} - -// Forward declaration of SEGGER RTT vprintf function -int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList); - -void log_rtt_printf(int terminal_index, char * format_msg, ...) -{ - //lint -save -e526 -e628 -e530 - va_list p_args; - va_start(p_args, format_msg); - (void)SEGGER_RTT_vprintf(terminal_index, format_msg, &p_args); - va_end(p_args); - //lint -restore -} - -__INLINE void log_rtt_write_string(int terminal_index, int num_args, ...) -{ - const char* msg; - //lint -save -e516 -e530 - va_list p_args; - va_start(p_args, num_args); - //lint -restore - - for (int i = 0; i < num_args; i++) - { - //lint -save -e26 -e10 -e64 -e526 -e628 -e530 - msg = va_arg(p_args, const char*); - //lint -restore - (void)SEGGER_RTT_WriteString(terminal_index, msg); - } - va_end(p_args); -} - -void log_rtt_write_hex(int terminal_index, uint32_t value) -{ - char temp[11]; - temp[0] = '0'; - temp[1] = 'x'; - temp[10] = 0; // Null termination - uint8_t nibble; - uint8_t i = 8; - - while(i-- != 0) - { - nibble = (value >> (4 * i)) & 0x0F; - temp[9-i] = (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble); - } - - (void)SEGGER_RTT_WriteString(terminal_index, temp); -} - -void log_rtt_write_hex_char(int terminal_index, uint8_t value) -{ - char temp[3]; - temp[2] = 0; // Null termination - uint8_t nibble; - uint8_t i = 2; - - while(i-- != 0) - { - nibble = (value >> (4 * i)) & 0x0F; - temp[1-i] = (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble); - } - - (void)SEGGER_RTT_WriteString(terminal_index, temp); -} - -__INLINE int log_rtt_has_input() -{ - return SEGGER_RTT_HasKey(); -} - -uint32_t log_rtt_read_input(char * c) -{ - int r; - - r = SEGGER_RTT_Read(LOG_TERMINAL_INPUT, c, 1); - if (r == 1) - return NRF_SUCCESS; - else - return NRF_ERROR_NULL; -} - -#elif defined(NRF_LOG_USES_UART) && NRF_LOG_USES_UART == 1 - -#include "app_uart.h" -#include "app_error.h" -#include <stdio.h> -#include <string.h> -#include "nrf.h" -#include "bsp.h" - -#define MAX_TEST_DATA_BYTES (15U) /**< max number of test bytes to be used for tx and rx. */ -#define UART_TX_BUF_SIZE 512 /**< UART TX buffer size. */ -#define UART_RX_BUF_SIZE 1 /**< UART RX buffer size. */ - -static uint8_t m_uart_data; -static bool m_uart_has_input; - -void uart_error_cb(app_uart_evt_t * p_event) -{ - if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR) - { - APP_ERROR_HANDLER(p_event->data.error_communication); - } - else if (p_event->evt_type == APP_UART_FIFO_ERROR) - { - APP_ERROR_HANDLER(p_event->data.error_code); - } -} - -uint32_t log_uart_init() -{ - static bool initialized = false; - if (initialized) - { - return NRF_SUCCESS; - } - - uint32_t err_code; - const app_uart_comm_params_t comm_params = - { - RX_PIN_NUMBER, - TX_PIN_NUMBER, - RTS_PIN_NUMBER, - CTS_PIN_NUMBER, - APP_UART_FLOW_CONTROL_ENABLED, - false, - UART_BAUDRATE_BAUDRATE_Baud115200 - }; - - APP_UART_FIFO_INIT(&comm_params, - UART_RX_BUF_SIZE, - UART_TX_BUF_SIZE, - uart_error_cb, - APP_IRQ_PRIORITY_LOW, - err_code); - - initialized = true; - - return err_code; -} - -//lint -save -e530 -e64 -void log_uart_printf(const char * format_msg, ...) -{ - va_list p_args; - va_start(p_args, format_msg); - (void)vprintf(format_msg, p_args); - va_end(p_args); -} - -__INLINE void log_uart_write_string_many(int num_args, ...) -{ - const char* msg; - va_list p_args; - va_start(p_args, num_args); - - for (int i = 0; i < num_args; i++) - { - msg = va_arg(p_args, const char*); - log_uart_write_string(msg); - } - va_end(p_args); -} - -__INLINE void log_uart_write_string(const char* msg) -{ - while( *msg ) - { - (void)app_uart_put(*msg++); - } -} -//lint -restore - -void log_uart_write_hex(uint32_t value) -{ - uint8_t nibble; - uint8_t i = 8; - - (void)app_uart_put('0'); - (void)app_uart_put('x'); - while( i-- != 0 ) - { - nibble = (value >> (4 * i)) & 0x0F; - (void)app_uart_put( (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble) ); - } -} - -void log_uart_write_hex_char(uint8_t c) -{ - uint8_t nibble; - uint8_t i = 2; - - while( i-- != 0 ) - { - nibble = (c >> (4 * i)) & 0x0F; - (void)app_uart_put( (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble) ); - } -} - -__INLINE int log_uart_has_input() -{ - if (m_uart_has_input) return 1; - if (app_uart_get(&m_uart_data) == NRF_SUCCESS) - { - m_uart_has_input = true; - return 1; - } - return 0; -} - -uint32_t log_uart_read_input(char * c) -{ - if (m_uart_has_input) - { - *c = (char)m_uart_data; - m_uart_has_input = false; - return NRF_SUCCESS; - } - if (app_uart_get((uint8_t *)c) == NRF_SUCCESS) - { - return NRF_SUCCESS; - } - return NRF_ERROR_NULL; -} - -#elif defined(NRF_LOG_USES_RAW_UART) && NRF_LOG_USES_RAW_UART == 1 - -#include "app_uart.h" -#include <stdio.h> -#include <string.h> -#include "bsp.h" - -uint32_t log_raw_uart_init() -{ - // Disable UART - NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Disabled; - - // Configure RX/TX pins - nrf_gpio_cfg_output( TX_PIN_NUMBER ); - nrf_gpio_cfg_input(RX_PIN_NUMBER, NRF_GPIO_PIN_NOPULL); - - // Set a default baud rate of UART0_CONFIG_BAUDRATE - NRF_UART0->PSELTXD = TX_PIN_NUMBER; - NRF_UART0->BAUDRATE = UART0_CONFIG_BAUDRATE; - - NRF_UART0->PSELRTS = 0xFFFFFFFF; - NRF_UART0->PSELCTS = 0xFFFFFFFF; - - // Disable parity and interrupt - NRF_UART0->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos ); - NRF_UART0->CONFIG |= (UART_CONFIG_HWFC_Disabled << UART_CONFIG_HWFC_Pos ); - - // Re-enable the UART - NRF_UART0->ENABLE = UART_ENABLE_ENABLE_Enabled; - NRF_UART0->INTENSET = 0; - NRF_UART0->TASKS_STARTTX = 1; - NRF_UART0->TASKS_STARTRX = 1; - - return NRF_SUCCESS; -} - -void log_raw_uart_printf(const char * format_msg, ...) -{ - static char buffer[256]; - - va_list p_args; - va_start(p_args, format_msg); - sprintf(buffer, format_msg, p_args); - va_end(p_args); - - log_raw_uart_write_string(buffer); -} - -__INLINE void log_raw_uart_write_char(const char c) -{ - NRF_UART0->TXD = c; - while( NRF_UART0->EVENTS_TXDRDY != 1 ); - NRF_UART0->EVENTS_TXDRDY = 0; -} - -__INLINE void log_raw_uart_write_string_many(int num_args, ...) -{ - - const char* msg; - va_list p_args; - va_start(p_args, num_args); - - for (int i = 0; i < num_args; i++) - { - msg = va_arg(p_args, const char*); - log_raw_uart_write_string(msg); - } - va_end(p_args); -} - -__INLINE void log_raw_uart_write_string(const char* msg) -{ - while( *msg ) - { - NRF_UART0->TXD = *msg++; - while( NRF_UART0->EVENTS_TXDRDY != 1 ); - NRF_UART0->EVENTS_TXDRDY = 0; - } -} - -void log_raw_uart_write_hex(uint32_t value) -{ - uint8_t nibble; - uint8_t i = 8; - - log_raw_uart_write_string( "0x" ); - while( i-- != 0 ) - { - nibble = (value >> (4 * i)) & 0x0F; - log_raw_uart_write_char( (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble) ); - } -} - -void log_raw_uart_write_hex_char(uint8_t c) -{ - uint8_t nibble; - uint8_t i = 2; - - while( i-- != 0 ) - { - nibble = (c >> (4 * i)) & 0x0F; - log_raw_uart_write_hex( (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble) ); - } -} - -__INLINE int log_raw_uart_has_input() -{ - return 0; -} - -uint32_t log_raw_uart_read_input(char * c) -{ - return NRF_ERROR_NULL; -} - -#endif // NRF_LOG_USES_RAW_UART == 1 - - -const char* log_hex_char(const char c) -{ - static volatile char hex_string[3]; - hex_string[2] = 0; // Null termination - uint8_t nibble; - uint8_t i = 2; - while(i-- != 0) - { - nibble = (c >> (4 * i)) & 0x0F; - hex_string[1-i] = (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble); - } - return (const char*) hex_string; -} - -const char* log_hex(uint32_t value) -{ - static volatile char hex_string[11]; - hex_string[0] = '0'; - hex_string[1] = 'x'; - hex_string[10] = 0; - uint8_t nibble; - uint8_t i = 8; - - while(i-- != 0) - { - nibble = (value >> (4 * i)) & 0x0F; - hex_string[9-i] = (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble); - } - - return (const char*)hex_string; -} -
