You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/11/22 05:31:56 UTC
[1/4] incubator-mynewt-core git commit: * debundle nordic ADC drivers,
as they rely on Nordic SDK, which is now bundled separately
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/1_0_0_b1_dev a1481cb22 -> 267d86b3a
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.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_log.h b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_log.h
deleted file mode 100644
index d74af7d..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/nrf_log.h
+++ /dev/null
@@ -1,707 +0,0 @@
-#ifndef NRF_LOG_H_
-#define NRF_LOG_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef DOXYGEN
-
-#include <stdint.h>
-#include <stdarg.h>
-#include <app_util.h>
-
-#ifndef NRF_LOG_USES_RTT
-#define NRF_LOG_USES_RTT 0
-#endif
-
-#ifndef NRF_LOG_USES_UART
-#define NRF_LOG_USES_UART 0
-#endif
-
-#ifndef NRF_LOG_USES_RAW_UART
-#define NRF_LOG_USES_RAW_UART 0
-#endif
-
-#ifndef NRF_LOG_USES_COLORS
- #define NRF_LOG_USES_COLORS 1
-#endif
-
-#if NRF_LOG_USES_COLORS == 1
- #define NRF_LOG_COLOR_DEFAULT "\x1B[0m"
- #define NRF_LOG_COLOR_BLACK "\x1B[1;30m"
- #define NRF_LOG_COLOR_RED "\x1B[1;31m"
- #define NRF_LOG_COLOR_GREEN "\x1B[1;32m"
- #define NRF_LOG_COLOR_YELLOW "\x1B[1;33m"
- #define NRF_LOG_COLOR_BLUE "\x1B[1;34m"
- #define NRF_LOG_COLOR_MAGENTA "\x1B[1;35m"
- #define NRF_LOG_COLOR_CYAN "\x1B[1;36m"
- #define NRF_LOG_COLOR_WHITE "\x1B[1;37m"
-#else
- #define NRF_LOG_COLOR_DEFAULT
- #define NRF_LOG_COLOR_BLACK
- #define NRF_LOG_COLOR_RED
- #define NRF_LOG_COLOR_GREEN
- #define NRF_LOG_COLOR_YELLOW
- #define NRF_LOG_COLOR_BLUE
- #define NRF_LOG_COLOR_MAGENTA
- #define NRF_LOG_COLOR_CYAN
- #define NRF_LOG_COLOR_WHITE
-#endif
-
-#if defined(NRF_LOG_USES_RTT) && NRF_LOG_USES_RTT == 1
-
-#define LOG_TERMINAL_NORMAL (0)
-#define LOG_TERMINAL_ERROR (1)
-#define LOG_TERMINAL_INPUT (0)
-
-/**@brief Function for initializing the SEGGER RTT logger.
- *
- * @details See <a href="https://www.segger.com/jlink-rtt.html" target="_blank">segger.com</a>
- * for information about SEGGER Real Time Transfer (RTT).
- *
- * This function is available only when NRF_LOG_USES_RTT is defined as 1.
- *
- * @note Do not call this function directly. Use the macro @ref NRF_LOG_INIT instead.
- *
- * @retval NRF_SUCCESS If initialization was successful.
- * @retval NRF_ERROR Otherwise.
- */
-uint32_t log_rtt_init(void);
-
-/**@brief Function for writing a printf string using RTT.
- *
- * @details The printf implementation in SEGGER's RTT is more efficient than
- * the standard implementation. However, printf requires more processor time
- * than other logging functions. Therefore, applications that require logging
- * but need it to interfere as little as possible with the execution, should
- * avoid using printf.
- *
- * This function is available only when NRF_LOG_USES_RTT is defined as 1.
- *
- * @note Do not call this function directly. Use one of the following macros instead:
- * - @ref NRF_LOG_PRINTF
- * - @ref NRF_LOG_PRINTF_DEBUG
- * - @ref NRF_LOG_PRINTF_ERROR
- *
- * @param terminal_index Segger RTT terminal index to use as output.
- * @param format_msg Printf format string.
- */
-void log_rtt_printf(int terminal_index, char * format_msg, ...);
-
-/**@brief Function for writing a string using RTT.
- *
- * @details The string to write must be null-terminated, but the null termination will not be stored
- * in the ring buffer.
- * The impact of running this function should be very low compared to writing to UART.
- *
- * This function is available only when NRF_LOG_USES_RTT is defined as 1.
- *
- * @note Do not call this function directly. Use one of the following macros instead:
- * - @ref NRF_LOG
- * - @ref NRF_LOG_DEBUG
- * - @ref NRF_LOG_ERROR
- *
- * @param terminal_index Segger RTT terminal index to use as output.
- * @param num_args Number of arguments.
- */
-void log_rtt_write_string(int terminal_index, int num_args, ...);
-
-/**@brief Function for writing an integer as HEX using RTT.
- *
- * The output data is formatted as, for example, 0x89ABCDEF.
- *
- * This function is available only when NRF_LOG_USES_RTT is defined as 1.
- *
- * @note Do not call this function directly. Use one of the following macros instead:
- * - @ref NRF_LOG_HEX
- * - @ref NRF_LOG_HEX_DEBUG
- * - @ref NRF_LOG_HEX_ERROR
- *
- * @param terminal_index Segger RTT terminal index to use as output.
- * @param value Integer value to be printed as HEX.
- */
-void log_rtt_write_hex(int terminal_index, uint32_t value);
-
-/**@brief Function for writing a single character as HEX using RTT.
- *
- * The output string is formatted as, for example, AA.
- *
- * This function is available only when NRF_LOG_USES_RTT is defined as 1.
- *
- * @note Do not call this function directly. Use one of the following macros instead:
- * - @ref NRF_LOG_HEX_CHAR
- * - @ref NRF_LOG_HEX_CHAR_DEBUG
- * - @ref NRF_LOG_HEX_CHAR_ERROR
- *
- * @param terminal_index Segger RTT terminal index to use as output.
- * @param value Character to print as HEX.
- */
-void log_rtt_write_hex_char(int terminal_index, uint8_t value);
-
-/**@brief Function for checking if data is available in the input buffer.
- *
- * This function is available only when NRF_LOG_USES_RTT is defined as 1.
- *
- * @note Do not call this function directly. Use @ref NRF_LOG_HAS_INPUT instead.
- *
- * @retval 1 If characters are available to read.
- * @retval 0 If no characters are available.
- */
-int log_rtt_has_input(void);
-
-/**@brief Function for reading one character from the input buffer.
- *
- * @param[out] p_char Pointer where to store the character.
- *
- * This function is available only when NRF_LOG_USES_RTT is defined as 1.
- *
- * @note Do not call this function directly. Use @ref NRF_LOG_READ_INPUT instead.
- *
- * @retval NRF_SUCCESS If the character was read out.
- * @retval NRF_ERROR_INVALID_DATA If no character could be read.
- */
-uint32_t log_rtt_read_input(char* p_char);
-
-#define NRF_LOG_INIT() log_rtt_init() /*!< Initialize the module. */
-
-#define NRF_LOG_PRINTF(...) log_rtt_printf(LOG_TERMINAL_NORMAL, ##__VA_ARGS__) /*!< Print a log message using printf. */
-#define NRF_LOG_PRINTF_DEBUG(...) log_rtt_printf(LOG_TERMINAL_NORMAL, ##__VA_ARGS__) /*!< If DEBUG is set, print a log message using printf. */
-#define NRF_LOG_PRINTF_ERROR(...) log_rtt_printf(LOG_TERMINAL_ERROR, ##__VA_ARGS__) /*!< Print a log message using printf to the error stream. */
-
-#define NRF_LOG(...) log_rtt_write_string(LOG_TERMINAL_NORMAL, NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< Print a log message. The input string must be null-terminated. */
-#define NRF_LOG_DEBUG(...) log_rtt_write_string(LOG_TERMINAL_NORMAL, NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< If DEBUG is set, print a log message. The input string must be null-terminated. */
-#define NRF_LOG_ERROR(...) log_rtt_write_string(LOG_TERMINAL_ERROR, NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< Print a log message to the error stream. The input string must be null-terminated. */
-
-#define NRF_LOG_HEX(val) log_rtt_write_hex(LOG_TERMINAL_NORMAL, val) /*!< Log an integer as HEX value (example output: 0x89ABCDEF). */
-#define NRF_LOG_HEX_DEBUG(val) log_rtt_write_hex(LOG_TERMINAL_NORMAL, val) /*!< If DEBUG is set, log an integer as HEX value (example output: 0x89ABCDEF). */
-#define NRF_LOG_HEX_ERROR(val) log_rtt_write_hex(LOG_TERMINAL_ERROR, val) /*!< Log an integer as HEX value to the error stream (example output: 0x89ABCDEF). */
-
-#define NRF_LOG_HEX_CHAR(val) log_rtt_write_hex_char(LOG_TERMINAL_NORMAL, val) /*!< Log a character as HEX value (example output: AA). */
-#define NRF_LOG_HEX_CHAR_DEBUG(val) log_rtt_write_hex_char(LOG_TERMINAL_NORMAL, val) /*!< If DEBUG is set, log a character as HEX value (example output: AA). */
-#define NRF_LOG_HEX_CHAR_ERROR(val) log_rtt_write_hex_char(LOG_TERMINAL_ERROR, val) /*!< Log a character as HEX value to the error stream (example output: AA). */
-
-#define NRF_LOG_HAS_INPUT() log_rtt_has_input() /*!< Check if the input buffer has unconsumed characters. */
-#define NRF_LOG_READ_INPUT(p_char) log_rtt_read_input(p_char) /*!< Consume a character from the input buffer. */
-
-#if !defined(DEBUG) && !defined(DOXYGEN)
-
-#undef NRF_LOG_DEBUG
-#define NRF_LOG_DEBUG(...)
-
-#undef NRF_LOG_STR_DEBUG
-#define NRF_LOG_STR_DEBUG(...)
-
-#undef NRF_LOG_HEX_DEBUG
-#define NRF_LOG_HEX_DEBUG(...)
-
-#undef NRF_LOG_HEX_CHAR_DEBUG
-#define NRF_LOG_HEX_CHAR_DEBUG(...)
-
-#endif // !defined(DEBUG) && !defined(DOXYGEN)
-
-#elif defined(NRF_LOG_USES_UART) && NRF_LOG_USES_UART == 1
-
-/**@brief Function for initializing the UART logger.
- *
- * This function is available only when NRF_LOG_USES_UART is defined as 1.
- *
- * @note Do not call this function directly. Use the macro @ref NRF_LOG_INIT instead.
- *
- * @retval NRF_SUCCESS If initialization was successful.
- * @retval NRF_ERROR Otherwise.
- */
-uint32_t log_uart_init(void);
-
-/**@brief Function for logging a printf string to UART.
- *
- * @details Printf requires more processor time
- * than other logging functions. Therefore, applications that require logging
- * but need it to interfere as little as possible with the execution, should
- * avoid using printf.
- *
- * This function is available only when NRF_LOG_USES_UART is defined as 1.
- *
- * @note This function is non-blocking. If too much data is sent to the UART,
- * some characters might be skipped.
- *
- * @note Do not call this function directly. Use one of the following macros instead:
- * - @ref NRF_LOG_PRINTF
- * - @ref NRF_LOG_PRINTF_DEBUG
- * - @ref NRF_LOG_PRINTF_ERROR
- *
- * @param format_msg Printf format string.
- */
-void log_uart_printf(const char * format_msg, ...);
-
-/**@brief Function for logging a single character to UART.
- *
- * This function is available only when NRF_LOG_USES_UART is defined as 1.
- *
- * @param c Character.
- */
-void log_uart_write_char(const char c);
-
-/**@brief Function for logging null-terminated strings to UART.
- *
- * @details This function is more efficient than using printf.
- * The null termination will not be logged.
- *
- * This function is available only when NRF_LOG_USES_UART is defined as 1.
- *
- * @note Do not call this function directly. Use one of the following macros instead:
- * - @ref NRF_LOG
- * - @ref NRF_LOG_DEBUG
- * - @ref NRF_LOG_ERROR
- *
- * @param num_args Number of arguments.
- */
-void log_uart_write_string_many(int num_args, ...);
-
-
-/**@brief Function for logging a null-terminated string to UART.
- *
- * @details This function is more efficient than using printf.
- * The null termination will not be logged.
- *
- * This function is available only when NRF_LOG_USES_UART is defined as 1.
- *
- * @note Do not call this function directly. Use one of the following macros instead:
- * - @ref NRF_LOG
- * - @ref NRF_LOG_DEBUG
- * - @ref NRF_LOG_ERROR
- *
- * @param msg Null-terminated string.
- */
-void log_uart_write_string(const char* msg);
-
-
-/**@brief Function for logging an integer value as HEX to UART.
- *
- * @details The output data is formatted as, for example, 0x89ABCDEF.
- * This function is more efficient than printf.
- *
- * This function is available only when NRF_LOG_USES_UART is defined as 1.
- *
- * @note This function is non-blocking. If too much data is sent to the UART,
- * some characters might be skipped.
- *
- * @note Do not call this function directly. Use one of the following macros instead:
- * - @ref NRF_LOG_HEX
- * - @ref NRF_LOG_HEX_DEBUG
- * - @ref NRF_LOG_HEX_ERROR
- *
- * @param value Integer value to be printed as HEX.
- */
-void log_uart_write_hex(uint32_t value);
-
-/**@brief Function for logging a single character as HEX to UART.
- *
- * @details The output string is formatted as, for example, AA.
- *
- * This function is available only when NRF_LOG_USES_UART is defined as 1.
- *
- * @note This function is non-blocking. If too much data is sent to the UART,
- * some characters might be skipped.
- *
- * @note Do not call this function directly. Use one of the following macros instead:
- * - @ref NRF_LOG_HEX_CHAR
- * - @ref NRF_LOG_HEX_CHAR_DEBUG
- * - @ref NRF_LOG_HEX_CHAR_ERROR
- *
- * @param c Character.
- */
-void log_uart_write_hex_char(uint8_t c);
-
-/**@brief Function for checking if data is available in the input buffer.
- *
- * This function is available only when NRF_LOG_USES_UART is defined as 1.
- *
- * @note Do not call this function directly. Use @ref NRF_LOG_HAS_INPUT instead.
- *
- * @retval 1 If characters are available to read.
- * @retval 0 If no characters are available.
- */
-int log_uart_has_input(void);
-
-/**@brief Function for reading one character from the input buffer.
- *
- * @param[out] p_char Pointer where to store the character.
- *
- * This function is available only when NRF_LOG_USES_UART is defined as 1.
- *
- * @note Do not call this function directly. Use NRF_LOG_READ_INPUT instead.
- *
- * @retval NRF_SUCCESS If the character was read out.
- * @retval NRF_ERROR_INVALID_DATA If no character could be read.
- */
-uint32_t log_uart_read_input(char* p_char);
-
-
-#define NRF_LOG_INIT() log_uart_init() /*!< Initialize the module. */
-
-#define NRF_LOG_PRINTF(...) log_uart_printf(__VA_ARGS__) /*!< Print a log message using printf. */
-#define NRF_LOG_PRINTF_DEBUG(...) log_uart_printf(__VA_ARGS__) /*!< If DEBUG is set, print a log message using printf. */
-#define NRF_LOG_PRINTF_ERROR(...) log_uart_printf(__VA_ARGS__) /*!< Print a log message using printf to the error stream. */
-
-#define NRF_LOG(...) log_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< Print a log message. The input string must be null-terminated. */
-#define NRF_LOG_DEBUG(...) log_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< If DEBUG is set, print a log message. The input string must be null-terminated. */
-#define NRF_LOG_ERROR(...) log_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< Print a log message to the error stream. The input string must be null-terminated. */
-
-#define NRF_LOG_HEX(val) log_uart_write_hex(val) /*!< Log an integer as HEX value (example output: 0x89ABCDEF). */
-#define NRF_LOG_HEX_DEBUG(val) log_uart_write_hex(val) /*!< If DEBUG is set, log an integer as HEX value (example output: 0x89ABCDEF). */
-#define NRF_LOG_HEX_ERROR(val) log_uart_write_hex(val) /*!< Log an integer as HEX value to the error stream (example output: 0x89ABCDEF). */
-
-#define NRF_LOG_HEX_CHAR(val) log_uart_write_hex_char(val) /*!< Log a character as HEX value (example output: AA). */
-#define NRF_LOG_HEX_CHAR_DEBUG(val) log_uart_write_hex_char(val) /*!< If DEBUG is set, log a character as HEX value (example output: AA). */
-#define NRF_LOG_HEX_CHAR_ERROR(val) log_uart_write_hex_char(val) /*!< Log a character as HEX value to the error stream (example output: AA). */
-
-#define NRF_LOG_HAS_INPUT() log_uart_has_input() /*!< Check if the input buffer has unconsumed characters. */
-#define NRF_LOG_READ_INPUT(p_char) log_uart_read_input(p_char) /*!< Consume a character from the input buffer. */
-
-#if !defined(DEBUG) && !defined(DOXYGEN)
-
-#undef NRF_LOG_DEBUG
-#define NRF_LOG_DEBUG(...)
-
-#undef NRF_LOG_PRINTF_DEBUG
-#define NRF_LOG_PRINTF_DEBUG(...)
-
-#undef NRF_LOG_STR_DEBUG
-#define NRF_LOG_STR_DEBUG(...)
-
-#undef NRF_LOG_HEX_DEBUG
-#define NRF_LOG_HEX_DEBUG(...)
-
-#undef NRF_LOG_HEX_CHAR_DEBUG
-#define NRF_LOG_HEX_CHAR_DEBUG(...)
-
-#endif // !defined(DEBUG) && !defined(DOXYGEN)
-
-#elif defined(NRF_LOG_USES_RAW_UART) && NRF_LOG_USES_RAW_UART == 1
-
-/**@brief Function for initializing the raw UART logger.
- *
- * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
- *
- * @note Do not call this function directly. Use the macro @ref NRF_LOG_INIT instead.
- *
- * @retval NRF_SUCCESS If initialization was successful.
- * @retval NRF_ERROR Otherwise.
- */
-uint32_t log_raw_uart_init(void);
-
-/**@brief Function for logging a printf string to raw UART.
- *
- * @details Printf requires more processor time
- * than other logging functions. Therefore, applications that require logging
- * but need it to interfere as little as possible with the execution, should
- * avoid using printf.
- *
- * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
- *
- * @note This function is non-blocking. If too much data is sent to the UART,
- * some characters might be skipped.
- *
- * @note Do not call this function directly. Use one of the following macros instead:
- * - @ref NRF_LOG_PRINTF
- * - @ref NRF_LOG_PRINTF_DEBUG
- * - @ref NRF_LOG_PRINTF_ERROR
- *
- * @param format_msg Printf format string.
- */
-void log_raw_uart_printf(const char * format_msg, ...);
-
-/**@brief Function for logging a single character to raw UART.
- *
- * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
- *
- * @param c Character.
- */
-void log_raw_uart_write_char(const char c);
-
-/**@brief Function for logging null-terminated strings to raw UART.
- *
- * @details This function is more efficient than using printf.
- * The null termination will not be logged.
- *
- * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
- *
- * @note Do not call this function directly. Use one of the following macros instead:
- * - @ref NRF_LOG
- * - @ref NRF_LOG_DEBUG
- * - @ref NRF_LOG_ERROR
- *
- * @param num_args Number of arguments.
- */
-void log_raw_uart_write_string_many(int num_args, ...);
-
-
-/**@brief Function for logging a null-terminated string to raw UART.
- *
- * @details This function is more efficient than using printf.
- * The null termination will not be logged.
- *
- * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
- *
- * @note Do not call this function directly. Use one of the following macros instead:
- * - @ref NRF_LOG
- * - @ref NRF_LOG_DEBUG
- * - @ref NRF_LOG_ERROR
- *
- * @param str Null-terminated string.
- */
-void log_raw_uart_write_string(const char * str);
-
-/**@brief Function for logging an integer value as HEX to raw UART.
- *
- * @details The output data is formatted as, for example, 0x89ABCDEF.
- * This function is more efficient than printf.
- *
- * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
- *
- * @note This function is non-blocking. If too much data is sent to the UART,
- * some characters might be skipped.
- *
- * @note Do not call this function directly. Use one of the following macros instead:
- * - @ref NRF_LOG_HEX
- * - @ref NRF_LOG_HEX_DEBUG
- * - @ref NRF_LOG_HEX_ERROR
- *
- * @param value Integer value to be printed as HEX.
- */
-void log_raw_uart_write_hex(uint32_t value);
-
-/**@brief Function for logging a single character as HEX to raw UART.
- *
- * @details The output string is formatted as, for example, AA.
- *
- * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
- *
- * @note This function is non-blocking. If too much data is sent to the UART,
- * some characters might be skipped.
- *
- * @note Do not call this function directly. Use one of the following macros instead:
- * - @ref NRF_LOG_HEX_CHAR
- * - @ref NRF_LOG_HEX_CHAR_DEBUG
- * - @ref NRF_LOG_HEX_CHAR_ERROR
- *
- * @param c Character.
- */
-void log_raw_uart_write_hex_char(uint8_t c);
-
-/**@brief Function for checking if data is available in the input buffer.
- *
- * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
- *
- * @note Do not call this function directly. Use @ref NRF_LOG_HAS_INPUT instead.
- *
- * @retval 1 If characters are available to read.
- * @retval 0 If no characters are available.
- */
-int log_raw_uart_has_input(void);
-
-/**@brief Function for reading one character from the input buffer.
- *
- * @param[out] p_char Pointer where to store the character.
- *
- * This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
- *
- * @note Do not call this function directly. Use NRF_LOG_READ_INPUT instead.
- *
- * @retval NRF_SUCCESS If the character was read out.
- * @retval NRF_ERROR_INVALID_DATA If no character could be read.
- */
-
-uint32_t log_raw_uart_read_input(char* p_char);
-
-#define NRF_LOG_INIT() log_raw_uart_init() /*!< nitialize the module. */
-
-#define NRF_LOG_PRINTF(...) log_raw_uart_printf(__VA_ARGS__) /*!< Print a log message using printf. */
-#define NRF_LOG_PRINTF_DEBUG(...) log_raw_uart_printf(__VA_ARGS__) /*!< If DEBUG is set, print a log message using printf. */
-#define NRF_LOG_PRINTF_ERROR(...) log_raw_uart_printf(__VA_ARGS__) /*!< Print a log message using printf to the error stream. */
-
-#define NRF_LOG(...) log_raw_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< Print a log message. The input string must be null-terminated. */
-#define NRF_LOG_DEBUG(...) log_raw_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< If DEBUG is set, print a log message. The input string must be null-terminated. */
-#define NRF_LOG_ERROR(...) log_raw_uart_write_string_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__) /*!< Print a log message to the error stream. The input string must be null-terminated. */
-
-#define NRF_LOG_HEX(val) log_raw_uart_write_hex(val) /*!< Log an integer as HEX value (example output: 0x89ABCDEF). */
-#define NRF_LOG_HEX_DEBUG(val) log_raw_uart_write_hex(val) /*!< If DEBUG is set, log an integer as HEX value (example output: 0x89ABCDEF). */
-#define NRF_LOG_HEX_ERROR(val) log_raw_uart_write_hex(val) /*!< Log an integer as HEX value to the error stream (example output: 0x89ABCDEF). */
-
-#define NRF_LOG_HEX_CHAR(val) log_raw_uart_write_hex_char(val) /*!< Log a character as HEX value (example output: AA). */
-#define NRF_LOG_HEX_CHAR_DEBUG(val) log_raw_uart_write_hex_char(val) /*!< If DEBUG is set, log a character as HEX value (example output: AA). */
-#define NRF_LOG_HEX_CHAR_ERROR(val) log_raw_uart_write_hex_char(val) /*!< Log a character as HEX value to the error stream (example output: AA). */
-
-#define NRF_LOG_HAS_INPUT() log_raw_uart_has_input() /*!< Check if the input buffer has unconsumed characters. */
-#define NRF_LOG_READ_INPUT(p_char) log_raw_uart_read_input(p_char) /*!< Consume a character from the input buffer. */
-
-#if !defined(DEBUG) && !defined(DOXYGEN)
-
-#undef NRF_LOG_DEBUG
-#define NRF_LOG_DEBUG(...)
-
-#undef NRF_LOG_PRINTF_DEBUG
-#define NRF_LOG_PRINTF_DEBUG(...)
-
-#undef NRF_LOG_STR_DEBUG
-#define NRF_LOG_STR_DEBUG(...)
-
-#undef NRF_LOG_HEX_DEBUG
-#define NRF_LOG_HEX_DEBUG(...)
-
-#undef NRF_LOG_HEX_CHAR_DEBUG
-#define NRF_LOG_HEX_CHAR_DEBUG(...)
-
-#endif // !defined(DEBUG) && !defined(DOXYGEN)
-
-#else
-
-#include "nrf_error.h"
-#include "nordic_common.h"
-
-// Empty definitions
-
-#define NRF_LOG_INIT() NRF_SUCCESS
-#define NRF_LOG(...)
-#define NRF_LOG_DEBUG(...)
-#define NRF_LOG_ERROR(...)
-
-#define NRF_LOG_PRINTF(...)
-#define NRF_LOG_PRINTF_DEBUG(...)
-#define NRF_LOG_PRINTF_ERROR(...)
-
-#define NRF_LOG_HEX(val)
-#define NRF_LOG_HEX_DEBUG(val)
-#define NRF_LOG_HEX_ERROR(val)
-
-#define NRF_LOG_HEX_CHAR(val)
-#define NRF_LOG_HEX_CHAR_DEBUG(val)
-#define NRF_LOG_HEX_CHAR_ERROR(val)
-
-#define NRF_LOG_HAS_INPUT() 0
-#define NRF_LOG_READ_INPUT(ignore) NRF_SUCCESS
-
-#endif
-
-/**@brief Function for writing HEX values.
- *
- * @note This function not thread-safe. It is written for convenience.
- * If you log from different application contexts, you might get different results.
- *
- * @retval NULL By default.
- */
-const char* log_hex(uint32_t value);
-
-/**@brief Function for writing HEX characters.
- *
- * @note This function not thread-safe. It is written for convenience.
- * If you log from different application contexts, you might get different results.
- *
- * @retval NULL By default.
- */
-const char* log_hex_char(const char value);
-
-
-
-
-#else // DOXYGEN
-
-/** @defgroup nrf_log UART/RTT logging
- * @{
- * @ingroup app_common
- *
- * @brief Library to output logging information over SEGGER's Real Time Transfer
- * (RTT), UART, or raw UART.
- *
- * This library provides macros that call the respective functions depending on
- * which protocol is used. Define LOG_USES_RTT=1 to enable logging over RTT,
- * NRF_LOG_USES_UART=1 to enable logging over UART, or NRF_LOG_USES_RAW_UART=1
- * to enable logging over raw UART. One of these defines must be set for any of
- * the macros to have effect. If you choose to not output information, all
- * logging macros can be left in the code without any cost; they will just be
- * ignored.
- */
-
-
-
-/**@brief Macro for initializing the logger.
- *
- * @retval NRF_SUCCESS If initialization was successful.
- * @retval NRF_ERROR Otherwise.
- */
-uint32_t NRF_LOG_INIT(void);
-
-/**@brief Macro for logging null-terminated strings.
- *
- * @details This function is more efficient than using printf.
- * The null termination will not be logged.
- *
- * @param msg Null-terminated string.
- */
-void NRF_LOG(const char* msg);
-
-/**@brief Macro for logging a printf string.
- *
- * @details Printf requires more processor time
- * than other logging functions. Therefore, applications that require logging
- * but need it to interfere as little as possible with the execution, should
- * avoid using printf.
- *
- * @note When NRF_LOG_USES_UART is set to 1, this macro is non-blocking.
- * If too much data is sent, some characters might be skipped.
- *
- * @param format_msg Printf format string.
- * @param ... Additional arguments replacing format specifiers in format_msg.
- */
-void NRF_LOG_PRINTF(const char * format_msg, ...);
-
-/**@brief Macro for logging an integer value as HEX.
- *
- * @details The output data is formatted as, for example, 0x89ABCDEF.
- * This function is more efficient than printf.
- *
- * @note When NRF_LOG_USES_UART is set to 1, this macro is non-blocking.
- * If too much data is sent, some characters might be skipped.
- *
- * @param value Integer value to be printed as HEX.
- */
-void NRF_LOG_HEX(uint32_t value);
-
-/**@brief Macro for logging a single character as HEX.
- *
- * @details The output string is formatted as, for example, AA.
- *
- * @note When NRF_LOG_USES_UART is set to 1, this macro is non-blocking.
- * If too much data is sent, some characters might be skipped.
- *
- * @param c Character.
- */
-void NRF_LOG_HEX_CHAR(uint8_t c);
-
-/**@brief Macro for checking if data is available in the input buffer.
- *
- * @note When NRF_LOG_USES_UART is set to 1, this macro is non-blocking.
- * If too much data is sent, some characters might be skipped.
- *
- * @retval 1 If characters are available to read.
- * @retval 0 If no characters are available.
- */
-int NRF_LOG_HAS_INPUT(void);
-
-/**@brief Macro for reading one character from the input buffer.
- *
- * @param[out] p_char Pointer where to store the character.
- *
- * @retval NRF_SUCCESS If the character was read out.
- * @retval NRF_ERROR_INVALID_DATA If no character could be read.
- */
-uint32_t NRF_LOG_READ_INPUT(char* p_char);
-
-/** @} */
-#endif // DOXYGEN
-#ifdef __cplusplus
-}
-#endif
-
-#endif // NRF_LOG_H_
[2/4] incubator-mynewt-core git commit: * debundle nordic ADC drivers,
as they rely on Nordic SDK, which is now bundled separately
Posted by st...@apache.org.
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 \ufffd 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 \ufffd 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 \ufffd 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 \ufffd 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;
-}
-
[4/4] incubator-mynewt-core git commit: * debundle nordic ADC drivers,
as they rely on Nordic SDK, which is now bundled separately
Posted by st...@apache.org.
* debundle nordic ADC drivers, as they rely on Nordic SDK, which is now
bundled separately
* debundle libraries/* which was not licensed correctly, and is
distributed separately as a part of the nordic sdk
* remove pointers to external nordic SDK, project now builds
successfully without that dependency
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/267d86b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/267d86b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/267d86b3
Branch: refs/heads/1_0_0_b1_dev
Commit: 267d86b3a639d4fb50bef65624fed797e9fcf419
Parents: a1481cb
Author: Sterling Hughes <st...@apache.org>
Authored: Mon Nov 21 21:30:09 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Mon Nov 21 21:30:09 2016 -0800
----------------------------------------------------------------------
hw/bsp/arduino_primo_nrf52/pkg.yml | 3 -
hw/bsp/arduino_primo_nrf52/src/hal_bsp.c | 16 -
hw/bsp/arduino_primo_nrf52/syscfg.yml | 13 -
hw/bsp/bmd300eval/pkg.yml | 3 -
hw/bsp/bmd300eval/src/hal_bsp.c | 18 -
hw/bsp/bmd300eval/syscfg.yml | 13 -
hw/bsp/nrf51-arduino_101/pkg.yml | 2 -
hw/bsp/nrf51-arduino_101/syscfg.yml | 7 -
hw/bsp/nrf51-blenano/pkg.yml | 3 -
hw/bsp/nrf51-blenano/syscfg.yml | 7 -
hw/bsp/nrf51dk-16kbram/pkg.yml | 3 -
hw/bsp/nrf51dk-16kbram/syscfg.yml | 7 -
hw/bsp/nrf51dk/pkg.yml | 5 -
hw/bsp/nrf51dk/syscfg.yml | 7 -
hw/bsp/nrf52dk/pkg.yml | 3 -
hw/bsp/nrf52dk/src/hal_bsp.c | 16 -
hw/bsp/nrf52dk/syscfg.yml | 13 -
hw/bsp/rb-nano2/pkg.yml | 3 -
hw/bsp/rb-nano2/syscfg.yml | 13 -
.../adc/adc_nrf51/include/adc_nrf51/adc_nrf51.h | 44 -
hw/drivers/adc/adc_nrf51/pkg.yml | 28 -
hw/drivers/adc/adc_nrf51/src/adc_nrf51.c | 405 ---
.../adc/adc_nrf52/include/adc_nrf52/adc_nrf52.h | 42 -
hw/drivers/adc/adc_nrf52/pkg.yml | 28 -
hw/drivers/adc/adc_nrf52/src/adc_nrf52.c | 404 ---
hw/mcu/nordic/nrf51xxx/pkg.yml | 2 +-
hw/mcu/nordic/nrf52xxx/pkg.yml | 2 +-
hw/mcu/nordic/pkg.yml | 22 +-
.../components/libraries/ant_fs/antfs.c | 2337 ------------------
.../components/libraries/ant_fs/antfs.h | 358 ---
.../components/libraries/ant_fs/crc.c | 55 -
.../components/libraries/ant_fs/crc.h | 50 -
.../components/libraries/ant_fs/defines.h | 68 -
.../components/libraries/ecc/ecc.c | 123 -
.../components/libraries/ecc/ecc.h | 61 -
.../components/libraries/timer/app_timer_rtx.c | 239 --
.../components/libraries/trace/app_trace.h | 64 -
.../components/libraries/util/nrf_assert.h | 68 -
.../components/libraries/util/nrf_log.c | 425 ----
.../components/libraries/util/nrf_log.h | 707 ------
40 files changed, 3 insertions(+), 5684 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/arduino_primo_nrf52/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/arduino_primo_nrf52/pkg.yml b/hw/bsp/arduino_primo_nrf52/pkg.yml
index ecaa468..8d6af0a 100644
--- a/hw/bsp/arduino_primo_nrf52/pkg.yml
+++ b/hw/bsp/arduino_primo_nrf52/pkg.yml
@@ -88,9 +88,6 @@ pkg.deps:
pkg.deps.BLE_DEVICE:
- hw/drivers/nimble/nrf52
-pkg.deps.ADC_0:
- - hw/drivers/adc/adc_nrf52
-
pkg.deps.UART_0:
- hw/drivers/uart/uart_hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/arduino_primo_nrf52/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/arduino_primo_nrf52/src/hal_bsp.c b/hw/bsp/arduino_primo_nrf52/src/hal_bsp.c
index 232bd6d..1a61b07 100644
--- a/hw/bsp/arduino_primo_nrf52/src/hal_bsp.c
+++ b/hw/bsp/arduino_primo_nrf52/src/hal_bsp.c
@@ -37,9 +37,6 @@
#if MYNEWT_VAL(UART_1)
#include "uart_bitbang/uart_bitbang.h"
#endif
-#if MYNEWT_VAL(ADC_0)
-#include "adc_nrf52/adc_nrf52.h"
-#endif
#if MYNEWT_VAL(UART_0)
static struct uart_dev os_bsp_uart0;
@@ -60,13 +57,6 @@ static const struct uart_bitbang_conf os_bsp_uart1_cfg = {
};
#endif
-#if MYNEWT_VAL(ADC_0)
-static struct adc_dev os_bsp_adc0;
-static struct nrf52_adc_dev_cfg os_bsp_adc0_config = {
- .nadc_refmv = 2800
-};
-#endif
-
#if MYNEWT_VAL(SPI_0_MASTER)
/*
* NOTE: Our HAL expects that the SS pin, if used, is treated as a gpio line
@@ -200,10 +190,4 @@ hal_bsp_init(void)
assert(rc == 0);
#endif
-#if MYNEWT_VAL(ADC_0)
- rc = os_dev_create((struct os_dev *) &os_bsp_adc0, "adc0",
- OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
- nrf52_adc_dev_init, &os_bsp_adc0_config);
- assert(rc == 0);
-#endif
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/arduino_primo_nrf52/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/arduino_primo_nrf52/syscfg.yml b/hw/bsp/arduino_primo_nrf52/syscfg.yml
index cea5591..c353c54 100644
--- a/hw/bsp/arduino_primo_nrf52/syscfg.yml
+++ b/hw/bsp/arduino_primo_nrf52/syscfg.yml
@@ -36,19 +36,6 @@ syscfg.defs:
description: 'TBD'
value: 1
- ADC_0:
- description: 'TBD'
- value: 0
- ADC_0_RESOLUTION:
- description: 'TBD'
- value: 'SAADC_CONFIG_RESOLUTION'
- ADC_0_OVERSAMPLE:
- description: 'TBD'
- value: 'SAADC_CONFIG_OVERSAMPLE'
- ADC_0_INTERRUPT_PRIORITY:
- description: 'TBD'
- value: 'SAADC_CONFIG_IRQ_PRIORITY'
-
UART_0:
description: 'TBD'
value: 1
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/bmd300eval/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/pkg.yml b/hw/bsp/bmd300eval/pkg.yml
index 4490156..a95cf05 100644
--- a/hw/bsp/bmd300eval/pkg.yml
+++ b/hw/bsp/bmd300eval/pkg.yml
@@ -87,9 +87,6 @@ pkg.deps:
pkg.deps.BLE_DEVICE:
- hw/drivers/nimble/nrf52
-pkg.deps.ADC_0:
- - hw/drivers/adc/adc_nrf52
-
pkg.deps.UART_0:
- hw/drivers/uart/uart_hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/bmd300eval/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/src/hal_bsp.c b/hw/bsp/bmd300eval/src/hal_bsp.c
index 117dd26..7bd7e2d 100644
--- a/hw/bsp/bmd300eval/src/hal_bsp.c
+++ b/hw/bsp/bmd300eval/src/hal_bsp.c
@@ -33,10 +33,6 @@
#include "os/os_dev.h"
#include "bsp.h"
-#if MYNEWT_VAL(ADC_0)
-#include "adc_nrf52/adc_nrf52.h"
-#endif
-
#if MYNEWT_VAL(UART_0)
static struct uart_dev os_bsp_uart0;
static const struct nrf52_uart_cfg os_bsp_uart0_cfg = {
@@ -56,13 +52,6 @@ static const struct uart_bitbang_conf os_bsp_uart1_cfg = {
};
#endif
-#if MYNEWT_VAL(ADC_0)
-static struct adc_dev os_bsp_adc0;
-static struct nrf52_adc_dev_cfg os_bsp_adc0_config = {
- .nadc_refmv = 2800
-};
-#endif
-
#if MYNEWT_VAL(SPI_0_MASTER)
/*
* NOTE: Our HAL expects that the SS pin, if used, is treated as a gpio line
@@ -195,11 +184,4 @@ hal_bsp_init(void)
OS_DEV_INIT_PRIMARY, 0, uart_bitbang_init, (void *)&os_bsp_uart1_cfg);
assert(rc == 0);
#endif
-
-#if MYNEWT_VAL(ADC_0)
- rc = os_dev_create((struct os_dev *) &os_bsp_adc0, "adc0",
- OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
- nrf52_adc_dev_init, &os_bsp_adc0_config);
- assert(rc == 0);
-#endif
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/bmd300eval/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/syscfg.yml b/hw/bsp/bmd300eval/syscfg.yml
index 35837af..ccfdadb 100644
--- a/hw/bsp/bmd300eval/syscfg.yml
+++ b/hw/bsp/bmd300eval/syscfg.yml
@@ -32,19 +32,6 @@ syscfg.defs:
description: 'TBD'
value: 1
- ADC_0:
- description: 'TBD'
- value: 0
- ADC_0_RESOLUTION:
- description: 'TBD'
- value: 'SAADC_CONFIG_RESOLUTION'
- ADC_0_OVERSAMPLE:
- description: 'TBD'
- value: 'SAADC_CONFIG_OVERSAMPLE'
- ADC_0_INTERRUPT_PRIORITY:
- description: 'TBD'
- value: 'SAADC_CONFIG_IRQ_PRIORITY'
-
UART_0:
description: 'TBD'
value: 1
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/nrf51-arduino_101/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-arduino_101/pkg.yml b/hw/bsp/nrf51-arduino_101/pkg.yml
index 062bd9a..1243efb 100644
--- a/hw/bsp/nrf51-arduino_101/pkg.yml
+++ b/hw/bsp/nrf51-arduino_101/pkg.yml
@@ -88,8 +88,6 @@ pkg.deps:
pkg.deps.BLE_DEVICE:
- hw/drivers/nimble/nrf51
-pkg.deps.ADC_0:
- - hw/drivers/adc/adc_nrf51
pkg.deps.UART_0:
- hw/drivers/uart/uart_hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/nrf51-arduino_101/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-arduino_101/syscfg.yml b/hw/bsp/nrf51-arduino_101/syscfg.yml
index 42e8c64..8c47db4 100644
--- a/hw/bsp/nrf51-arduino_101/syscfg.yml
+++ b/hw/bsp/nrf51-arduino_101/syscfg.yml
@@ -32,13 +32,6 @@ syscfg.defs:
description: 'TBD'
value: 1
- ADC_0:
- description: 'TBD'
- value: 0
- ADC_0_INTERRUPT_PRIORITY:
- description: 'TBD'
- value: 'ADC_CONFIG_IRQ_PRIORITY'
-
UART_0:
description: 'TBD'
value: 1
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/nrf51-blenano/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/pkg.yml b/hw/bsp/nrf51-blenano/pkg.yml
index 61553a5..839cec8 100644
--- a/hw/bsp/nrf51-blenano/pkg.yml
+++ b/hw/bsp/nrf51-blenano/pkg.yml
@@ -87,9 +87,6 @@ pkg.deps:
pkg.deps.BLE_DEVICE:
- hw/drivers/nimble/nrf51
-pkg.deps.ADC_0:
- - hw/drivers/adc/adc_nrf51
-
pkg.deps.UART_0:
- hw/drivers/uart/uart_hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/nrf51-blenano/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/syscfg.yml b/hw/bsp/nrf51-blenano/syscfg.yml
index defcd55..569382d 100644
--- a/hw/bsp/nrf51-blenano/syscfg.yml
+++ b/hw/bsp/nrf51-blenano/syscfg.yml
@@ -32,13 +32,6 @@ syscfg.defs:
description: 'TBD'
value: 1
- ADC_0:
- description: 'TBD'
- value: 1
- ADC_0_INTERRUPT_PRIORITY:
- description: 'TBD'
- value: 'ADC_CONFIG_IRQ_PRIORITY'
-
UART_0:
description: 'TBD'
value: 1
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/nrf51dk-16kbram/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/pkg.yml b/hw/bsp/nrf51dk-16kbram/pkg.yml
index 9c95016..bbb5f33 100644
--- a/hw/bsp/nrf51dk-16kbram/pkg.yml
+++ b/hw/bsp/nrf51dk-16kbram/pkg.yml
@@ -88,9 +88,6 @@ pkg.deps:
pkg.deps.BLE_DEVICE:
- hw/drivers/nimble/nrf51
-pkg.deps.ADC_0:
- - hw/drivers/adc/adc_nrf51
-
pkg.deps.UART_0:
- hw/drivers/uart/uart_hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/nrf51dk-16kbram/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/syscfg.yml b/hw/bsp/nrf51dk-16kbram/syscfg.yml
index 8a076f5..8e14b43 100644
--- a/hw/bsp/nrf51dk-16kbram/syscfg.yml
+++ b/hw/bsp/nrf51dk-16kbram/syscfg.yml
@@ -32,13 +32,6 @@ syscfg.defs:
description: 'TBD'
value: 1
- ADC_0:
- description: 'TBD'
- value: 0
- ADC_0_INTERRUPT_PRIORITY:
- description: 'TBD'
- value: 'ADC_CONFIG_IRQ_PRIORITY'
-
UART_0:
description: 'TBD'
value: 1
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/nrf51dk/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/pkg.yml b/hw/bsp/nrf51dk/pkg.yml
index 16d04bd..ddf62bd 100644
--- a/hw/bsp/nrf51dk/pkg.yml
+++ b/hw/bsp/nrf51dk/pkg.yml
@@ -28,7 +28,6 @@ pkg.keywords:
pkg.cflags:
# Nordic SDK files require these defines.
- - '-DADC_ENABLED=1'
- '-DCLOCK_ENABLED=1'
- '-DCOMP_ENABLED=0'
- '-DEGU_ENABLED=0'
@@ -46,7 +45,6 @@ pkg.cflags:
- '-DRTC0_ENABLED=0'
- '-DRTC1_ENABLED=0'
- '-DRTC2_ENABLED=0'
- - '-DSAADC_ENABLED=0'
- '-DSPI0_CONFIG_MISO_PIN=28'
- '-DSPI0_CONFIG_MOSI_PIN=25'
- '-DSPI0_CONFIG_SCK_PIN=29'
@@ -86,9 +84,6 @@ pkg.deps:
pkg.deps.BLE_DEVICE:
- hw/drivers/nimble/nrf51
-pkg.deps.ADC_0:
- - hw/drivers/adc/adc_nrf51
-
pkg.deps.UART_0:
- hw/drivers/uart/uart_hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/nrf51dk/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/syscfg.yml b/hw/bsp/nrf51dk/syscfg.yml
index 78129ce..bade890 100644
--- a/hw/bsp/nrf51dk/syscfg.yml
+++ b/hw/bsp/nrf51dk/syscfg.yml
@@ -32,13 +32,6 @@ syscfg.defs:
description: 'TBD'
value: 1
- ADC_0:
- description: 'TBD'
- value: 1
- ADC_0_INTERRUPT_PRIORITY:
- description: 'TBD'
- value: 'ADC_CONFIG_IRQ_PRIORITY'
-
UART_0:
description: 'TBD'
value: 1
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/nrf52dk/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/pkg.yml b/hw/bsp/nrf52dk/pkg.yml
index cdda423..f2685f8 100644
--- a/hw/bsp/nrf52dk/pkg.yml
+++ b/hw/bsp/nrf52dk/pkg.yml
@@ -87,9 +87,6 @@ pkg.deps:
pkg.deps.BLE_DEVICE:
- hw/drivers/nimble/nrf52
-pkg.deps.ADC_0:
- - hw/drivers/adc/adc_nrf52
-
pkg.deps.UART_0:
- hw/drivers/uart/uart_hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/nrf52dk/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/src/hal_bsp.c b/hw/bsp/nrf52dk/src/hal_bsp.c
index e6f51fc..be8322e 100644
--- a/hw/bsp/nrf52dk/src/hal_bsp.c
+++ b/hw/bsp/nrf52dk/src/hal_bsp.c
@@ -35,9 +35,6 @@
#include "uart_hal/uart_hal.h"
#include "os/os_dev.h"
#include "bsp.h"
-#if MYNEWT_VAL(ADC_0)
-#include "adc_nrf52/adc_nrf52.h"
-#endif
#if MYNEWT_VAL(UART_0)
static struct uart_dev os_bsp_uart0;
@@ -58,13 +55,6 @@ static const struct uart_bitbang_conf os_bsp_uart1_cfg = {
};
#endif
-#if MYNEWT_VAL(ADC_0)
-static struct adc_dev os_bsp_adc0;
-static struct nrf52_adc_dev_cfg os_bsp_adc0_config = {
- .nadc_refmv = 2800
-};
-#endif
-
#if MYNEWT_VAL(SPI_0_MASTER)
/*
* NOTE: Our HAL expects that the SS pin, if used, is treated as a gpio line
@@ -211,10 +201,4 @@ hal_bsp_init(void)
assert(rc == 0);
#endif
-#if MYNEWT_VAL(ADC_0)
- rc = os_dev_create((struct os_dev *) &os_bsp_adc0, "adc0",
- OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
- nrf52_adc_dev_init, &os_bsp_adc0_config);
- assert(rc == 0);
-#endif
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/nrf52dk/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/syscfg.yml b/hw/bsp/nrf52dk/syscfg.yml
index bc62394..18024af 100644
--- a/hw/bsp/nrf52dk/syscfg.yml
+++ b/hw/bsp/nrf52dk/syscfg.yml
@@ -29,19 +29,6 @@ syscfg.defs:
XTAL_32768:
description: 'TBD'
value: 1
- ADC_0:
- description: 'TBD'
- value: 0
- ADC_0_RESOLUTION:
- description: 'TBD'
- value: 'SAADC_CONFIG_RESOLUTION'
- ADC_0_OVERSAMPLE:
- description: 'TBD'
- value: 'SAADC_CONFIG_OVERSAMPLE'
- ADC_0_INTERRUPT_PRIORITY:
- description: 'TBD'
- value: 'SAADC_CONFIG_IRQ_PRIORITY'
-
UART_0:
description: 'TBD'
value: 1
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/rb-nano2/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/rb-nano2/pkg.yml b/hw/bsp/rb-nano2/pkg.yml
index 69497c0..4bce2f5 100644
--- a/hw/bsp/rb-nano2/pkg.yml
+++ b/hw/bsp/rb-nano2/pkg.yml
@@ -88,8 +88,5 @@ pkg.deps:
pkg.deps.BLE_DEVICE:
- hw/drivers/nimble/nrf52
-pkg.deps.ADC_0:
- - hw/drivers/adc/adc_nrf52
-
pkg.deps.UART_0:
- hw/drivers/uart/uart_hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/bsp/rb-nano2/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/rb-nano2/syscfg.yml b/hw/bsp/rb-nano2/syscfg.yml
index 8631290..ad48bd6 100644
--- a/hw/bsp/rb-nano2/syscfg.yml
+++ b/hw/bsp/rb-nano2/syscfg.yml
@@ -31,19 +31,6 @@ syscfg.defs:
XTAL_32768:
description: 'TBD'
value: 1
- ADC_0:
- description: 'TBD'
- value: 0
- ADC_0_RESOLUTION:
- description: 'TBD'
- value: 'SAADC_CONFIG_RESOLUTION'
- ADC_0_OVERSAMPLE:
- description: 'TBD'
- value: 'SAADC_CONFIG_OVERSAMPLE'
- ADC_0_INTERRUPT_PRIORITY:
- description: 'TBD'
- value: 'SAADC_CONFIG_IRQ_PRIORITY'
-
UART_0:
description: 'TBD'
value: 1
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/drivers/adc/adc_nrf51/include/adc_nrf51/adc_nrf51.h
----------------------------------------------------------------------
diff --git a/hw/drivers/adc/adc_nrf51/include/adc_nrf51/adc_nrf51.h b/hw/drivers/adc/adc_nrf51/include/adc_nrf51/adc_nrf51.h
deleted file mode 100644
index d681404..0000000
--- a/hw/drivers/adc/adc_nrf51/include/adc_nrf51/adc_nrf51.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.
- */
-
-#ifndef __ADC_NRF51_H__
-#define __ADC_NRF51_H__
-
-#include <adc/adc.h>
-
-#include <nrf.h>
-#include <nrf_adc.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct nrf51_adc_dev_cfg {
- uint16_t nadc_refmv0; /* reference mV in AREF0 */
- uint16_t nadc_refmv1; /* reference mV in AREF1 */
- uint16_t nadc_refmv_vdd; /* reference mV in VDD */
-};
-
-int nrf51_adc_dev_init(struct os_dev *, void *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __ADC_NRF51_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/drivers/adc/adc_nrf51/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/adc/adc_nrf51/pkg.yml b/hw/drivers/adc/adc_nrf51/pkg.yml
deleted file mode 100644
index 03e4120..0000000
--- a/hw/drivers/adc/adc_nrf51/pkg.yml
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# 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.
-#
-
-pkg.name: hw/drivers/adc/adc_nrf51
-pkg.description: ADC driver for the NRF51
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-pkg.apis:
- - ADC_HW_IMPL
-pkg.deps:
- - hw/drivers/adc
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/drivers/adc/adc_nrf51/src/adc_nrf51.c
----------------------------------------------------------------------
diff --git a/hw/drivers/adc/adc_nrf51/src/adc_nrf51.c b/hw/drivers/adc/adc_nrf51/src/adc_nrf51.c
deleted file mode 100644
index 129fb4a..0000000
--- a/hw/drivers/adc/adc_nrf51/src/adc_nrf51.c
+++ /dev/null
@@ -1,405 +0,0 @@
-/*
- * 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 <hal/hal_bsp.h>
-#include <adc/adc.h>
-#include <assert.h>
-#include <os/os.h>
-#include <bsp/cmsis_nvic.h>
-
-/* Nordic headers */
-#include <nrf.h>
-#include <nrf_adc.h>
-#include <nrf_drv_adc.h>
-#include <app_error.h>
-
-#include "adc_nrf51/adc_nrf51.h"
-
-/**
- * Weak symbol, this is defined in Nordic drivers but not exported.
- * Needed for NVIC_SetVector().
- */
-extern void ADC_IRQHandler(void);
-
-#define NRF_ADC_CHANNEL_COUNT (1)
-
-struct nrf51_adc_stats {
- uint16_t adc_events;
- uint16_t adc_events_failed;
-};
-static struct nrf51_adc_stats nrf51_adc_stats;
-
-static struct adc_dev *global_adc_dev;
-
-static nrf_drv_adc_config_t *global_adc_config;
-static struct nrf51_adc_dev_cfg *init_adc_config;
-
-static struct adc_chan_config nrf51_adc_chans[NRF_ADC_CHANNEL_COUNT];
-static nrf_drv_adc_channel_t *nrf_adc_chan;
-
-static void
-nrf51_adc_event_handler(const nrf_drv_adc_evt_t *event)
-{
- nrf_drv_adc_done_evt_t *done_ev;
- int rc;
-
- if (global_adc_dev == NULL) {
- ++nrf51_adc_stats.adc_events_failed;
- return;
- }
-
- ++nrf51_adc_stats.adc_events;
-
- /* Right now only data reads supported, assert for unknown event
- * type.
- */
- assert(event->type == NRF_DRV_ADC_EVT_DONE);
-
- done_ev = (nrf_drv_adc_done_evt_t * const) &event->data.done;
-
- rc = global_adc_dev->ad_event_handler_func(global_adc_dev,
- global_adc_dev->ad_event_handler_arg,
- ADC_EVENT_RESULT, done_ev->p_buffer,
- done_ev->size * sizeof(nrf_adc_value_t));
- if (rc != 0) {
- ++nrf51_adc_stats.adc_events_failed;
- }
-}
-
-/**
- * Open the NRF51 ADC device
- *
- * This function locks the device for access from other tasks.
- *
- * @param odev The OS device to open
- * @param wait The time in MS to wait. If 0 specified, returns immediately
- * if resource unavailable. If OS_WAIT_FOREVER specified, blocks
- * until resource is available.
- * @param arg Argument provided by higher layer to open, in this case
- * it can be a nrf_drv_saadc_config_t, to override the default
- * configuration.
- *
- * @return 0 on success, non-zero on failure.
- */
-static int
-nrf51_adc_open(struct os_dev *odev, uint32_t wait, void *arg)
-{
- struct adc_dev *dev;
- nrf_drv_adc_config_t *cfg;
- int rc;
-
- dev = (struct adc_dev *) odev;
-
- if (os_started()) {
- rc = os_mutex_pend(&dev->ad_lock, wait);
- if (rc != OS_OK) {
- goto err;
- }
- }
-
- /* Initialize the device */
- cfg = (nrf_drv_adc_config_t *)arg;
- rc = nrf_drv_adc_init(cfg, nrf51_adc_event_handler);
- if (rc != 0) {
- goto err;
- }
-
- global_adc_dev = dev;
- global_adc_config = arg;
-
- return (0);
-err:
- return (rc);
-}
-
-
-/**
- * Close the NRF51 ADC device.
- *
- * This function unlocks the device.
- *
- * @param odev The device to close.
- */
-static int
-nrf51_adc_close(struct os_dev *odev)
-{
- struct adc_dev *dev;
-
- dev = (struct adc_dev *) odev;
-
- nrf_drv_adc_uninit();
-
- global_adc_dev = NULL;
- global_adc_config = NULL;
-
- if (os_started()) {
- os_mutex_release(&dev->ad_lock);
- }
-
- return (0);
-}
-
-/**
- * Configure an ADC channel on the Nordic ADC.
- *
- * @param dev The ADC device to configure
- * @param cnum The channel on the ADC device to configure
- * @param cfgdata An opaque pointer to channel config, expected to be
- * a nrf_drv_adc_channel_config_t
- *
- * @return 0 on success, non-zero on failure.
- */
-static int
-nrf51_adc_configure_channel(struct adc_dev *dev, uint8_t cnum,
- void *cfgdata)
-{
- nrf_drv_adc_channel_t *cc;
- nrf_drv_adc_channel_config_t *cc_cfg;
- nrf_adc_config_t adc_cfg;
- uint16_t refmv;
- uint8_t res;
- int rc;
-
- rc = -1;
- if (global_adc_config == NULL) {
- goto err;
- }
-
- cc = (nrf_drv_adc_channel_t *)cfgdata;
- nrf_adc_chan = cc;
- cc_cfg = &cc->config.config;
-
- adc_cfg.reference = cc_cfg->reference |
- (cc_cfg->external_reference << ADC_CONFIG_EXTREFSEL_Pos);
- adc_cfg.resolution = cc_cfg->resolution;
- adc_cfg.scaling = cc_cfg->input;
- nrf_adc_configure(&adc_cfg);
- nrf_drv_adc_channel_enable(cc);
-
- /* Set the resolution and reference voltage for this channel to
- * enable conversion functions.
- */
- switch (adc_cfg.resolution) {
- case NRF_ADC_CONFIG_RES_8BIT:
- res = 8;
- break;
- case NRF_ADC_CONFIG_RES_9BIT:
- res = 9;
- break;
- case NRF_ADC_CONFIG_RES_10BIT:
- res = 10;
- break;
- default:
- assert(0);
- }
-
- switch (adc_cfg.reference) {
- case NRF_ADC_CONFIG_REF_VBG:
- refmv = 1200; /* 1.2V for NRF51 */
- break;
- case NRF_ADC_CONFIG_REF_EXT_REF0:
- refmv = init_adc_config->nadc_refmv0;
- break;
- case NRF_ADC_CONFIG_REF_EXT_REF1:
- refmv = init_adc_config->nadc_refmv1;
- break;
- case NRF_ADC_CONFIG_REF_SUPPLY_ONE_HALF:
- refmv = init_adc_config->nadc_refmv_vdd / 2;
- break;
- case NRF_ADC_CONFIG_REF_SUPPLY_ONE_THIRD:
- refmv = init_adc_config->nadc_refmv_vdd / 3;
- break;
- default:
- assert(0);
- }
-
- /* Adjust reference voltage for gain. */
- switch (cc_cfg->input) {
- case NRF_ADC_CONFIG_SCALING_INPUT_FULL_SCALE:
- break;
- case NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD:
- refmv *= 3;
- break;
- case NRF_ADC_CONFIG_SCALING_INPUT_TWO_THIRDS:
- refmv = (refmv * 3) / 2;
- break;
- case NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD:
- refmv = refmv * 3;
- break;
- case NRF_ADC_CONFIG_SCALING_SUPPLY_TWO_THIRDS:
- refmv = (refmv * 3) / 2;
- break;
- default:
- break;
- }
-
- /* Store these values in channel definitions, for conversions to
- * milivolts.
- */
- dev->ad_chans[cnum].c_res = res;
- dev->ad_chans[cnum].c_refmv = refmv;
- dev->ad_chans[cnum].c_configured = 1;
-
- return (0);
-err:
- return (rc);
-}
-
-/**
- * Set buffer to read data into. Implementation of setbuffer handler.
- * Sets both the primary and secondary buffers for DMA.
- */
-static int
-nrf51_adc_set_buffer(struct adc_dev *dev, void *buf1, void *buf2,
- int buf_len)
-{
- int rc;
-
- /* XXX: If this is called in blocking mode, it will result in a wait. */
-
- /* Convert overall buffer length, into a total number of samples which
- * Nordic APIs expect.
- */
- buf_len /= sizeof(nrf_adc_value_t);
-
- rc = nrf_drv_adc_buffer_convert((nrf_adc_value_t *) buf1, buf_len);
- if (rc != 0) {
- goto err;
- }
-
- /* XXX: For now, only support one buffer */
-#if 0
- if (buf2) {
- rc = nrf_drv_adc_buffer_convert((nrf_adc_value_t *) buf2,
- buf_len);
- if (rc != 0) {
- goto err;
- }
- }
-#endif
- return (0);
-err:
- return (rc);
-}
-
-static int
-nrf51_adc_release_buffer(struct adc_dev *dev, void *buf, int buf_len)
-{
- int rc;
-
- buf_len /= sizeof(nrf_adc_value_t);
-
- rc = nrf_drv_adc_buffer_convert((nrf_adc_value_t *) buf, buf_len);
- if (rc != 0) {
- goto err;
- }
-
- return (0);
-err:
- return (rc);
-}
-
-/**
- * Trigger an ADC sample.
- */
-static int
-nrf51_adc_sample(struct adc_dev *dev)
-{
- nrf_drv_adc_sample();
-
- return (0);
-}
-
-/**
- * Blocking read of an ADC channel, returns result as an integer.
- */
-static int
-nrf51_adc_read_channel(struct adc_dev *dev, uint8_t cnum, int *result)
-{
- nrf_adc_value_t adc_value;
- int rc;
-
- rc = nrf_drv_adc_sample_convert(nrf_adc_chan, &adc_value);
- if (rc == 0) {
- *result = (int) adc_value;
- }
- return (rc);
-}
-
-static int
-nrf51_adc_read_buffer(struct adc_dev *dev, void *buf, int buf_len, int off,
- int *result)
-{
- nrf_adc_value_t val;
- int data_off;
-
- data_off = off * sizeof(nrf_adc_value_t);
- assert(data_off < buf_len);
-
- val = *(nrf_adc_value_t *) ((uint8_t *) buf + data_off);
- *result = val;
-
- return (0);
-}
-
-static int
-nrf51_adc_size_buffer(struct adc_dev *dev, int chans, int samples)
-{
- return (sizeof(nrf_adc_value_t) * chans * samples);
-}
-
-
-/**
- * Callback to initialize an adc_dev structure from the os device
- * initialization callback. This sets up a nrf51_adc_device(), so that
- * subsequent lookups to this device allow us to manipulate it.
- */
-int
-nrf51_adc_dev_init(struct os_dev *odev, void *arg)
-{
- struct adc_dev *dev;
- struct adc_driver_funcs *af;
-
- dev = (struct adc_dev *) odev;
-
- os_mutex_init(&dev->ad_lock);
-
- dev->ad_chans = (void *) nrf51_adc_chans;
- dev->ad_chan_count = NRF_ADC_CHANNEL_COUNT;
-
- OS_DEV_SETHANDLERS(odev, nrf51_adc_open, nrf51_adc_close);
-
- assert(init_adc_config == NULL || init_adc_config == arg);
- init_adc_config = arg;
-
- af = &dev->ad_funcs;
-
- af->af_configure_channel = nrf51_adc_configure_channel;
- af->af_sample = nrf51_adc_sample;
- af->af_read_channel = nrf51_adc_read_channel;
- af->af_set_buffer = nrf51_adc_set_buffer;
- af->af_release_buffer = nrf51_adc_release_buffer;
- af->af_read_buffer = nrf51_adc_read_buffer;
- af->af_size_buffer = nrf51_adc_size_buffer;
-
- NVIC_SetVector(ADC_IRQn, (uint32_t) ADC_IRQHandler);
-
- return (0);
-}
-
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/drivers/adc/adc_nrf52/include/adc_nrf52/adc_nrf52.h
----------------------------------------------------------------------
diff --git a/hw/drivers/adc/adc_nrf52/include/adc_nrf52/adc_nrf52.h b/hw/drivers/adc/adc_nrf52/include/adc_nrf52/adc_nrf52.h
deleted file mode 100644
index 6aadb4c..0000000
--- a/hw/drivers/adc/adc_nrf52/include/adc_nrf52/adc_nrf52.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.
- */
-
-#ifndef __ADC_NRF52_H__
-#define __ADC_NRF52_H__
-
-#include <adc/adc.h>
-
-#include <nrf.h>
-#include <nrf_saadc.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct nrf52_adc_dev_cfg {
- uint16_t nadc_refmv; /* reference VDD in mV */
-};
-
-int nrf52_adc_dev_init(struct os_dev *, void *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __ADC_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/drivers/adc/adc_nrf52/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/adc/adc_nrf52/pkg.yml b/hw/drivers/adc/adc_nrf52/pkg.yml
deleted file mode 100644
index cd029e5..0000000
--- a/hw/drivers/adc/adc_nrf52/pkg.yml
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# 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.
-#
-
-pkg.name: hw/drivers/adc/adc_nrf52
-pkg.description: ADC driver for the NRF52
-pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-pkg.apis:
- - ADC_HW_IMPL
-pkg.deps:
- - hw/drivers/adc
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/drivers/adc/adc_nrf52/src/adc_nrf52.c
----------------------------------------------------------------------
diff --git a/hw/drivers/adc/adc_nrf52/src/adc_nrf52.c b/hw/drivers/adc/adc_nrf52/src/adc_nrf52.c
deleted file mode 100644
index 5054a9f..0000000
--- a/hw/drivers/adc/adc_nrf52/src/adc_nrf52.c
+++ /dev/null
@@ -1,404 +0,0 @@
-/*
- * 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 <hal/hal_bsp.h>
-#include <adc/adc.h>
-#include <assert.h>
-#include <os/os.h>
-#include <bsp/cmsis_nvic.h>
-
-/* Nordic headers */
-#include <nrf.h>
-#include <nrf_saadc.h>
-#include <nrf_drv_saadc.h>
-#include <app_error.h>
-
-#include "adc_nrf52/adc_nrf52.h"
-
-/**
- * Weak symbol, this is defined in Nordic drivers but not exported.
- * Needed for NVIC_SetVector().
- */
-extern void SAADC_IRQHandler(void);
-
-struct nrf52_saadc_stats {
- uint16_t saadc_events;
- uint16_t saadc_events_failed;
-};
-static struct nrf52_saadc_stats nrf52_saadc_stats;
-
-static struct adc_dev *global_adc_dev;
-static nrf_drv_saadc_config_t *global_adc_config;
-static struct nrf52_adc_dev_cfg *init_adc_config;
-
-static uint8_t nrf52_adc_chans[NRF_SAADC_CHANNEL_COUNT * sizeof(struct adc_chan_config)];
-
-static void
-nrf52_saadc_event_handler(const nrf_drv_saadc_evt_t *event)
-{
- nrf_drv_saadc_done_evt_t *done_ev;
- int rc;
-
- if (global_adc_dev == NULL) {
- ++nrf52_saadc_stats.saadc_events_failed;
- return;
- }
-
- ++nrf52_saadc_stats.saadc_events;
-
- /* Right now only data reads supported, assert for unknown event
- * type.
- */
- assert(event->type == NRF_DRV_SAADC_EVT_DONE);
-
- done_ev = (nrf_drv_saadc_done_evt_t * const) &event->data.done;
-
- rc = global_adc_dev->ad_event_handler_func(global_adc_dev,
- global_adc_dev->ad_event_handler_arg,
- ADC_EVENT_RESULT, done_ev->p_buffer,
- done_ev->size * sizeof(nrf_saadc_value_t));
- if (rc != 0) {
- ++nrf52_saadc_stats.saadc_events_failed;
- }
-}
-
-
-/**
- * Open the NRF52 ADC device
- *
- * This function locks the device for access from other tasks.
- *
- * @param odev The OS device to open
- * @param wait The time in MS to wait. If 0 specified, returns immediately
- * if resource unavailable. If OS_WAIT_FOREVER specified, blocks
- * until resource is available.
- * @param arg Argument provided by higher layer to open, in this case
- * it can be a nrf_drv_saadc_config_t, to override the default
- * configuration.
- *
- * @return 0 on success, non-zero on failure.
- */
-static int
-nrf52_adc_open(struct os_dev *odev, uint32_t wait, void *arg)
-{
- struct adc_dev *dev;
- int rc;
-
- dev = (struct adc_dev *) odev;
-
- if (os_started()) {
- rc = os_mutex_pend(&dev->ad_lock, wait);
- if (rc != OS_OK) {
- goto err;
- }
- }
-
- if (odev->od_flags & OS_DEV_F_STATUS_OPEN) {
- os_mutex_release(&dev->ad_lock);
- rc = OS_EBUSY;
- goto err;
- }
-
- /* Initialize the device */
- rc = nrf_drv_saadc_init((nrf_drv_saadc_config_t *) arg,
- nrf52_saadc_event_handler);
- if (rc != 0) {
- goto err;
- }
-
- global_adc_dev = dev;
- global_adc_config = arg;
-
- return (0);
-err:
- return (rc);
-}
-
-
-/**
- * Close the NRF52 ADC device.
- *
- * This function unlocks the device.
- *
- * @param odev The device to close.
- */
-static int
-nrf52_adc_close(struct os_dev *odev)
-{
- struct adc_dev *dev;
-
- dev = (struct adc_dev *) odev;
-
- nrf_drv_saadc_uninit();
-
- global_adc_dev = NULL;
- global_adc_config = NULL;
-
- if (os_started()) {
- os_mutex_release(&dev->ad_lock);
- }
-
- return (0);
-}
-
-/**
- * Configure an ADC channel on the Nordic ADC.
- *
- * @param dev The ADC device to configure
- * @param cnum The channel on the ADC device to configure
- * @param cfgdata An opaque pointer to channel config, expected to be
- * a nrf_saadc_channel_config_t
- *
- * @return 0 on success, non-zero on failure.
- */
-static int
-nrf52_adc_configure_channel(struct adc_dev *dev, uint8_t cnum,
- void *cfgdata)
-{
- nrf_saadc_channel_config_t *cc;
- uint16_t refmv;
- uint8_t res;
- int rc;
-
- cc = (nrf_saadc_channel_config_t *) cfgdata;
-
- rc = nrf_drv_saadc_channel_init(cnum, cc);
- if (rc != 0) {
- goto err;
- }
-
- if (global_adc_config) {
- /* Set the resolution and reference voltage for this channel to
- * enable conversion functions.
- */
- switch (global_adc_config->resolution) {
- case NRF_SAADC_RESOLUTION_8BIT:
- res = 8;
- break;
- case NRF_SAADC_RESOLUTION_10BIT:
- res = 10;
- break;
- case NRF_SAADC_RESOLUTION_12BIT:
- res = 12;
- break;
- case NRF_SAADC_RESOLUTION_14BIT:
- res = 14;
- break;
- default:
- assert(0);
- }
- } else {
- /* Default to 10-bit resolution. */
- res = 10;
- }
-
- switch (cc->reference) {
- case NRF_SAADC_REFERENCE_INTERNAL:
- refmv = 600; /* 0.6V for NRF52 */
- break;
- case NRF_SAADC_REFERENCE_VDD4:
- refmv = init_adc_config->nadc_refmv / 4;
- break;
- default:
- assert(0);
- }
-
- /* Adjust reference voltage for gain. */
- switch (cc->gain) {
- case NRF_SAADC_GAIN1_6:
- refmv *= 6;
- break;
- case NRF_SAADC_GAIN1_5:
- refmv *= 5;
- break;
- case NRF_SAADC_GAIN1_4:
- refmv *= 4;
- break;
- case NRF_SAADC_GAIN1_3:
- refmv *= 3;
- break;
- case NRF_SAADC_GAIN1_2:
- refmv *= 2;
- break;
- case NRF_SAADC_GAIN2:
- refmv /= 2;
- break;
- case NRF_SAADC_GAIN4:
- refmv /= 4;
- break;
- default:
- break;
- }
-
- /* Store these values in channel definitions, for conversions to
- * milivolts.
- */
- dev->ad_chans[cnum].c_res = res;
- dev->ad_chans[cnum].c_refmv = refmv;
- dev->ad_chans[cnum].c_configured = 1;
-
- return (0);
-err:
- return (rc);
-}
-
-/**
- * Set buffer to read data into. Implementation of setbuffer handler.
- * Sets both the primary and secondary buffers for DMA.
- */
-static int
-nrf52_adc_set_buffer(struct adc_dev *dev, void *buf1, void *buf2,
- int buf_len)
-{
- int rc;
-
- /* Convert overall buffer length, into a total number of samples which
- * Nordic APIs expect.
- */
- buf_len /= sizeof(nrf_saadc_value_t);
-
- rc = nrf_drv_saadc_buffer_convert((nrf_saadc_value_t *) buf1, buf_len);
- if (rc != 0) {
- goto err;
- }
-
- if (buf2) {
- rc = nrf_drv_saadc_buffer_convert((nrf_saadc_value_t *) buf2,
- buf_len);
- if (rc != 0) {
- goto err;
- }
- }
- return (0);
-err:
- return (rc);
-}
-
-static int
-nrf52_adc_release_buffer(struct adc_dev *dev, void *buf, int buf_len)
-{
- int rc;
-
- buf_len /= sizeof(nrf_saadc_value_t);
-
- rc = nrf_drv_saadc_buffer_convert((nrf_saadc_value_t *) buf, buf_len);
- if (rc != 0) {
- goto err;
- }
-
- return (0);
-err:
- return (rc);
-}
-
-/**
- * Trigger an ADC sample.
- */
-static int
-nrf52_adc_sample(struct adc_dev *dev)
-{
- nrf_drv_saadc_sample();
-
- return (0);
-}
-
-/**
- * Blocking read of an ADC channel, returns result as an integer.
- */
-static int
-nrf52_adc_read_channel(struct adc_dev *dev, uint8_t cnum, int *result)
-{
- nrf_saadc_value_t adc_value;
- int rc;
-
- rc = nrf_drv_saadc_sample_convert(cnum, &adc_value);
- if (rc != 0) {
- goto err;
- }
-
- *result = (int) adc_value;
-
- return (0);
-err:
- return (rc);
-}
-
-static int
-nrf52_adc_read_buffer(struct adc_dev *dev, void *buf, int buf_len, int off,
- int *result)
-{
- nrf_saadc_value_t val;
- int data_off;
-
- data_off = off * sizeof(nrf_saadc_value_t);
- assert(data_off < buf_len);
-
- val = *(nrf_saadc_value_t *) ((uint8_t *) buf + data_off);
- *result = val;
-
- return (0);
-}
-
-static int
-nrf52_adc_size_buffer(struct adc_dev *dev, int chans, int samples)
-{
- return (sizeof(nrf_saadc_value_t) * chans * samples);
-}
-
-
-/**
- * Callback to initialize an adc_dev structure from the os device
- * initialization callback. This sets up a nrf52_adc_device(), so
- * that subsequent lookups to this device allow us to manipulate it.
- */
-int
-nrf52_adc_dev_init(struct os_dev *odev, void *arg)
-{
- struct adc_dev *dev;
- struct adc_driver_funcs *af;
-
- dev = (struct adc_dev *) odev;
-
- os_mutex_init(&dev->ad_lock);
-
- dev->ad_chans = (void *) nrf52_adc_chans;
- dev->ad_chan_count = NRF_SAADC_CHANNEL_COUNT;
-
- OS_DEV_SETHANDLERS(odev, nrf52_adc_open, nrf52_adc_close);
-
- assert(init_adc_config == NULL || init_adc_config == arg);
- init_adc_config = arg;
-
- af = &dev->ad_funcs;
-
- af->af_configure_channel = nrf52_adc_configure_channel;
- af->af_sample = nrf52_adc_sample;
- af->af_read_channel = nrf52_adc_read_channel;
- af->af_set_buffer = nrf52_adc_set_buffer;
- af->af_release_buffer = nrf52_adc_release_buffer;
- af->af_read_buffer = nrf52_adc_read_buffer;
- af->af_size_buffer = nrf52_adc_size_buffer;
-
- NVIC_SetVector(SAADC_IRQn, (uint32_t) SAADC_IRQHandler);
-
- return (0);
-}
-
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/mcu/nordic/nrf51xxx/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/pkg.yml b/hw/mcu/nordic/nrf51xxx/pkg.yml
index 1043c16..d81834f 100644
--- a/hw/mcu/nordic/nrf51xxx/pkg.yml
+++ b/hw/mcu/nordic/nrf51xxx/pkg.yml
@@ -25,7 +25,7 @@ pkg.keywords:
- nrf51
pkg.deps:
- - '@mynewt_nordic/hw/mcu/nordic_sdk'
+ - hw/mcu/nordic
- compiler/arm-none-eabi-m0
- hw/cmsis-core
- hw/hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/mcu/nordic/nrf52xxx/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/pkg.yml b/hw/mcu/nordic/nrf52xxx/pkg.yml
index a9d4862..463dfff 100644
--- a/hw/mcu/nordic/nrf52xxx/pkg.yml
+++ b/hw/mcu/nordic/nrf52xxx/pkg.yml
@@ -25,7 +25,7 @@ pkg.keywords:
- nrf52
pkg.deps:
- - '@mynewt_nordic/hw/mcu/nordic_sdk'
+ - hw/mcu/nordic
- compiler/arm-none-eabi-m4
- hw/cmsis-core
- hw/hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/267d86b3/hw/mcu/nordic/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/pkg.yml b/hw/mcu/nordic/pkg.yml
index 54e3173..463aa68 100644
--- a/hw/mcu/nordic/pkg.yml
+++ b/hw/mcu/nordic/pkg.yml
@@ -26,31 +26,11 @@ pkg.keywords:
pkg.type: sdk
-pkg.ign_files.BSP_NRF52:
- - "nrf_drv_adc.c"
- - "pstorage*"
- - "sdk_mapped_flags.c"
-
-pkg.ign_files.BSP_NRF51:
- - "nrf_saadc.c"
- - "nrf_drv_saadc.c"
- - "nrf_drv_comp.c"
- - "nrf_drv_i2s.c"
- - "nrf_drv_pdm.c"
- - "nrf_drv_pwm.c"
- - "nrf_drv_spis.c"
- - "nrf_drv_twis.c"
- - "spi_5W_master.c"
- - "pstorage*"
- - "sdk_mapped_flags.c"
-
pkg.ign_dirs:
- "deprecated"
pkg.src_dirs:
- - "src/ext/nRF5_SDK_11.0.0_89a8197/components/drivers_nrf/"
- - "src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/fifo/"
- - "src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/util/"
+ - "src/ext/nRF5_SDK_11.0.0_89a8197/components/device/"
pkg.cflags: -std=gnu99 -DNRF52_PAN_28
[3/4] incubator-mynewt-core git commit: * debundle nordic ADC drivers,
as they rely on Nordic SDK, which is now bundled separately
Posted by st...@apache.org.
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.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/antfs.c b/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/antfs.c
deleted file mode 100644
index 8739073..0000000
--- a/hw/mcu/nordic/src/ext/nRF5_SDK_11.0.0_89a8197/components/libraries/ant_fs/antfs.c
+++ /dev/null
@@ -1,2337 +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 \ufffd Dynastream Innovations Inc. 2012
-All rights reserved.
-*/
-
-#include "antfs.h"
-#include <string.h>
-#include "defines.h"
-#include "app_error.h"
-#include "app_timer.h"
-#include "ant_error.h"
-#include "ant_parameters.h"
-#include "ant_interface.h"
-#include "ant_key_manager.h"
-#include "crc.h"
-#include "app_util.h"
-
-#ifdef LEDDRIVER_ACTIVE
- #include "bsp.h"
-#endif // LEDDRIVER_ACTIVE
-
-#define BURST_PACKET_SIZE 8u /**< The burst packet size. */
-
-#define ANTFS_CONNECTION_TYPE_OFFSET 0x00u /**< The connection type offset within ANT-FS message. */
-#define ANTFS_COMMAND_OFFSET 0x01u /**< The command offset within ANT-FS message. */
-#define ANTFS_RESPONSE_OFFSET 0x01u /**< The response offset within ANT-FS message. */
-
-#define ANTFS_CONTROL_OFFSET 0x02u /**< The control offset within ANT-FS message. */
-#define ANTFS_DATA_OFFSET 0x03u /**< The data offset within ANT-FS message. */
-
-#define ANTFS_BEACON_ID 0x43u /**< The ANT-FS beacon ID. */
-#define ANTFS_COMMAND_ID 0x44u /**< The ANT-FS command ID. */
-
-// Beacon definitions.
-#define STATUS1_OFFSET 0x01u /**< The beacon status1 field offset. */
-#define STATUS2_OFFSET 0x02u /**< The beacon status2 field offset. */
- #define DEVICE_STATE_SHIFT 0x00u /**< Shift value for device state bitfield. */
- #define DEVICE_STATE_MASK (0x0Fu << DEVICE_STATE_SHIFT) /**< Device state bitmask. */
- #define DEVICE_STATE_LINK (0x00u << DEVICE_STATE_SHIFT) /**< Device is in link state. */
- #define DEVICE_STATE_AUTHENTICATE (0x01u << DEVICE_STATE_SHIFT) /**< Device is in authenticate state. */
- #define DEVICE_STATE_TRANSPORT (0x02u << DEVICE_STATE_SHIFT) /**< Device is in transport state. */
- #define DEVICE_STATE_BUSY (0x03u << DEVICE_STATE_SHIFT) /**< Device is in busy state. */
-
-#define DEVICE_DESCRIPTOR_OFFSET_0 0x04u /**< Beacon ANT-FS device descriptor LSB position. */
-#define DEVICE_DESCRIPTOR_OFFSET_1 0x05u /**< Beacon ANT-FS device descriptor LSB + 1 position. */
-#define DEVICE_DESCRIPTOR_OFFSET_2 0x06u /**< Beacon ANT-FS device descriptor LSB + 2 position. */
-#define DEVICE_DESCRIPTOR_OFFSET_3 0x07u /**< Beacon ANT-FS device descriptor MSB position. */
-
-// Commands.
-#define ANTFS_CMD_NONE 0x00u /**< Used to identify that no ANT-FS command is in progress. */
-#define ANTFS_CMD_LINK_ID 0x02u /**< ANT-FS link command ID. */
-#define ANTFS_CMD_DISCONNECT_ID 0x03u /**< ANT-FS disconnect command ID. */
-#define ANTFS_CMD_AUTHENTICATE_ID 0x04u /**< ANT-FS authenticate command ID. */
-#define ANTFS_CMD_PING_ID 0x05u /**< ANT-FS ping command ID. */
-#define ANTFS_CMD_DOWNLOAD_ID 0x09u /**< ANT-FS download request command ID. */
-#define ANTFS_CMD_UPLOAD_REQUEST_ID 0x0Au /**< ANT-FS upload request command ID. */
-#define ANTFS_CMD_ERASE_ID 0x0Bu /**< ANT-FS erase request command ID. */
-#define ANTFS_CMD_UPLOAD_DATA_ID 0x0Cu /**< ANT-FS upload command ID. */
-
-// Responses.
-#define ANTFS_RSP_AUTHENTICATE_ID 0x84u /**< ANT-FS authenticate response command ID. */
-#define ANTFS_RSP_DOWNLOAD_ID 0x89u /**< ANT-FS download request response command ID. */
-#define ANTFS_RSP_UPLOAD_REQ_ID 0x8Au /**< ANT-FS upload request response command ID. */
-#define ANTFS_RSP_ERASE_ID 0x8Bu /**< ANT-FS erase response command ID. */
-#define ANTFS_RSP_UPLOAD_DATA_ID 0x8Cu /**< ANT-FS upload data response command ID. */
-
-// Link command.
-#define TRANSPORT_CHANNEL_FREQUENCY_OFFSET 0x02u /**< Channel frequency field offset within link command. */
-#define TRANSPORT_MESSAGE_PERIOD_OFFSET 0x03u /**< Channel period field offset within link command. */
-#define HOST_ID_OFFSET_0 0x04u /**< Host serial number period field LSB offset within link command. */
-#define HOST_ID_OFFSET_1 0x05u /**< Host serial number period field LSB + 1 offset within link command. */
-#define HOST_ID_OFFSET_2 0x06u /**< Host serial number period field LSB + 2 offset within link command. */
-#define HOST_ID_OFFSET_3 0x07u /**< Host serial number period field MSB offset within link command. */
-
-// Authenticate command.
-#define COMMAND_TYPE_OFFSET 0x02u /**< Command type field offset within authenticate command. */
- #define COMMAND_TYPE_PROCEED 0x00u /**< Command type proceed to transport in the authenticate command. */
- #define COMMAND_TYPE_REQUEST_SERIAL 0x01u /**< Command type request client device serial number in the authenticate command. */
- #define COMMAND_TYPE_REQUEST_PAIR 0x02u /**< Command type request pairing in the authenticate command. */
- #define COMMAND_TYPE_REQUEST_PASSKEY 0x03u /**< Command type request passkey exchange in the authenticate command. */
-
-// Authenticate response.
-#define RESPONSE_TYPE_OFFSET 0x02u /**< Command type field offset within authenticate response command. */
- #define AUTH_RESPONSE_N_A 0x00u /**< Command response type N/A (response for client serial number request). */
- #define AUTH_RESPONSE_ACCEPT 0x01u /**< Command response type accept. */
- #define AUTH_RESPONSE_REJECT 0x02u /**< Command response type reject. */
-
-// Authenticate command/response.
-#define AUTH_STRING_LENGTH_OFFSET 0x03u /**< Authenticate Command/Response authentication string length offset. */
-#define SERIAL_NUMBER_OFFSET_0 0x04u /**< Authenticate Command/Response client/host serial number LSB offset. */
-#define SERIAL_NUMBER_OFFSET_1 0x05u /**< Authenticate Command/Response client/host serial number LSB + 1 offset. */
-#define SERIAL_NUMBER_OFFSET_2 0x06u /**< Authenticate Command/Response client/host serial number LSB + 2 offset. */
-#define SERIAL_NUMBER_OFFSET_3 0x07u /**< Authenticate Command/Response client/host serial number MSB offset. */
-
-// Download/Upload/Erase commands.
-#define INITIAL_REQUEST_OFFSET 0x01u /**< Download/Upload/Erase command initial request command offset. */
-#define DATA_INDEX_OFFSET_LOW 0x02u /**< Download/Upload/Erase command offset index low. */
-#define DATA_INDEX_OFFSET_HIGH 0x03u /**< Download/Upload/Erase command offset index high. */
-
-#define ADDRESS_PARAMETER_OFFSET_0 0x04u /**< Download/Upload command parameter LSB offset. */
-#define ADDRESS_PARAMETER_OFFSET_1 0x05u /**< Download/Upload command parameter LSB + 1 offset. */
-#define ADDRESS_PARAMETER_OFFSET_2 0x06u /**< Download/Upload command parameter LSB + 2 offset. */
-#define ADDRESS_PARAMETER_OFFSET_3 0x07u /**< Download/Upload command parameter MSB offset. */
-#define UPLOAD_CRC_OFFSET_LOW 0x06u /**< Upload data CRC offset low. */
-#define UPLOAD_CRC_OFFSET_HIGH 0x07u /**< Upload data CRC offset high. */
-
-// Below compile switches should be provided by antfs_config.h:
-// - ANTFS_AUTH_TYPE_PAIRING /**< Use pairing and key exchange authentication. */
-// - ANTFS_AUTH_TYPE_PASSKEY /**< Use passkey authentication. */
-// - ANTFS_AUTH_TYPE_PASSTHROUGH /**< Allow host to bypass authentication. */
-// - ANTFS_INCLUDE_UPLOAD /**< Support upload operation. */
-
-// Authentication type. The highest level of authentication available is included in the beacon.
-#if defined (ANTFS_AUTH_TYPE_PASSKEY)
- #define AUTHENTICATION_TYPE COMMAND_TYPE_REQUEST_PASSKEY /**< Passkey and pairing only mode set as authentication type in beacon. */
-#elif defined (ANTFS_AUTH_TYPE_PAIRING)
- #define AUTHENTICATION_TYPE COMMAND_TYPE_REQUEST_PAIR /**< Pairing only mode set as authentication type in beacon. */
-#elif defined (ANTFS_AUTH_TYPE_PASSTHROUGH)
- #define AUTHENTICATION_TYPE COMMAND_TYPE_PROCEED /**< Pass-through mode set as authentication type in beacon. */
-#else
- #error "No valid auth type defined"
-#endif
-
-#define AUTHENTICATION_RETRIES 0x05u /**< Max number of retries for authentication responses */
-
-#define ANTFS_EVENT_QUEUE_SIZE 0x04u /**< ANT-FS event queue size. */
-#define SAVE_DISTANCE 256u /**< Save distance required because of nRF buffer to line up data offset on retry. */
-
-// Buffer Indices.
-#define BUFFER_INDEX_MESG_SIZE 0x00u /**< ANT message buffer index length offset. */
-#define BUFFER_INDEX_MESG_ID 0x01u /**< ANT message buffer index ID offset. */
-#define BUFFER_INDEX_CHANNEL_NUM 0x02u /**< ANT message buffer index channel number offset. */
-#define BUFFER_INDEX_MESG_DATA 0x03u /**< ANT message buffer index begin of data offset. */
-#define BUFFER_INDEX_RESPONSE_CODE 0x04u /**< ANT message buffer index response code offset. */
-
-typedef struct
-{
- char friendly_name[ANTFS_FRIENDLY_NAME_MAX]; /**< Friendly Name. */
- bool is_name_set; /**< Is the name set. */
- uint32_t index; /**< Current index (for reading the friendly name). */
- uint32_t friendly_name_size; /**< Friendly name size. */
-} friendly_name_t;
-
-typedef union
-{
- antfs_link_substate_t link_sub_state; /**< Sub-state (Link layer). */
- antfs_authenticate_substate_t auth_sub_state; /**< Sub-state (Authentication layer). */
- antfs_transport_substate_t trans_sub_state; /**< Sub-state (Transport layer). */
-} antfs_substate_t;
-
-typedef struct
-{
- antfs_state_t state; /**< ANT-FS state. */
- antfs_substate_t sub_state; /**< ANT-FS sub-state. */
-} antfs_states_t;
-
-typedef struct
-{
- antfs_event_return_t * p_queue; /**< ANT-FS event queue. */
- uint32_t head; /**< ANT-FS event queue head index. */
- uint32_t tail; /**< ANT-FS event queue tail index. */
-} antfs_event_queue_t;
-
-static antfs_params_t m_initial_parameters; /**< Initial parameters. */
-static antfs_beacon_status_byte1_t m_active_beacon_status1_field; /**< Status 1 field in beacon. */
-static uint32_t m_active_beacon_frequency; /**< Active beacon frequency. */
-static antfs_states_t m_current_state; /**< Current state. */
-static friendly_name_t m_friendly_name; /**< Host's friendly name. */
-static ulong_union_t m_link_host_serial_number; /**< Host's serial number. */
-static uint32_t m_link_command_in_progress; /**< ANT-FS command in progress. */
-static uint32_t m_authenticate_command_type; /**< Authenticate command type in progress. */
-static volatile uint8_t m_burst_wait; /**< Polling status flag for data unlock on burst handler input. */
-static uint8_t m_retry; /**< Retry counter */
-APP_TIMER_DEF(m_timer_id); /**< Timer ID used with the timer module. */
-
-#if defined (ANTFS_AUTH_TYPE_PASSKEY)
- static uint32_t m_passkey_index; /**< Current location of Tx block (auth string). */
-#endif // ANTFS_AUTH_TYPE_PASSKEY
-
-// Download/upload.
-static bool m_is_data_request_pending; /**< Requested data pending. */
-static bool m_is_crc_pending; /**< CRC for data packets pending. */
-static ushort_union_t m_file_index; /**< File index of current upload/download. */
-static ulong_union_t m_file_size; /**< File size of current upload/download (bytes). */
-static ulong_union_t m_max_block_size; /**< Maximum number of bytes expected to be downloaded in a single burst block of data (set by host). */
-static ulong_union_t m_link_burst_index; /**< Current location of Tx block (bytes). */
-static ulong_union_t m_bytes_remaining; /**< Total remaining data length (bytes). */
-static ulong_union_t m_max_transfer_index; /**< Upper limit of the current Tx burst block (bytes). */
-static uint32_t m_bytes_to_write; /**< Number of bytes to write to file (upload). */
-static const uint8_t * mp_upload_data; /**< Address of begin of the buffer that holds data received from upload. */
-#ifdef ANTFS_INCLUDE_UPLOAD
- static ulong_union_t m_block_size; /**< Number of bytes the client can receive in a single burst. */
-#endif // ANTFS_INCLUDE_UPLOAD
-
-// CRC verification.
-static uint32_t m_saved_crc_offset; /**< CRC data offset (bytes) saved at last CRC update (save point). */
-static uint32_t m_saved_buffer_crc_offset; /**< Data offset to track how much data has been buffered into nRF */
-static uint32_t m_temp_crc_offset; /**< Temporary CRC data offset used in CRC calculation. */
-static uint16_t m_compared_crc; /**< 16-bit CRC for all data packets in the block (provided by download request). */
-static uint16_t m_transfer_crc; /**< 16-bit CRC for all data packets in the block (calculated by client). */
-static uint16_t m_saved_transfer_crc; /**< 16-bit CRC saved at last CRC update (save point). */
-static uint16_t m_saved_buffer_crc; /**< 16-bit CRC saved at last CRC update (save point) for buffering the nRF */
-
-// ANT-FS event handling.
-static antfs_event_return_t m_event_queue_buffer[ANTFS_EVENT_QUEUE_SIZE]; /**< Event queue storage. */
-static antfs_event_queue_t m_event_queue; /**< Event queue. */
-
-static antfs_burst_wait_handler_t m_burst_wait_handler = NULL; /**< Burst wait handler */
-
-
-const char * antfs_hostname_get(void)
-{
- if (m_friendly_name.is_name_set)
- {
- return (m_friendly_name.friendly_name);
- }
-
- return NULL;
-}
-
-
-/**@brief Function for waiting for the burst transmission request to complete.
- */
-static void wait_burst_request_to_complete(void)
-{
- while (m_burst_wait != 0)
- {
- if(m_burst_wait_handler != NULL)
- {
- m_burst_wait_handler();
- }
- };
-}
-
-
-/**@brief Function for stopping ANT-FS timeout, which is possibly currently running.
- */
-static void timeout_disable(void)
-{
- m_link_command_in_progress = ANTFS_CMD_NONE;
-
- const uint32_t err_code = app_timer_stop(m_timer_id);
- APP_ERROR_CHECK(err_code);
-}
-
-
-/**@brief Function for transmitting a beacon.
- *
- * Transmits a beacon either using a broadcast or burst transmission mode.
- *
- * @param[in] message_type Defines the used transmission mode.
- */
-static void beacon_transmit(uint32_t message_type)
-{
- uint8_t beacon_status_byte2;
-
- // Set beacon status byte 2.
-
- if (m_link_command_in_progress == ANTFS_CMD_NONE)
- {
- switch (m_current_state.state)
- {
- case ANTFS_STATE_AUTH:
- beacon_status_byte2 = DEVICE_STATE_AUTHENTICATE;
- break;
-
- case ANTFS_STATE_TRANS:
- beacon_status_byte2 = DEVICE_STATE_TRANSPORT;
- break;
-
- default:
- beacon_status_byte2 = DEVICE_STATE_LINK;
- break;
- }
- }
- else
- {
- beacon_status_byte2 = DEVICE_STATE_BUSY;
- }
-
- // Set remaining beacon fields.
-
- uint8_t tx_buffer[BURST_PACKET_SIZE];
-
- tx_buffer[0] = ANTFS_BEACON_ID;
- tx_buffer[1] = m_active_beacon_status1_field.status;
- tx_buffer[2] = beacon_status_byte2;
- tx_buffer[3] = AUTHENTICATION_TYPE;
-
- if ((m_current_state.state == ANTFS_STATE_AUTH) ||
- (m_current_state.state == ANTFS_STATE_TRANS))
- {
- tx_buffer[4] = m_link_host_serial_number.bytes.byte0;
- tx_buffer[5] = m_link_host_serial_number.bytes.byte1;
- tx_buffer[6] = m_link_host_serial_number.bytes.byte2;
- tx_buffer[7] = m_link_host_serial_number.bytes.byte3;
- }
- else
- {
- tx_buffer[4] = m_initial_parameters.beacon_device_type;
- tx_buffer[5] = (m_initial_parameters.beacon_device_type >> 8u);
- tx_buffer[6] = m_initial_parameters.beacon_device_manufacturing_id;
- tx_buffer[7] = (m_initial_parameters.beacon_device_manufacturing_id >> 8u);
- }
-
- if (message_type == MESG_BROADCAST_DATA_ID)
- {
- if (sd_ant_broadcast_message_tx(ANTFS_CHANNEL, sizeof(tx_buffer), tx_buffer) != NRF_SUCCESS)
- {
- // @note: No implementation needed, as it is a valid and accepted use case for this call
- // to fail. This call can fail if we are in middle of bursting.
- }
- }
- else if(message_type == MESG_BURST_DATA_ID)
- {
- // Send as the first packet of a burst.
- const uint32_t err_code = sd_ant_burst_handler_request(ANTFS_CHANNEL,
- sizeof(tx_buffer),
- tx_buffer,
- BURST_SEGMENT_START);
- APP_ERROR_CHECK(err_code);
-
- wait_burst_request_to_complete();
-
- // This is the first packet of a burst response, disable command timeout while bursting.
- timeout_disable();
- }
- else
- {
- // This should not happen.
- APP_ERROR_HANDLER(message_type);
- }
-}
-
-
-/**@brief Function for transmitting a authenticate response message.
- *
- * @param[in] response_type Authenticate response code.
- * @param[in] password_length Length of authentication string.
- * @param[in] p_password Authentication string transmitted.
- */
-static void authenticate_response_transmit(uint8_t response_type,
- uint32_t password_length,
- const uint8_t * p_password)
-{
- ulong_union_t serial_number;
-
- serial_number.data = m_initial_parameters.client_serial_number;
-
- // First packet is beacon.
- beacon_transmit(MESG_BURST_DATA_ID);
-
- uint8_t tx_buffer[BURST_PACKET_SIZE];
-
- tx_buffer[ANTFS_CONNECTION_TYPE_OFFSET] = ANTFS_COMMAND_ID;
- tx_buffer[ANTFS_RESPONSE_OFFSET] = ANTFS_RSP_AUTHENTICATE_ID;
- tx_buffer[RESPONSE_TYPE_OFFSET] = response_type;
- tx_buffer[AUTH_STRING_LENGTH_OFFSET] = password_length;
- tx_buffer[SERIAL_NUMBER_OFFSET_0] = serial_number.bytes.byte0;
- tx_buffer[SERIAL_NUMBER_OFFSET_1] = serial_number.bytes.byte1;
- tx_buffer[SERIAL_NUMBER_OFFSET_2] = serial_number.bytes.byte2;
- tx_buffer[SERIAL_NUMBER_OFFSET_3] = serial_number.bytes.byte3;
-
- uint32_t err_code;
- if ((m_current_state.state == ANTFS_STATE_AUTH) &&
- (
- (response_type != AUTH_RESPONSE_REJECT) &&
- password_length &&
- (password_length <= ANTFS_AUTH_STRING_MAX)
- )
- )
- {
- // Send second packet (auth response).
- err_code = sd_ant_burst_handler_request(ANTFS_CHANNEL,
- sizeof(tx_buffer),
- tx_buffer,
- BURST_SEGMENT_CONTINUE);
- APP_ERROR_CHECK(err_code);
-
- wait_burst_request_to_complete();
-
- // Round size to a multiple of 8 bytes.
- uint8_t tx_buffer_authenticate[ANTFS_AUTH_STRING_MAX + 1u];
-
- memset(tx_buffer_authenticate, 0, ANTFS_AUTH_STRING_MAX + 1u);
- memcpy(tx_buffer_authenticate, p_password, password_length);
-
- // Round up total number bytes to a multiple of 8 to be sent to burst handler.
- if (password_length & (BURST_PACKET_SIZE - 1u))
- {
- password_length &= ~(BURST_PACKET_SIZE - 1u);
- password_length += BURST_PACKET_SIZE;
- }
-
- // Send auth string (last packets of the burst).
- err_code = sd_ant_burst_handler_request(ANTFS_CHANNEL,
- password_length,
- tx_buffer_authenticate,
- BURST_SEGMENT_END);
- APP_ERROR_CHECK(err_code);
-
- wait_burst_request_to_complete();
-
- m_link_command_in_progress = ANTFS_RSP_AUTHENTICATE_ID;
- }
- else
- {
- // If the authorization is rejected or there is no valid password, the auth response is the
- // last packet.
-
- err_code = sd_ant_burst_handler_request(ANTFS_CHANNEL,
- sizeof(tx_buffer),
- tx_buffer,
- BURST_SEGMENT_END);
- APP_ERROR_CHECK(err_code);
-
- wait_burst_request_to_complete();
- }
-
- // Switch to appropiate state.
- if (response_type == AUTH_RESPONSE_REJECT)
- {
- m_current_state.sub_state.auth_sub_state = ANTFS_AUTH_SUBSTATE_REJECT;
- }
- else if (response_type == AUTH_RESPONSE_ACCEPT)
- {
- m_current_state.sub_state.auth_sub_state = ANTFS_AUTH_SUBSTATE_ACCEPT;
- }
- else
- {
- // No implementation needed.
- }
-}
-
-
-bool antfs_pairing_resp_transmit(bool accept)
-{
-#if defined(ANTFS_AUTH_TYPE_PAIRING)
- // This function should only be called when ANT-FS is in PAIRING mode.
- if ((m_current_state.state != ANTFS_STATE_AUTH) ||
- (m_current_state.sub_state.auth_sub_state != ANTFS_AUTH_SUBSTATE_PAIR))
- {
- return false;
- }
-
- m_link_command_in_progress = ANTFS_CMD_AUTHENTICATE_ID;
-
- if (accept)
- {
- // Accept request and send passkey if authentication passed.
- authenticate_response_transmit(AUTH_RESPONSE_ACCEPT,
- ANTFS_PASSKEY_SIZE,
- m_initial_parameters.p_pass_key);
- }
- else
- {
- // Reject authentication request.
- authenticate_response_transmit(AUTH_RESPONSE_REJECT, 0, NULL);
- }
-
- return true;
-#else
- return false;
-#endif // ANTFS_AUTH_TYPE_PAIRING
-}
-
-
-/**@brief Function for adding an ANT-FS event to the event queue.
- *
- * @param[in] event_code The event to be added.
- */
-static void event_queue_write(antfs_event_t event_code)
-{
- antfs_event_return_t * p_event = NULL;
-#ifdef LEDDRIVER_ACTIVE
- uint32_t err_code;
-#endif
-
- // Check if there is room in the queue for a new event.
- if (((m_event_queue.head + 1u) & (ANTFS_EVENT_QUEUE_SIZE - 1u)) != m_event_queue.tail)
- {
- p_event = &(m_event_queue.p_queue[m_event_queue.head]);
- }
-
- if (p_event != NULL)
- {
- // Initialize event parameters.
- p_event->event = event_code;
-
- // Set parameters depending on event type.
- switch (event_code)
- {
- case ANTFS_EVENT_ERASE_REQUEST:
- p_event->file_index = m_file_index.data;
- p_event->offset = 0;
- p_event->bytes = 0;
- p_event->crc = 0;
- break;
-
- case ANTFS_EVENT_DOWNLOAD_REQUEST:
- p_event->file_index = m_file_index.data;
- // Requested offset for the download.
- p_event->offset = m_link_burst_index.data;
- p_event->bytes = 0;
- p_event->crc = 0;
- break;
-
- case ANTFS_EVENT_DOWNLOAD_REQUEST_DATA:
- p_event->file_index = m_file_index.data;
- // Current offset.
- p_event->offset = m_link_burst_index.data;
-
- if (m_bytes_remaining.data > (ANTFS_BURST_BLOCK_SIZE * BURST_PACKET_SIZE))
- {
- // If remaining bytes > burst block size then grab one block at a time.
- p_event->bytes = ANTFS_BURST_BLOCK_SIZE * BURST_PACKET_SIZE;
- }
- else
- {
- p_event->bytes = m_bytes_remaining.data;
- }
-
- p_event->crc = 0;
- break;
-
- case ANTFS_EVENT_UPLOAD_REQUEST:
- p_event->file_index = m_file_index.data;
- // Requested offset for the upload.
- p_event->offset = m_link_burst_index.data;
- // Upper limit of the download (offset + remaining bytes).
- p_event->bytes = m_max_transfer_index.data;
- // CRC Seed (from last save point if resuming).
- p_event->crc = m_transfer_crc;
- break;
-
- case ANTFS_EVENT_UPLOAD_DATA:
- p_event->file_index = m_file_index.data;
- // Current offset.
- p_event->offset = m_link_burst_index.data;
- // Current CRC.
- p_event->crc = m_transfer_crc;
- // Number of bytes to write.
- p_event->bytes = m_bytes_to_write;
- // Upload to appication data buffer.
- memcpy(p_event->data, mp_upload_data, m_bytes_to_write);
- break;
-
- case ANTFS_EVENT_PAIRING_REQUEST:
-#ifdef LEDDRIVER_ACTIVE
- err_code = bsp_indication_set(BSP_INDICATE_BONDING);
- APP_ERROR_CHECK(err_code);
-#endif // LEDDRIVER_ACTIVE
- break;
-
- default:
- // No parameters need to be set.
-
- p_event->file_index = 0;
- p_event->offset = 0;
- p_event->bytes = 0;
- p_event->crc = 0;
- break;
- }
-
- // Put the event in the queue.
- m_event_queue.head = ((m_event_queue.head + 1u) & (ANTFS_EVENT_QUEUE_SIZE - 1u));
- }
- else
- {
- // No free space left in the queue.
- APP_ERROR_HANDLER(0);
- }
-}
-
-
-/**@brief Function for transmitting download request response message.
- *
- * @param[in] response Download response code.
- */
-static void download_request_response_transmit(uint8_t response)
-{
- // First burst packet is beacon.
- beacon_transmit(MESG_BURST_DATA_ID);
-
- uint8_t tx_buffer[BURST_PACKET_SIZE];
-
- // Next send the first part of the download response.
- tx_buffer[0] = ANTFS_COMMAND_ID;
- tx_buffer[1] = ANTFS_RSP_DOWNLOAD_ID;
- tx_buffer[2] = response;
- tx_buffer[3] = 0;
- // Total number of bytes remaining in the data block.
- tx_buffer[4] = m_bytes_remaining.bytes.byte0;
- tx_buffer[5] = m_bytes_remaining.bytes.byte1;
- tx_buffer[6] = m_bytes_remaining.bytes.byte2;
- tx_buffer[7] = m_bytes_remaining.bytes.byte3;
-
- uint32_t err_code = sd_ant_burst_handler_request(ANTFS_CHANNEL,
- sizeof(tx_buffer),
- tx_buffer,
- BURST_SEGMENT_CONTINUE);
- APP_ERROR_CHECK(err_code);
-
- wait_burst_request_to_complete();
-
- // Second part of the download response.
-
- // The offset the data will start from in this block.
- tx_buffer[0] = m_link_burst_index.bytes.byte0;
- tx_buffer[1] = m_link_burst_index.bytes.byte1;
- tx_buffer[2] = m_link_burst_index.bytes.byte2;
- tx_buffer[3] = m_link_burst_index.bytes.byte3;
- // The file size in the client device.
- tx_buffer[4] = m_file_size.bytes.byte0;
- tx_buffer[5] = m_file_size.bytes.byte1;
- tx_buffer[6] = m_file_size.bytes.byte2;
- tx_buffer[7] = m_file_size.bytes.byte3;
-
- if (response || (m_bytes_remaining.data == 0))
- {
- // If the download was rejected or there is no data to send.
-
- // Set response to end since we're not downloading any data.
- err_code = sd_ant_burst_handler_request(ANTFS_CHANNEL,
- sizeof(tx_buffer),
- tx_buffer,
- BURST_SEGMENT_END);
- APP_ERROR_CHECK(err_code);
-
- wait_burst_request_to_complete();
- }
- else
- {
- // Response will continue (data packets + CRC footer to follow).
- err_code = sd_ant_burst_handler_request(ANTFS_CHANNEL,
- sizeof(tx_buffer),
- tx_buffer,
- BURST_SEGMENT_CONTINUE);
- APP_ERROR_CHECK(err_code);
-
- wait_burst_request_to_complete();
- }
-
- m_link_command_in_progress = ANTFS_CMD_DOWNLOAD_ID;
-
- if (response == 0)
- {
- // If we are going to download (response OK), enter the downloading substate.
- m_current_state.sub_state.trans_sub_state = ANTFS_TRANS_SUBSTATE_DOWNLOADING;
- event_queue_write(ANTFS_EVENT_DOWNLOAD_START);
- }
- else
- {
- // Download rejected.
- event_queue_write(ANTFS_EVENT_DOWNLOAD_FAIL);
- }
-}
-
-
-void antfs_download_req_resp_prepare(uint8_t response,
- const antfs_request_info_t * const p_request_info)
-{
- // This function should only be called after receiving a download request.
- APP_ERROR_CHECK_BOOL((m_current_state.state == ANTFS_STATE_TRANS) &&
- (m_link_command_in_progress == ANTFS_CMD_DOWNLOAD_ID));
-
- if (response == 0)
- {
- // Download request OK.
-
- // File size of the requested download.
- m_file_size.data = p_request_info->file_size.data;
-
- if (m_link_burst_index.data > m_file_size.data)
- {
- // Offset should not exceed file size.
- m_link_burst_index.data = m_file_size.data;
- }
-
- // If the host is not limiting download size or the file size does not exceed the host's
- // download size limit.
- if ((m_max_block_size.data == 0) || (m_file_size.data < m_max_block_size.data))
- {
- // Number of bytes remaining to be downloaded in this block is the file size.
- m_bytes_remaining.data = m_file_size.data;
- }
-
- if ((m_file_size.data - m_link_burst_index.data) < m_bytes_remaining.data)
- {
- // Calculate number of remaining bytes in this block based on the offset.
- m_bytes_remaining.data = m_file_size.data - m_link_burst_index.data;
- }
-
- // If the application is limiting the Tx block size.
- if (m_bytes_remaining.data > p_request_info->max_burst_block_size.data)
- {
- // Number of remaining bytes in this block is the application defined block size.
- m_bytes_remaining.data = p_request_info->max_burst_block_size.data;
- }
-
- // Find upper limit of the burst Tx.
- m_max_transfer_index.data = m_link_burst_index.data + m_bytes_remaining.data;
-
- if (m_saved_crc_offset == ANTFS_MAX_FILE_SIZE)
- {
- // CRC checking was set as invalid. An invalid download was requested, so reject it.
- response = RESPONSE_INVALID_OPERATION;
- }
- }
-
- if ((response != 0) || (m_file_size.data == 0))
- {
- // Send the response right away if the download request was rejected or there is no data to
- // send.
- download_request_response_transmit(response);
- }
- else
- {
- // Proceed to download data.
- if (m_link_burst_index.data != m_saved_crc_offset)
- {
- uint32_t temp;
-
- // If requesting to resume exactly where we left off, we can start from the same block.
- if (m_link_burst_index.data == m_temp_crc_offset)
- {
- // Move last save point to end of last block sent.
- m_saved_crc_offset = m_link_burst_index.data;
- m_saved_transfer_crc = m_transfer_crc;
- }
-
- // To resume the download, request a block of data starting from the last save point.
- // Update the remaining number of bytes per the last save point.
- m_bytes_remaining.data += (m_link_burst_index.data - m_saved_crc_offset);
-
- // Swap the current burst Tx index with the saved CRC index, to make sure we do not
- // start updating the CRC until we get to the requested index.
- temp = m_link_burst_index.data;
- m_link_burst_index.data = m_saved_crc_offset;
- m_saved_crc_offset = temp;
-
- // Set CRC to previous save point, to check the CRC provided by the host.
- m_transfer_crc = m_saved_transfer_crc;
- }
-
- m_temp_crc_offset = m_saved_crc_offset;
-
- m_is_data_request_pending = true;
-
- // Request data from application.
- event_queue_write(ANTFS_EVENT_DOWNLOAD_REQUEST_DATA);
-
- m_current_state.sub_state.trans_sub_state = ANTFS_TRANS_SUBSTATE_VERIFY_CRC;
- }
-}
-
-
-uint32_t antfs_input_data_download(uint16_t index,
- uint32_t offset,
- uint32_t num_bytes,
- const uint8_t * const p_message)
-{
- // Verify that this is the requested data.
- APP_ERROR_CHECK_BOOL((offset == m_link_burst_index.data) && (index == m_file_index.data));
-
- // If file offset is greater than the upper limit, this is not data we need.
- APP_ERROR_CHECK_BOOL(offset <= m_max_transfer_index.data);
-
- if ((m_current_state.state == ANTFS_STATE_TRANS) &&
- (
- (m_current_state.sub_state.trans_sub_state == ANTFS_TRANS_SUBSTATE_VERIFY_CRC) ||
- // Only send data if we were processing a download request.
- (m_current_state.sub_state.trans_sub_state == ANTFS_TRANS_SUBSTATE_DOWNLOADING)
- )
- )
- {
- uint32_t block_offset = 0;
-
- if (m_current_state.sub_state.trans_sub_state == ANTFS_TRANS_SUBSTATE_VERIFY_CRC)
- {
- // Make sure download_request_response_transmit defaults to RESPONSE_INVALID_CRC.
- uint32_t response = RESPONSE_MESSAGE_OK;
-
- // Check CRC.
- if (m_link_burst_index.data == m_saved_crc_offset)
- {
- // If indexes match, we can compare CRC directly.
- if (m_transfer_crc != m_compared_crc)
- {
- response = RESPONSE_INVALID_CRC;
- }
- else
- {
- // Set up the save point
- m_temp_crc_offset = m_link_burst_index.data; // Reset save point counter
- m_saved_crc_offset = m_link_burst_index.data;
- m_saved_buffer_crc_offset = m_link_burst_index.data;
-
- // Set up the CRC save points
- m_saved_transfer_crc = m_compared_crc;
- m_saved_buffer_crc = m_compared_crc;
- m_is_crc_pending = true;
- }
- // Start bursting beacon and the download response (3 burst packets).
- download_request_response_transmit(response);
- }
- // If the data is in this block, advance to the requested offset
- else if ((m_link_burst_index.data < m_saved_crc_offset) &&
- ((m_saved_crc_offset - m_link_burst_index.data) < num_bytes))
- {
- // Update the offset within this block for the requested transmission.
- block_offset = m_saved_crc_offset - m_link_burst_index.data;
- // Update the number of bytes that will actually be transmitted.
- num_bytes -= block_offset;
-
- // Update CRC calculation up to requested index.
- m_transfer_crc = crc_crc16_update(m_transfer_crc, p_message, block_offset);
- // Update the remaining number of bytes.
- m_bytes_remaining.data -= block_offset;
-
- // Check CRC
- if (m_transfer_crc != m_compared_crc)
- {
- response = RESPONSE_INVALID_CRC;
- }
- else
- {
- // Move index back to point where transmission will resume.
- m_link_burst_index.data = m_saved_crc_offset;
-
- // Set up the save point
- m_temp_crc_offset = m_link_burst_index.data; // Reset save point counter
- m_saved_buffer_crc_offset = m_link_burst_index.data;
-
- // Set up the CRC save points
- m_saved_transfer_crc = m_compared_crc;
- m_saved_buffer_crc = m_compared_crc;
-
- m_is_crc_pending = true;
- }
- download_request_response_transmit(response);
- }
- // Data index has gone too far and it is not possible to check CRC, fail and let host retry
- else if(m_link_burst_index.data > m_saved_crc_offset)
- {
- response = RESPONSE_INVALID_CRC;
- download_request_response_transmit(response);
- }
- // Keep getting data and recalculate the CRC until the indexes match
- else
- {
- m_is_data_request_pending = false;
-
- // Update the current burst index and bytes remaining
- m_link_burst_index.data += num_bytes;
- m_bytes_remaining.data -= num_bytes;
-
- // Update CRC
- m_transfer_crc = crc_crc16_update(m_transfer_crc, p_message, num_bytes);
-
- // Request more data.
- event_queue_write(ANTFS_EVENT_DOWNLOAD_REQUEST_DATA);
- }
- }
-
- // Append data.
- if (m_current_state.sub_state.trans_sub_state == ANTFS_TRANS_SUBSTATE_DOWNLOADING)
- {
- uint32_t num_of_bytes_to_burst = num_bytes;
-
- if (num_of_bytes_to_burst & (BURST_PACKET_SIZE - 1u))
- {
- // Round up total number bytes to a multiple of BURST_PACKET_SIZE to be sent to
- // burst handler.
- num_of_bytes_to_burst &= ~(BURST_PACKET_SIZE - 1u);
- num_of_bytes_to_burst += BURST_PACKET_SIZE;
- }
-
- uint32_t err_code = sd_ant_burst_handler_request(ANTFS_CHANNEL,
- num_of_bytes_to_burst,
- (uint8_t*)&(p_message[block_offset]),
- BURST_SEGMENT_CONTINUE);
- if(err_code != NRF_ANT_ERROR_TRANSFER_SEQUENCE_NUMBER_ERROR)
- {
- // If burst failed before we are able to catch it, we will get a TRANSFER_SEQUENCE_NUMBER_ERROR
- // The message processing will send client back to correct state
- APP_ERROR_CHECK(err_code);
- }
-
- wait_burst_request_to_complete();
-
- // Update current burst index.
- m_link_burst_index.data += num_bytes;
- // Update remaining bytes.
- m_bytes_remaining.data -= num_bytes;
-
- m_is_data_request_pending = false;
-
- m_transfer_crc = crc_crc16_update(m_transfer_crc,
- &(p_message[block_offset]),
- num_bytes);
-
- if((m_link_burst_index.data - m_temp_crc_offset) > SAVE_DISTANCE)
- {
- // Set CRC save point
- m_saved_transfer_crc = m_saved_buffer_crc; // Set CRC at buffer save point (will always be one behind to account for buffering)
- m_saved_buffer_crc = m_transfer_crc; // Set CRC at save point
-
- // Set offset save point
- m_saved_crc_offset = m_saved_buffer_crc_offset; // Set offset at buffer save point (will always be one behind to account for buffering)
- m_saved_buffer_crc_offset = m_link_burst_index.data; // Set buffer offset to current data offset
-
- // Reset save counter offset
- m_temp_crc_offset = m_link_burst_index.data; // Set to current location; next save point will take place after SAVE_DISTANCE bytes
- }
-
- if (!m_is_data_request_pending && (m_link_burst_index.data < m_max_transfer_index.data))
- {
- // If we have not finished the download.
-
- // Request more data.
- event_queue_write(ANTFS_EVENT_DOWNLOAD_REQUEST_DATA);
-
- m_is_data_request_pending = true;
- }
- else if (m_link_burst_index.data >= m_max_transfer_index.data && m_is_crc_pending)
- {
- // We are done, send CRC footer.
-
- uint8_t tx_buffer[BURST_PACKET_SIZE];
-
- tx_buffer[0] = 0;
- tx_buffer[1] = 0;
- tx_buffer[2] = 0;
- tx_buffer[3] = 0;
- tx_buffer[4] = 0;
- tx_buffer[5] = 0;
- tx_buffer[6] = (uint8_t)m_transfer_crc;
- tx_buffer[7] = (uint8_t)(m_transfer_crc >> 8u);
-
- err_code = sd_ant_burst_handler_request(ANTFS_CHANNEL,
- sizeof(tx_buffer),
- tx_buffer,
- BURST_SEGMENT_END);
- if(err_code != NRF_ANT_ERROR_TRANSFER_SEQUENCE_NUMBER_ERROR)
- {
- // If burst failed before we are able to catch it, we will get a TRANSFER_SEQUENCE_NUMBER_ERROR
- // The message processing will send client back to correct state
- APP_ERROR_CHECK(err_code);
- }
-
- wait_burst_request_to_complete();
-
- m_is_crc_pending = false;
- m_max_transfer_index.data = 0;
- }
-
- // Return the number of bytes we accepted.
- return num_bytes;
- }
- }
-
- // No bytes were accepted.
- return 0;
-}
-
-
-bool antfs_upload_req_resp_transmit(uint8_t response,
- const antfs_request_info_t * const p_request_info)
-{
-#if defined(ANTFS_INCLUDE_UPLOAD)
- if (m_current_state.state != ANTFS_STATE_TRANS ||
- // Only send the response if we were processing an upload request.
- (m_link_command_in_progress != ANTFS_CMD_UPLOAD_REQUEST_ID))
- {
- return false;
- }
-
- // If the application is sending a response for a different file than requested, the upload
- // will fail.
- if (p_request_info->file_index.data != m_file_index.data)
- {
- event_queue_write(ANTFS_EVENT_UPLOAD_FAIL);
-
- return false;
- }
-
- ulong_union_t max_mem_size;
- // Set maximum number of bytes that can be written to the file.
- max_mem_size.data = p_request_info->max_file_size;
-
- if (p_request_info->max_burst_block_size.data != 0)
- {
- // If the client is limiting the block size set the block size requested by the client.
- m_block_size.data = p_request_info->max_burst_block_size.data;
- }
- else
- {
- // Try to get the entire file in a single block.
- m_block_size.data = max_mem_size.data;
- }
-
- if (response == 0)
- {
- if (m_max_transfer_index.data > max_mem_size.data)
- {
- // Not enough space to write file, reject download.
- response = RESPONSE_MESSAGE_NOT_ENOUGH_SPACE;
- }
- }
-
- // Get last valid CRC and last valid offset.
- m_transfer_crc = p_request_info->file_crc;
- m_link_burst_index.data = p_request_info->file_size.data;
-
- // First packet to transmit is the beacon.
- beacon_transmit(MESG_BURST_DATA_ID);
-
- // Second packet.
-
- uint8_t tx_buffer[BURST_PACKET_SIZE];
-
- tx_buffer[0] = ANTFS_COMMAND_ID;
- tx_buffer[1] = ANTFS_RSP_UPLOAD_REQ_ID;
- tx_buffer[2] = response;
- tx_buffer[3] = 0;
- // Last valid data offset written to the file.
- tx_buffer[4] = m_link_burst_index.bytes.byte0;
- tx_buffer[5] = m_link_burst_index.bytes.byte1;
- tx_buffer[6] = m_link_burst_index.bytes.byte2;
- tx_buffer[7] = m_link_burst_index.bytes.byte3;
-
-
- uint32_t err_code = sd_ant_burst_handler_request(ANTFS_CHANNEL,
- sizeof(tx_buffer),
- tx_buffer,
- BURST_SEGMENT_CONTINUE);
- APP_ERROR_CHECK(err_code);
-
- wait_burst_request_to_complete();
-
- // Third packet.
-
- // Maximum number of bytes that can be written to the file.
- tx_buffer[0] = max_mem_size.bytes.byte0;
- tx_buffer[1] = max_mem_size.bytes.byte1;
- tx_buffer[2] = max_mem_size.bytes.byte2;
- tx_buffer[3] = max_mem_size.bytes.byte3;
- // Maximum upload block size.
- tx_buffer[4] = m_block_size.bytes.byte0;
- tx_buffer[5] = m_block_size.bytes.byte1;
- tx_buffer[6] = m_block_size.bytes.byte2;
- tx_buffer[7] = m_block_size.bytes.byte3;
-
- err_code = sd_ant_burst_handler_request(ANTFS_CHANNEL,
- sizeof(tx_buffer),
- tx_buffer,
- BURST_SEGMENT_CONTINUE);
- APP_ERROR_CHECK(err_code);
-
- wait_burst_request_to_complete();
-
- // Fourth packet.
-
- tx_buffer[0] = 0;
- tx_buffer[1] = 0;
- tx_buffer[2] = 0;
- tx_buffer[3] = 0;
- tx_buffer[4] = 0;
- tx_buffer[5] = 0;
- // Value of CRC at last data offset.
- tx_buffer[6] = (uint8_t) m_transfer_crc;
- tx_buffer[7] = (uint8_t)(m_transfer_crc >> 8);
-
- err_code = sd_ant_burst_handler_request(ANTFS_CHANNEL,
- sizeof(tx_buffer),
- tx_buffer,
- BURST_SEGMENT_END);
- APP_ERROR_CHECK(err_code);
-
- wait_burst_request_to_complete();
-
- m_link_command_in_progress = ANTFS_CMD_UPLOAD_REQUEST_ID;
-
- if (response != 0)
- {
- // Failed upload request. Reset max transfer index to 0 (do not accept any data if the host
- // sends it anyway).
- m_max_transfer_index.data = 0;
- }
- else
- {
- // Wait for upload data request.
- m_current_state.sub_state.trans_sub_state = ANTFS_TRANS_SUBSTATE_UPLOAD_WAIT_FOR_DATA;
- }
-
- return true;
-#else
- return false;
-#endif // ANTFS_INCLUDE_UPLOAD
-}
-
-
-bool antfs_upload_data_resp_transmit(bool data_upload_success)
-{
-#if defined(ANTFS_INCLUDE_UPLOAD)
- // Should be in TRANSPORT layer to send this response.
- if (m_current_state.state != ANTFS_STATE_TRANS)
- {
- return false;
- }
-
- uint8_t tx_buffer[BURST_PACKET_SIZE];
-
- // Response.
- tx_buffer[0] = ANTFS_COMMAND_ID;
- tx_buffer[1] = ANTFS_RSP_UPLOAD_DATA_ID;
- tx_buffer[2] = (data_upload_success) ? RESPONSE_MESSAGE_OK : RESPONSE_MESSAGE_FAIL;
- tx_buffer[3] = 0;
- tx_buffer[4] = 0;
- tx_buffer[5] = 0;
- tx_buffer[6] = 0;
- tx_buffer[7] = 0;
-
- // First packet is beacon.
- beacon_transmit(MESG_BURST_DATA_ID);
-
- // Send last packet.
- uint32_t err_code = sd_ant_burst_handler_request(ANTFS_CHANNEL,
- sizeof(tx_buffer),
- tx_buffer,
- BURST_SEGMENT_END);
- APP_ERROR_CHECK(err_code);
-
- wait_burst_request_to_complete();
-
- m_link_command_in_progress = ANTFS_CMD_UPLOAD_REQUEST_ID;
-
- // Reset maximum index.
- m_max_transfer_index.data = 0;
-
- return true;
-#else
- return false;
-#endif // ANTFS_INCLUDE_UPLOAD
-}
-
-
-void antfs_erase_req_resp_transmit(uint8_t response)
-{
- // This function should only be called after receiving an erase request.
- APP_ERROR_CHECK_BOOL((m_current_state.state == ANTFS_STATE_TRANS) &&
- (m_link_command_in_progress == ANTFS_CMD_ERASE_ID));
-
- beacon_transmit(MESG_BURST_DATA_ID);
-
- uint8_t tx_buffer[BURST_PACKET_SIZE];
-
- // Erase response.
- tx_buffer[0] = ANTFS_COMMAND_ID;
- tx_buffer[1] = ANTFS_RSP_ERASE_ID;
- tx_buffer[2] = response;
- tx_buffer[3] = 0;
- tx_buffer[4] = 0;
- tx_buffer[5] = 0;
- tx_buffer[6] = 0;
- tx_buffer[7] = 0;
-
- uint32_t err_code = sd_ant_burst_handler_request(ANTFS_CHANNEL,
- sizeof(tx_buffer),
- tx_buffer,
- BURST_SEGMENT_END);
- APP_ERROR_CHECK(err_code);
-
- wait_burst_request_to_complete();
-}
-
-
-bool antfs_event_extract(antfs_event_return_t * const p_event)
-{
- bool return_value = false;
-
- if (m_event_queue.head != m_event_queue.tail)
- {
- // Pending events exist. Copy event parameters into return event.
- p_event->event = m_event_queue.p_queue[m_event_queue.tail].event;
- p_event->file_index = m_event_queue.p_queue[m_event_queue.tail].file_index;
- p_event->offset = m_event_queue.p_queue[m_event_queue.tail].offset;
- p_event->bytes = m_event_queue.p_queue[m_event_queue.tail].bytes;
- p_event->crc = m_event_queue.p_queue[m_event_queue.tail].crc;
- memcpy(p_event->data,
- m_event_queue.p_queue[m_event_queue.tail].data,
- sizeof(p_event->data));
-
- // Release the event queue.
- m_event_queue.tail = ((m_event_queue.tail + 1u) & (ANTFS_EVENT_QUEUE_SIZE - 1u));
-
- return_value = true;
- }
-
- return return_value;
-}
-
-
-/**@brief Function for setting the channel period.
- *
- * Sets the channel period. The only allowed frequencies are 0.5, 1, 2, 4 and 8 Hz.
- *
- * @param[in] link_period Link period for the beacon transmission.
- */
-static void channel_period_set(uint32_t link_period)
-{
- uint32_t period;
-
- switch (link_period)
- {
- default:
- // Shouldn't happen, but just in case default to 0,5Hz.
- case BEACON_PERIOD_0_5_HZ:
- period = 65535u;
- break;
-
- case BEACON_PERIOD_1_HZ:
- period = 32768u;
- break;
-
- case BEACON_PERIOD_2_HZ:
- period = 16384u;
- break;
-
- case BEACON_PERIOD_4_HZ:
- period = 8192u;
- break;
-
- case BEACON_PERIOD_8_HZ:
- period = 4096u;
- break;
- }
-
- const uint32_t err_code = sd_ant_channel_period_set(ANTFS_CHANNEL, period);
- APP_ERROR_CHECK(err_code);
-}
-
-
-/**@brief Function for starting ANT-FS timeout.
- *
- * @param[in] timeout_in_secs Timeout requested in unit of seconds.
- */
-static void timeout_start(uint32_t timeout_in_secs)
-{
- uint32_t err_code = app_timer_stop(m_timer_id);
- APP_ERROR_CHECK(err_code);
-
- err_code = app_timer_start(m_timer_id,
- APP_TIMER_TICKS((uint32_t)(timeout_in_secs * 1000u),
- APP_TIMER_PRESCALER),
- NULL);
- APP_ERROR_CHECK(err_code);
-}
-
-
-/**@brief Function for switching to authentication layer.
- */
-static void authenticate_layer_transit(void)
-{
- if (m_current_state.state != ANTFS_STATE_OFF)
- {
- m_current_state.state = ANTFS_STATE_AUTH;
- m_current_state.sub_state.auth_sub_state = ANTFS_AUTH_SUBSTATE_NONE;
- m_link_command_in_progress = ANTFS_CMD_NONE;
-
- timeout_start(ANTFS_LINK_COMMAND_TIMEOUT);
-
- uint32_t err_code = sd_ant_channel_radio_freq_set(ANTFS_CHANNEL, m_active_beacon_frequency);
- APP_ERROR_CHECK(err_code);
-
- event_queue_write(ANTFS_EVENT_AUTH);
- }
-}
-
-
-/**@brief Function for decoding an ANT-FS command received at the link layer.
- *
- * @param[in] p_command_buffer The ANT-FS command buffer.
- */
-static void link_layer_cmd_decode(const uint8_t * p_command_buffer)
-{
- if (p_command_buffer[ANTFS_CONNECTION_TYPE_OFFSET] != ANTFS_COMMAND_ID)
- {
- return;
- }
-
- switch (p_command_buffer[ANTFS_COMMAND_OFFSET])
- {
- case ANTFS_CMD_LINK_ID:
- // Channel frequency.
- m_active_beacon_frequency =
- p_command_buffer[TRANSPORT_CHANNEL_FREQUENCY_OFFSET];
- // Channel message period.
- m_active_beacon_status1_field.parameters.link_period =
- p_command_buffer[TRANSPORT_MESSAGE_PERIOD_OFFSET];
- // Host serial Number.
- m_link_host_serial_number.bytes.byte0 =
- p_command_buffer[HOST_ID_OFFSET_0];
- m_link_host_serial_number.bytes.byte1 =
- p_command_buffer[HOST_ID_OFFSET_1];
- m_link_host_serial_number.bytes.byte2 =
- p_command_buffer[HOST_ID_OFFSET_2];
- m_link_host_serial_number.bytes.byte3 =
- p_command_buffer[HOST_ID_OFFSET_3];
-
- // Move to the channel period issued by the host.
- channel_period_set(m_active_beacon_status1_field.parameters.link_period);
-
- authenticate_layer_transit();
- break;
-
- default:
- break;
- }
-}
-
-
-/**@brief Function for switching to link layer.
- */
-static void link_layer_transit(void)
-{
- if (m_current_state.state != ANTFS_STATE_OFF)
- {
- uint32_t err_code;
-#ifdef LEDDRIVER_ACTIVE
- err_code = bsp_indication_set(BSP_INDICATE_IDLE);
- APP_ERROR_CHECK(err_code);
-#endif // LEDDRIVER_ACTIVE
-
- m_current_state.state = ANTFS_STATE_LINK;
- m_current_state.sub_state.link_sub_state = ANTFS_LINK_SUBSTATE_NONE;
- m_link_command_in_progress = ANTFS_CMD_NONE;
- m_active_beacon_status1_field = m_initial_parameters.beacon_status_byte1;
- m_active_beacon_frequency = m_initial_parameters.beacon_frequency;
-
- timeout_disable();
-
- err_code = sd_ant_channel_radio_freq_set(ANTFS_CHANNEL, m_active_beacon_frequency);
- APP_ERROR_CHECK(err_code);
-
- event_queue_write(ANTFS_EVENT_LINK);
- }
-}
-
-
-/**@brief Function for decoding an ANT-FS command received at the authenticate layer.
- *
- * @param[in] control_byte The command control byte.
- * @param[in] p_command_buffer The ANT-FS command buffer.
- */
-static void authenticate_layer_cmd_decode(uint8_t control_byte,
- const uint8_t * p_command_buffer)
-{
- // @note: Response variable must have a static storage allocation as it keeps track of the
- // passkey authentication progress between multiple burst packets.
-#if defined (ANTFS_AUTH_TYPE_PASSKEY)
- static uint32_t response;
-#endif // ANTFS_AUTH_TYPE_PASSKEY
-
- if((control_byte & ~SEQUENCE_LAST_MESSAGE) == 0 && m_link_command_in_progress != ANTFS_CMD_NONE)
- {
- // This is something new, and we're busy processing something already, so don't respond
- return;
- }
-
- if (p_command_buffer[ANTFS_CONNECTION_TYPE_OFFSET] == ANTFS_COMMAND_ID &&
- m_link_command_in_progress == ANTFS_CMD_NONE)
- {
- if (p_command_buffer[ANTFS_COMMAND_OFFSET] == ANTFS_CMD_AUTHENTICATE_ID)
- {
- // Make sure it is the correct host
- if(m_link_host_serial_number.bytes.byte0 != p_command_buffer[HOST_ID_OFFSET_0] ||
- m_link_host_serial_number.bytes.byte1 != p_command_buffer[HOST_ID_OFFSET_1] ||
- m_link_host_serial_number.bytes.byte2 != p_command_buffer[HOST_ID_OFFSET_2] ||
- m_link_host_serial_number.bytes.byte3 != p_command_buffer[HOST_ID_OFFSET_3])
- return;
-
- m_link_command_in_progress = ANTFS_CMD_AUTHENTICATE_ID;
- m_authenticate_command_type = p_command_buffer[COMMAND_TYPE_OFFSET];
- m_retry = AUTHENTICATION_RETRIES;
- }
- }
-
- if (m_link_command_in_progress == ANTFS_CMD_AUTHENTICATE_ID)
- {
- switch (m_authenticate_command_type)
- {
- case COMMAND_TYPE_REQUEST_SERIAL:
- if (control_byte & SEQUENCE_LAST_MESSAGE)
- {
- // Don't do anything before the burst completes (last burst message received).
- timeout_start(ANTFS_LINK_COMMAND_TIMEOUT);
- authenticate_response_transmit(AUTH_RESPONSE_N_A,
- ANTFS_REMOTE_FRIENDLY_NAME_MAX,
- // Send device friendly name if it exists.
- m_initial_parameters.p_remote_friendly_name);
- }
- break;
-
-#if defined (ANTFS_AUTH_TYPE_PASSTHROUGH)
- case COMMAND_TYPE_PROCEED:
- if (control_byte & SEQUENCE_LAST_MESSAGE)
- {
- // Don't do anything before the burst completes (last burst message received).
- timeout_start(ANTFS_LINK_COMMAND_TIMEOUT);
- // Proceed directly to transport layer (no authentication required).
- authenticate_response_transmit(AUTH_RESPONSE_ACCEPT, 0, NULL);
- }
- break;
-
-#endif // ANTFS_AUTH_TYPE_PASSTHROUGH
-#if defined (ANTFS_AUTH_TYPE_PAIRING)
- case COMMAND_TYPE_REQUEST_PAIR:
- if ((control_byte & SEQUENCE_NUMBER_ROLLOVER) == 0)
- {
- // First burst packet.
-
- // Friendly name length.
- m_friendly_name.friendly_name_size =
- p_command_buffer[AUTH_STRING_LENGTH_OFFSET];
-
- if (m_friendly_name.friendly_name_size > 0)
- {
- if (m_friendly_name.friendly_name_size > ANTFS_FRIENDLY_NAME_MAX)
- {
- m_friendly_name.friendly_name_size = ANTFS_FRIENDLY_NAME_MAX;
- }
-
- m_friendly_name.index = 0;
- }
- }
- else
- {
- // Next burst packets: read host friendly name.
-
- if (m_friendly_name.index < ANTFS_FRIENDLY_NAME_MAX)
- {
- uint32_t num_of_bytes = ANTFS_FRIENDLY_NAME_MAX - m_friendly_name.index;
- if (num_of_bytes > 8u)
- {
- num_of_bytes = 8u;
- }
- memcpy((uint8_t*)&m_friendly_name.friendly_name[m_friendly_name.index],
- p_command_buffer,
- num_of_bytes);
- m_friendly_name.index += num_of_bytes;
- }
- }
-
- if (control_byte & SEQUENCE_LAST_MESSAGE)
- {
- // Last burst packet.
-
- timeout_start(ANTFS_PAIRING_TIMEOUT);
- if (m_friendly_name.friendly_name_size > 0)
- {
- m_friendly_name.is_name_set = true;
- }
-
- m_current_state.sub_state.auth_sub_state = ANTFS_AUTH_SUBSTATE_PAIR;
- // If pairing is supported, send request to UI.
- event_queue_write(ANTFS_EVENT_PAIRING_REQUEST);
- }
- break;
-
-#endif // ANTFS_AUTH_TYPE_PAIRING
-#if defined (ANTFS_AUTH_TYPE_PASSKEY)
- case COMMAND_TYPE_REQUEST_PASSKEY:
- if ((control_byte & SEQUENCE_NUMBER_ROLLOVER) == 0)
- {
- // First burst packet.
-
- // Passkey length.
- const uint32_t passkey_size = p_command_buffer[AUTH_STRING_LENGTH_OFFSET];
-
- // Default the algorithm to accept.
- response = AUTH_RESPONSE_ACCEPT;
-
- // Check if the passkey length is valid.
- if (passkey_size == ANTFS_PASSKEY_SIZE)
- {
- m_passkey_index = 0;
- }
- else
- {
- // Invalid lenght supplied - the authentication will be rejected.
- response = AUTH_RESPONSE_REJECT;
- }
- }
- else
- {
- // Next burst packets: read host friendly name.
-
- if ((response == AUTH_RESPONSE_ACCEPT) &&
- // Prevent buffer overrun.
- (m_passkey_index != ANTFS_PASSKEY_SIZE))
- {
- // Passkey length was valid and the host supplied key matches so far.
- uint32_t idx = 0;
-
- // Check the current received burst packet for passkey match.
- do
- {
- if (m_initial_parameters.p_pass_key[m_passkey_index++] !=
- p_command_buffer[idx])
- {
- // Reject the authentication request and further processing of
- // passkey matching if a mismatch is found.
- response = AUTH_RESPONSE_REJECT;
- break;
- }
-
- ++idx;
- }
- while (idx < BURST_PACKET_SIZE);
- }
- }
-
- if (control_byte & SEQUENCE_LAST_MESSAGE)
- {
- // Last burst packet.
-
- if (m_passkey_index < ANTFS_PASSKEY_SIZE)
- {
- // We did not get the complete passkey, reject authentication request.
- response = AUTH_RESPONSE_REJECT;
- }
-
- timeout_start(ANTFS_LINK_COMMAND_TIMEOUT);
- m_current_state.sub_state.auth_sub_state = ANTFS_AUTH_SUBSTATE_PASSKEY;
- authenticate_response_transmit(response, 0, NULL);
- }
- break;
-
-#endif // ANTFS_AUTH_TYPE_PASSKEY
- default:
- break;
- }
- }
- else if (p_command_buffer[ANTFS_COMMAND_OFFSET] == ANTFS_CMD_DISCONNECT_ID)
- {
- if (control_byte & SEQUENCE_LAST_MESSAGE)
- {
- // Don't do anything before the burst completes (last burst message received).
- link_layer_transit();
- }
- }
- else if (p_command_buffer[ANTFS_COMMAND_OFFSET] == ANTFS_CMD_PING_ID)
- {
- // Reset timeout.
- timeout_start(ANTFS_LINK_COMMAND_TIMEOUT);
- m_link_command_in_progress = ANTFS_CMD_NONE;
- }
- else
- {
- // No implementation needed.
- }
-}
-
-
-/**@brief Function for decoding an ANT-FS command received at the transport layer.
- *
- * @param[in] control_byte The command control byte.
- * @param[in] p_command_buffer The ANT-FS command buffer.
- */
-static void transport_layer_cmd_decode(uint8_t control_byte, const uint8_t * p_command_buffer)
-{
- ulong_union_t host_serial_number = {0};
-
- if (p_command_buffer[ANTFS_CONNECTION_TYPE_OFFSET] == ANTFS_COMMAND_ID)
- {
- m_link_command_in_progress = p_command_buffer[ANTFS_COMMAND_OFFSET];
- }
-
- switch (m_link_command_in_progress)
- {
- case ANTFS_CMD_PING_ID:
- // Reset timeout.
- timeout_start(ANTFS_LINK_COMMAND_TIMEOUT);
- m_link_command_in_progress = ANTFS_CMD_NONE;
- break;
-
- case ANTFS_CMD_DISCONNECT_ID:
- if(control_byte & SEQUENCE_LAST_MESSAGE)
- {
- // Don't do anything before the burst completes (last burst message received).
- link_layer_transit();
- }
- break;
-
- case ANTFS_CMD_ERASE_ID:
- if(control_byte & SEQUENCE_LAST_MESSAGE)
- {
- // Don't do anything before the burst completes (last burst message received).
-
- // Requested index.
- m_file_index.bytes.low = p_command_buffer[DATA_INDEX_OFFSET_LOW];
- m_file_index.bytes.high = p_command_buffer[DATA_INDEX_OFFSET_HIGH];
-
- // Send erase request to the application.
- event_queue_write(ANTFS_EVENT_ERASE_REQUEST);
- timeout_start(ANTFS_LINK_COMMAND_TIMEOUT);
- m_link_command_in_progress = ANTFS_CMD_ERASE_ID;
- }
- break;
-
- case ANTFS_CMD_DOWNLOAD_ID:
- if (m_current_state.sub_state.trans_sub_state != ANTFS_TRANS_SUBSTATE_NONE)
- {
- // Ignore the command if we are busy.
- break;
- }
-
- if ((control_byte & ~SEQUENCE_LAST_MESSAGE) == 0x00)
- {
- // First burst packet.
-
- if ((m_file_index.bytes.low != p_command_buffer[DATA_INDEX_OFFSET_LOW]) ||
- (m_file_index.bytes.high != p_command_buffer[DATA_INDEX_OFFSET_HIGH]))
- {
- // This is a new index, so we can not check the CRC against the previous saved
- // CRC.
-
- // CRC seed checking is made invalid by setting the last saved offset to the
- // maximum file size.
- m_saved_crc_offset = ANTFS_MAX_FILE_SIZE;
- }
-
- // Requested data file index.
- m_file_index.bytes.low = p_command_buffer[DATA_INDEX_OFFSET_LOW];
- m_file_index.bytes.high = p_command_buffer[DATA_INDEX_OFFSET_HIGH];
-
- // Initialize current position in the TX burst to the requested offset.
- m_link_burst_index.bytes.byte0 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_0];
- m_link_burst_index.bytes.byte1 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_1];
- m_link_burst_index.bytes.byte2 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_2];
- m_link_burst_index.bytes.byte3 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_3];
- }
- else if (control_byte & SEQUENCE_LAST_MESSAGE)
- {
- // Last burst packet (download command should be two packets long).
-
- // Get CRC seed from host.
- m_compared_crc = (uint16_t)p_command_buffer[DATA_INDEX_OFFSET_LOW];
- m_compared_crc |= ((uint16_t)p_command_buffer[DATA_INDEX_OFFSET_HIGH] << 8u);
-
- // Maximum block size allowed by host.
- m_max_block_size.bytes.byte0 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_0];
- m_max_block_size.bytes.byte1 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_1];
- m_max_block_size.bytes.byte2 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_2];
- m_max_block_size.bytes.byte3 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_3];
-
- // Initialize number of remaining bytes for this block to the maximum block size.
- m_bytes_remaining.data = m_max_block_size.data;
-
- if (p_command_buffer[INITIAL_REQUEST_OFFSET])
- {
- // This request is the start of a new transfer.
-
- // Initialize data offset for CRC calculation to the requested data offset.
- m_saved_crc_offset = m_link_burst_index.data;
- m_saved_buffer_crc_offset = m_link_burst_index.data;
-
- // Use CRC seed provided by host for CRC checking of the data.
- m_transfer_crc = m_compared_crc;
- m_saved_transfer_crc = m_compared_crc;
- m_saved_buffer_crc = m_compared_crc;
- m_current_state.sub_state.trans_sub_state = ANTFS_TRANS_SUBSTATE_VERIFY_CRC;
- }
- else
- {
- // This is a request to resume a partially completed transfer.
-
- if (m_saved_crc_offset > m_link_burst_index.data)
- {
- // We can not check the received CRC seed as the requested offset is before
- // our last save point.
-
- // Set CRC checking as invalid.
- m_saved_crc_offset = ANTFS_MAX_FILE_SIZE;
- }
- else
- {
- m_current_state.sub_state.trans_sub_state = ANTFS_TRANS_SUBSTATE_VERIFY_CRC;
- }
- }
-
- m_is_data_request_pending = false;
-
- // Send download request to the application for further handling.
- event_queue_write(ANTFS_EVENT_DOWNLOAD_REQUEST);
-
- timeout_start(ANTFS_LINK_COMMAND_TIMEOUT);
- m_link_command_in_progress = ANTFS_CMD_DOWNLOAD_ID;
- }
- break;
-
- case ANTFS_CMD_UPLOAD_REQUEST_ID:
-#if defined(ANTFS_INCLUDE_UPLOAD)
- if ((control_byte & ~SEQUENCE_LAST_MESSAGE) == 0x00)
- {
- // First burst packet.
-
- if ((m_file_index.bytes.low != p_command_buffer[DATA_INDEX_OFFSET_LOW]) ||
- (
- (m_file_index.bytes.high != p_command_buffer[DATA_INDEX_OFFSET_HIGH]) ||
- (m_current_state.sub_state.trans_sub_state == ANTFS_TRANS_SUBSTATE_NONE)
- )
- )
- {
- // If it is a new index or we completed the last upload.
-
- // Get the file index.
- m_file_index.bytes.low = p_command_buffer[DATA_INDEX_OFFSET_LOW];
- m_file_index.bytes.high = p_command_buffer[DATA_INDEX_OFFSET_HIGH];
-
- // As this is a new upload, reset save point to the beginning of the file.
-
- // Set CRC to zero.
- m_saved_crc_offset = 0;
- m_saved_transfer_crc = 0;
- }
-
- // Get the upper limit of upload from request message.
- m_max_transfer_index.bytes.byte0 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_0];
- m_max_transfer_index.bytes.byte1 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_1];
- m_max_transfer_index.bytes.byte2 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_2];
- m_max_transfer_index.bytes.byte3 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_3];
- }
- else if (control_byte & SEQUENCE_LAST_MESSAGE)
- {
- // Last burst (second) packet.
-
- // Get data offset the requested upload will start at.
- m_link_burst_index.bytes.byte0 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_0];
- m_link_burst_index.bytes.byte1 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_1];
- m_link_burst_index.bytes.byte2 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_2];
- m_link_burst_index.bytes.byte3 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_3];
-
- if (m_link_burst_index.data != ANTFS_MAX_FILE_SIZE)
- {
- // If this is a new upload.
-
- // The data offset specified in the upload request will be used.
- m_saved_crc_offset = m_link_burst_index.data;
-
- m_saved_transfer_crc = 0;
- }
-
- m_transfer_crc = m_saved_transfer_crc;
-
- // Send upload request to the application for further handling.
- event_queue_write(ANTFS_EVENT_UPLOAD_REQUEST);
-
- timeout_start(ANTFS_LINK_COMMAND_TIMEOUT);
- m_link_command_in_progress = ANTFS_CMD_UPLOAD_REQUEST_ID;
- }
-#endif // ANTFS_INCLUDE_UPLOAD
- break;
-
- case ANTFS_CMD_UPLOAD_DATA_ID:
-#if defined(ANTFS_INCLUDE_UPLOAD)
- if ((control_byte & ~SEQUENCE_LAST_MESSAGE) == 0x00)
- {
- // First burst packet.
-
- if (m_current_state.sub_state.trans_sub_state ==
- ANTFS_TRANS_SUBSTATE_UPLOAD_WAIT_FOR_DATA)
- {
- antfs_event_t event;
-
- // Get CRC Seed from host.
- m_compared_crc = (uint16_t)p_command_buffer[DATA_INDEX_OFFSET_LOW];
- m_compared_crc |= ((uint16_t)p_command_buffer[DATA_INDEX_OFFSET_HIGH] << 8u);
-
- // Set download offset.
- m_link_burst_index.bytes.byte0 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_0];
- m_link_burst_index.bytes.byte1 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_1];
- m_link_burst_index.bytes.byte2 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_2];
- m_link_burst_index.bytes.byte3 = p_command_buffer[ADDRESS_PARAMETER_OFFSET_3];
-
- if ((m_link_burst_index.data + m_block_size.data) < m_max_transfer_index.data)
- {
- // Adjust block size as set by client.
- m_max_transfer_index.data = m_link_burst_index.data + m_block_size.data;
- }
-
- if (m_compared_crc != m_transfer_crc)
- {
- // Check that the request matches the CRC sent on the upload response.
-
- // Do not accept any data.
- m_max_transfer_index.data = 0;
-
- // Failure will be reported when upload is done.
- event = (antfs_event_t)0;
- }
-
- // Set ready to receive a file.
- m_current_state.sub_state.trans_sub_state = ANTFS_TRANS_SUBSTATE_UPLOADING;
-
- event = ANTFS_EVENT_UPLOAD_START;
- m_transfer_crc = m_compared_crc;
-
- if (m_link_burst_index.data > m_max_transfer_index.data)
- {
- // If the requested offset is too high.
-
- // Clear the max transfer index, so we'll report fail when the transfer
- // finishes.
- m_max_transfer_index.data = 0;
- // Clear the event because we normally would not send an event at this point
- // in this case.
- event = (antfs_event_t)0;
- }
-
- if (control_byte & SEQUENCE_LAST_MESSAGE)
- {
- // If this upload contains no data.
-
- // Leave the upload state.
- m_current_state.sub_state.trans_sub_state = ANTFS_TRANS_SUBSTATE_NONE;
-
- // if it was a valid index, report it as a successful upload, otherwise
- // report it as a failure.
- if (event == 0)
- {
- event = ANTFS_EVENT_UPLOAD_FAIL;
- }
- else
- {
- event = ANTFS_EVENT_UPLOAD_COMPLETE;
- }
- }
-
- if (event != 0)
- {
- event_queue_write(event);
- }
- }
- }
-#endif // ANTFS_INCLUDE_UPLOAD
- break;
-
- case ANTFS_CMD_LINK_ID:
- host_serial_number.bytes.byte0 = p_command_buffer[HOST_ID_OFFSET_0];
- host_serial_number.bytes.byte1 = p_command_buffer[HOST_ID_OFFSET_1];
- host_serial_number.bytes.byte2 = p_command_buffer[HOST_ID_OFFSET_2];
- host_serial_number.bytes.byte3 = p_command_buffer[HOST_ID_OFFSET_3];
-
- if (m_link_host_serial_number.data == host_serial_number.data)
- {
- m_active_beacon_frequency = p_command_buffer[TRANSPORT_CHANNEL_FREQUENCY_OFFSET];
- m_active_beacon_status1_field.parameters.link_period =
- p_command_buffer[TRANSPORT_MESSAGE_PERIOD_OFFSET];
-
- const uint32_t err_code = sd_ant_channel_radio_freq_set(ANTFS_CHANNEL,
- m_active_beacon_frequency);
- APP_ERROR_CHECK(err_code);
-
- channel_period_set(m_active_beacon_status1_field.parameters.link_period);
- }
-
- m_link_command_in_progress = 0;
- break;
-
- default:
- // Don't do anything, this is an invalid message.
- m_link_command_in_progress = 0;
- break;
- }
-}
-
-
-/**@brief Function for handling data upload.
- *
- * @param[in] control_byte The command control byte.
- * @param[in] p_buffer The data buffer.
- */
-static void upload_data_process(uint8_t control_byte, const uint8_t * p_buffer)
-{
-#if defined(ANTFS_INCLUDE_UPLOAD)
- if (control_byte & SEQUENCE_LAST_MESSAGE)
- {
- // Last burst packet: upload complete.
-
- m_current_state.sub_state.trans_sub_state = ANTFS_TRANS_SUBSTATE_NONE;
-
- // CRC for data packets contained in this upload block.
- m_compared_crc = p_buffer[UPLOAD_CRC_OFFSET_LOW ];
- m_compared_crc |= (p_buffer[UPLOAD_CRC_OFFSET_HIGH] << 8u);
-
- if (m_max_transfer_index.data && (m_compared_crc == m_transfer_crc))
- {
- // CRC OK, upload was completed successfully.
- event_queue_write(ANTFS_EVENT_UPLOAD_COMPLETE);
- }
- else
- {
- // CRC mismatch, upload failed.
- event_queue_write(ANTFS_EVENT_UPLOAD_FAIL);
- }
-
- m_max_transfer_index.data = 0;
- }
- else
- {
- // Not the last burst packet: upload not complete.
-
- // Set initial number of bytes to 8 (size of burst packet).
- m_bytes_to_write = BURST_PACKET_SIZE;
- timeout_start(ANTFS_LINK_COMMAND_TIMEOUT);
-
- if (m_link_burst_index.data > m_max_transfer_index.data)
- {
- // We are past the main index, we do not need to write any more data.
- m_bytes_to_write = 0;
- }
- else
- {
- if ((m_bytes_to_write + m_link_burst_index.data) > m_max_transfer_index.data)
- {
- // if we're less than 8 bytes away from the end, adjust the number of bytes to write
- // in this block.
- m_bytes_to_write = m_max_transfer_index.data - m_link_burst_index.data;
- }
- }
-
- if (m_bytes_to_write != 0)
- {
- APP_ERROR_CHECK_BOOL(m_bytes_to_write <= BURST_PACKET_SIZE);
-
- // Store begin of upload data.
- mp_upload_data = p_buffer;
-
- m_transfer_crc = crc_crc16_update(m_transfer_crc, p_buffer, m_bytes_to_write);
-
- // Send data to application.
- event_queue_write(ANTFS_EVENT_UPLOAD_DATA);
-
- // Update current offset.
- m_link_burst_index.data += m_bytes_to_write;
-
- // Store save point.
- m_saved_crc_offset = m_link_burst_index.data;
- m_saved_transfer_crc = m_transfer_crc;
- }
- }
-#endif // ANTFS_INCLUDE_UPLOAD
-}
-
-
-/**@brief Function for switching to transport layer.
- */
-static void transport_layer_transit(void)
-{
- if (m_current_state.state != ANTFS_STATE_OFF)
- {
-#ifdef LEDDRIVER_ACTIVE
- uint32_t err_code = bsp_indication_set(BSP_INDICATE_IDLE);
- APP_ERROR_CHECK(err_code);
-#endif // LEDDRIVER_ACTIVE
- m_current_state.state = ANTFS_STATE_TRANS;
- m_current_state.sub_state.trans_sub_state = ANTFS_TRANS_SUBSTATE_NONE;
-
- timeout_start(ANTFS_LINK_COMMAND_TIMEOUT);
-
- beacon_transmit(MESG_BROADCAST_DATA_ID);
-
- event_queue_write(ANTFS_EVENT_TRANS);
- }
-}
-
-
-void antfs_message_process(uint8_t * p_message)
-{
-#ifdef LEDDRIVER_ACTIVE
- uint32_t err_code;
-#endif
-
- if (p_message != NULL)
- {
- if ((p_message[BUFFER_INDEX_CHANNEL_NUM] & CHANNEL_NUMBER_MASK) != ANTFS_CHANNEL)
- {
- // Only process messages corresponding to the ANT-FS channel here.
- return;
- }
-
- if ((m_current_state.state == ANTFS_STATE_OFF) &&
- (
- !(
- (p_message[BUFFER_INDEX_MESG_ID] == MESG_RESPONSE_EVENT_ID) &&
- (p_message[BUFFER_INDEX_RESPONSE_CODE] == NO_EVENT)
- )
- )
- )
- {
- return;
- }
-
- switch (p_message[BUFFER_INDEX_MESG_ID])
- {
- case MESG_BROADCAST_DATA_ID:
- // We are not going to process broadcast messages or pass them to the app to handle.
- break;
-
- case MESG_ACKNOWLEDGED_DATA_ID:
- // Mark it as being the last message if it's an ack message.
- p_message[ANTFS_CONTROL_OFFSET] |= SEQUENCE_LAST_MESSAGE;
-
- /* fall-through */
- case MESG_BURST_DATA_ID:
- switch (m_current_state.state)
- {
- case ANTFS_STATE_LINK:
- link_layer_cmd_decode(&p_message[ANTFS_DATA_OFFSET]);
- break;
-
- case ANTFS_STATE_AUTH:
- authenticate_layer_cmd_decode(p_message[ANTFS_CONTROL_OFFSET],
- &p_message[ANTFS_DATA_OFFSET]);
- break;
-
- case ANTFS_STATE_TRANS:
- if (m_current_state.sub_state.trans_sub_state !=
- ANTFS_TRANS_SUBSTATE_UPLOADING)
- {
- transport_layer_cmd_decode(p_message[ANTFS_CONTROL_OFFSET],
- &p_message[ANTFS_DATA_OFFSET]);
- }
- else
- {
- upload_d
<TRUNCATED>