mirror of
https://github.com/espressif/openthread.git
synced 2026-08-10 20:57:47 +00:00
[third-party] change end of line character from CRLF do LF (#4250)
Also remove .gitattibutes from third-party
This commit is contained in:
committed by
Jonathan Hui
parent
c4e7156f41
commit
4871f12645
@@ -1,4 +0,0 @@
|
||||
# Disable automatic text file line-ending
|
||||
# normalization for third-party code.
|
||||
* !text
|
||||
|
||||
+7030
-7030
File diff suppressed because it is too large
Load Diff
+734
-734
File diff suppressed because it is too large
Load Diff
+1800
-1800
File diff suppressed because it is too large
Load Diff
+1373
-1373
File diff suppressed because it is too large
Load Diff
+1937
-1937
File diff suppressed because it is too large
Load Diff
+86
-86
@@ -1,86 +1,86 @@
|
||||
/**************************************************************************//**
|
||||
* @file core_cmFunc.h
|
||||
* @brief CMSIS Cortex-M Core Function Access Header File
|
||||
* @version V4.30
|
||||
* @date 20. October 2015
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
- Neither the name of ARM nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
*
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#pragma system_include /* treat file as system include file for MISRA check */
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#pragma clang system_header /* treat file as system include file */
|
||||
#endif
|
||||
|
||||
#ifndef __CORE_CMFUNC_H
|
||||
#define __CORE_CMFUNC_H
|
||||
|
||||
|
||||
/* ########################### Core Function Access ########################### */
|
||||
/** \ingroup CMSIS_Core_FunctionInterface
|
||||
\defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
|
||||
@{
|
||||
*/
|
||||
|
||||
/*------------------ RealView Compiler -----------------*/
|
||||
#if defined ( __CC_ARM )
|
||||
#include "cmsis_armcc.h"
|
||||
|
||||
/*------------------ ARM Compiler V6 -------------------*/
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#include "cmsis_armcc_V6.h"
|
||||
|
||||
/*------------------ GNU Compiler ----------------------*/
|
||||
#elif defined ( __GNUC__ )
|
||||
#include "cmsis_gcc.h"
|
||||
|
||||
/*------------------ ICC Compiler ----------------------*/
|
||||
#elif defined ( __ICCARM__ )
|
||||
#include <cmsis_iar.h>
|
||||
|
||||
/*------------------ TI CCS Compiler -------------------*/
|
||||
#elif defined ( __TMS470__ )
|
||||
#include <cmsis_ccs.h>
|
||||
|
||||
/*------------------ TASKING Compiler ------------------*/
|
||||
#elif defined ( __TASKING__ )
|
||||
/*
|
||||
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
||||
* Please use "carm -?i" to get an up to date list of all intrinsics,
|
||||
* Including the CMSIS ones.
|
||||
*/
|
||||
|
||||
/*------------------ COSMIC Compiler -------------------*/
|
||||
#elif defined ( __CSMC__ )
|
||||
#include <cmsis_csm.h>
|
||||
|
||||
#endif
|
||||
|
||||
/*@} end of CMSIS_Core_RegAccFunctions */
|
||||
|
||||
#endif /* __CORE_CMFUNC_H */
|
||||
/**************************************************************************//**
|
||||
* @file core_cmFunc.h
|
||||
* @brief CMSIS Cortex-M Core Function Access Header File
|
||||
* @version V4.30
|
||||
* @date 20. October 2015
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
- Neither the name of ARM nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
*
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#pragma system_include /* treat file as system include file for MISRA check */
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#pragma clang system_header /* treat file as system include file */
|
||||
#endif
|
||||
|
||||
#ifndef __CORE_CMFUNC_H
|
||||
#define __CORE_CMFUNC_H
|
||||
|
||||
|
||||
/* ########################### Core Function Access ########################### */
|
||||
/** \ingroup CMSIS_Core_FunctionInterface
|
||||
\defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
|
||||
@{
|
||||
*/
|
||||
|
||||
/*------------------ RealView Compiler -----------------*/
|
||||
#if defined ( __CC_ARM )
|
||||
#include "cmsis_armcc.h"
|
||||
|
||||
/*------------------ ARM Compiler V6 -------------------*/
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#include "cmsis_armcc_V6.h"
|
||||
|
||||
/*------------------ GNU Compiler ----------------------*/
|
||||
#elif defined ( __GNUC__ )
|
||||
#include "cmsis_gcc.h"
|
||||
|
||||
/*------------------ ICC Compiler ----------------------*/
|
||||
#elif defined ( __ICCARM__ )
|
||||
#include <cmsis_iar.h>
|
||||
|
||||
/*------------------ TI CCS Compiler -------------------*/
|
||||
#elif defined ( __TMS470__ )
|
||||
#include <cmsis_ccs.h>
|
||||
|
||||
/*------------------ TASKING Compiler ------------------*/
|
||||
#elif defined ( __TASKING__ )
|
||||
/*
|
||||
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
||||
* Please use "carm -?i" to get an up to date list of all intrinsics,
|
||||
* Including the CMSIS ones.
|
||||
*/
|
||||
|
||||
/*------------------ COSMIC Compiler -------------------*/
|
||||
#elif defined ( __CSMC__ )
|
||||
#include <cmsis_csm.h>
|
||||
|
||||
#endif
|
||||
|
||||
/*@} end of CMSIS_Core_RegAccFunctions */
|
||||
|
||||
#endif /* __CORE_CMFUNC_H */
|
||||
|
||||
+87
-87
@@ -1,87 +1,87 @@
|
||||
/**************************************************************************//**
|
||||
* @file core_cmInstr.h
|
||||
* @brief CMSIS Cortex-M Core Instruction Access Header File
|
||||
* @version V4.30
|
||||
* @date 20. October 2015
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
- Neither the name of ARM nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
*
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#pragma system_include /* treat file as system include file for MISRA check */
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#pragma clang system_header /* treat file as system include file */
|
||||
#endif
|
||||
|
||||
#ifndef __CORE_CMINSTR_H
|
||||
#define __CORE_CMINSTR_H
|
||||
|
||||
|
||||
/* ########################## Core Instruction Access ######################### */
|
||||
/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
|
||||
Access to dedicated instructions
|
||||
@{
|
||||
*/
|
||||
|
||||
/*------------------ RealView Compiler -----------------*/
|
||||
#if defined ( __CC_ARM )
|
||||
#include "cmsis_armcc.h"
|
||||
|
||||
/*------------------ ARM Compiler V6 -------------------*/
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#include "cmsis_armcc_V6.h"
|
||||
|
||||
/*------------------ GNU Compiler ----------------------*/
|
||||
#elif defined ( __GNUC__ )
|
||||
#include "cmsis_gcc.h"
|
||||
|
||||
/*------------------ ICC Compiler ----------------------*/
|
||||
#elif defined ( __ICCARM__ )
|
||||
#include <cmsis_iar.h>
|
||||
|
||||
/*------------------ TI CCS Compiler -------------------*/
|
||||
#elif defined ( __TMS470__ )
|
||||
#include <cmsis_ccs.h>
|
||||
|
||||
/*------------------ TASKING Compiler ------------------*/
|
||||
#elif defined ( __TASKING__ )
|
||||
/*
|
||||
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
||||
* Please use "carm -?i" to get an up to date list of all intrinsics,
|
||||
* Including the CMSIS ones.
|
||||
*/
|
||||
|
||||
/*------------------ COSMIC Compiler -------------------*/
|
||||
#elif defined ( __CSMC__ )
|
||||
#include <cmsis_csm.h>
|
||||
|
||||
#endif
|
||||
|
||||
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
|
||||
|
||||
#endif /* __CORE_CMINSTR_H */
|
||||
/**************************************************************************//**
|
||||
* @file core_cmInstr.h
|
||||
* @brief CMSIS Cortex-M Core Instruction Access Header File
|
||||
* @version V4.30
|
||||
* @date 20. October 2015
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
- Neither the name of ARM nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
*
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#pragma system_include /* treat file as system include file for MISRA check */
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#pragma clang system_header /* treat file as system include file */
|
||||
#endif
|
||||
|
||||
#ifndef __CORE_CMINSTR_H
|
||||
#define __CORE_CMINSTR_H
|
||||
|
||||
|
||||
/* ########################## Core Instruction Access ######################### */
|
||||
/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
|
||||
Access to dedicated instructions
|
||||
@{
|
||||
*/
|
||||
|
||||
/*------------------ RealView Compiler -----------------*/
|
||||
#if defined ( __CC_ARM )
|
||||
#include "cmsis_armcc.h"
|
||||
|
||||
/*------------------ ARM Compiler V6 -------------------*/
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#include "cmsis_armcc_V6.h"
|
||||
|
||||
/*------------------ GNU Compiler ----------------------*/
|
||||
#elif defined ( __GNUC__ )
|
||||
#include "cmsis_gcc.h"
|
||||
|
||||
/*------------------ ICC Compiler ----------------------*/
|
||||
#elif defined ( __ICCARM__ )
|
||||
#include <cmsis_iar.h>
|
||||
|
||||
/*------------------ TI CCS Compiler -------------------*/
|
||||
#elif defined ( __TMS470__ )
|
||||
#include <cmsis_ccs.h>
|
||||
|
||||
/*------------------ TASKING Compiler ------------------*/
|
||||
#elif defined ( __TASKING__ )
|
||||
/*
|
||||
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
||||
* Please use "carm -?i" to get an up to date list of all intrinsics,
|
||||
* Including the CMSIS ones.
|
||||
*/
|
||||
|
||||
/*------------------ COSMIC Compiler -------------------*/
|
||||
#elif defined ( __CSMC__ )
|
||||
#include <cmsis_csm.h>
|
||||
|
||||
#endif
|
||||
|
||||
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
|
||||
|
||||
#endif /* __CORE_CMINSTR_H */
|
||||
|
||||
+96
-96
@@ -1,96 +1,96 @@
|
||||
/**************************************************************************//**
|
||||
* @file core_cmSimd.h
|
||||
* @brief CMSIS Cortex-M SIMD Header File
|
||||
* @version V4.30
|
||||
* @date 20. October 2015
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
- Neither the name of ARM nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
*
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#pragma system_include /* treat file as system include file for MISRA check */
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#pragma clang system_header /* treat file as system include file */
|
||||
#endif
|
||||
|
||||
#ifndef __CORE_CMSIMD_H
|
||||
#define __CORE_CMSIMD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* ################### Compiler specific Intrinsics ########################### */
|
||||
/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
|
||||
Access to dedicated SIMD instructions
|
||||
@{
|
||||
*/
|
||||
|
||||
/*------------------ RealView Compiler -----------------*/
|
||||
#if defined ( __CC_ARM )
|
||||
#include "cmsis_armcc.h"
|
||||
|
||||
/*------------------ ARM Compiler V6 -------------------*/
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#include "cmsis_armcc_V6.h"
|
||||
|
||||
/*------------------ GNU Compiler ----------------------*/
|
||||
#elif defined ( __GNUC__ )
|
||||
#include "cmsis_gcc.h"
|
||||
|
||||
/*------------------ ICC Compiler ----------------------*/
|
||||
#elif defined ( __ICCARM__ )
|
||||
#include <cmsis_iar.h>
|
||||
|
||||
/*------------------ TI CCS Compiler -------------------*/
|
||||
#elif defined ( __TMS470__ )
|
||||
#include <cmsis_ccs.h>
|
||||
|
||||
/*------------------ TASKING Compiler ------------------*/
|
||||
#elif defined ( __TASKING__ )
|
||||
/*
|
||||
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
||||
* Please use "carm -?i" to get an up to date list of all intrinsics,
|
||||
* Including the CMSIS ones.
|
||||
*/
|
||||
|
||||
/*------------------ COSMIC Compiler -------------------*/
|
||||
#elif defined ( __CSMC__ )
|
||||
#include <cmsis_csm.h>
|
||||
|
||||
#endif
|
||||
|
||||
/*@} end of group CMSIS_SIMD_intrinsics */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CORE_CMSIMD_H */
|
||||
/**************************************************************************//**
|
||||
* @file core_cmSimd.h
|
||||
* @brief CMSIS Cortex-M SIMD Header File
|
||||
* @version V4.30
|
||||
* @date 20. October 2015
|
||||
******************************************************************************/
|
||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
||||
|
||||
All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
- Neither the name of ARM nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
*
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#pragma system_include /* treat file as system include file for MISRA check */
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#pragma clang system_header /* treat file as system include file */
|
||||
#endif
|
||||
|
||||
#ifndef __CORE_CMSIMD_H
|
||||
#define __CORE_CMSIMD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* ################### Compiler specific Intrinsics ########################### */
|
||||
/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
|
||||
Access to dedicated SIMD instructions
|
||||
@{
|
||||
*/
|
||||
|
||||
/*------------------ RealView Compiler -----------------*/
|
||||
#if defined ( __CC_ARM )
|
||||
#include "cmsis_armcc.h"
|
||||
|
||||
/*------------------ ARM Compiler V6 -------------------*/
|
||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#include "cmsis_armcc_V6.h"
|
||||
|
||||
/*------------------ GNU Compiler ----------------------*/
|
||||
#elif defined ( __GNUC__ )
|
||||
#include "cmsis_gcc.h"
|
||||
|
||||
/*------------------ ICC Compiler ----------------------*/
|
||||
#elif defined ( __ICCARM__ )
|
||||
#include <cmsis_iar.h>
|
||||
|
||||
/*------------------ TI CCS Compiler -------------------*/
|
||||
#elif defined ( __TMS470__ )
|
||||
#include <cmsis_ccs.h>
|
||||
|
||||
/*------------------ TASKING Compiler ------------------*/
|
||||
#elif defined ( __TASKING__ )
|
||||
/*
|
||||
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
||||
* Please use "carm -?i" to get an up to date list of all intrinsics,
|
||||
* Including the CMSIS ones.
|
||||
*/
|
||||
|
||||
/*------------------ COSMIC Compiler -------------------*/
|
||||
#elif defined ( __CSMC__ )
|
||||
#include <cmsis_csm.h>
|
||||
|
||||
#endif
|
||||
|
||||
/*@} end of group CMSIS_SIMD_intrinsics */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CORE_CMSIMD_H */
|
||||
|
||||
+1310
-1310
File diff suppressed because it is too large
Load Diff
+129
-129
@@ -1,129 +1,129 @@
|
||||
/**
|
||||
* Copyright (c) 2014 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "app_util_platform.h"
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
/* Global nvic state instance, required by nrf_nvic.h */
|
||||
nrf_nvic_state_t nrf_nvic_state;
|
||||
#endif
|
||||
|
||||
static uint32_t m_in_critical_region = 0;
|
||||
|
||||
void app_util_disable_irq(void)
|
||||
{
|
||||
__disable_irq();
|
||||
m_in_critical_region++;
|
||||
}
|
||||
|
||||
void app_util_enable_irq(void)
|
||||
{
|
||||
m_in_critical_region--;
|
||||
if (m_in_critical_region == 0)
|
||||
{
|
||||
__enable_irq();
|
||||
}
|
||||
}
|
||||
|
||||
void app_util_critical_region_enter(uint8_t *p_nested)
|
||||
{
|
||||
#if __CORTEX_M == (0x04U)
|
||||
ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
|
||||
#endif
|
||||
|
||||
#if defined(SOFTDEVICE_PRESENT)
|
||||
/* return value can be safely ignored */
|
||||
(void) sd_nvic_critical_region_enter(p_nested);
|
||||
#else
|
||||
(void)p_nested;
|
||||
app_util_disable_irq();
|
||||
#endif
|
||||
}
|
||||
|
||||
void app_util_critical_region_exit(uint8_t nested)
|
||||
{
|
||||
#if __CORTEX_M == (0x04U)
|
||||
ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
|
||||
#endif
|
||||
|
||||
#if defined(SOFTDEVICE_PRESENT)
|
||||
/* return value can be safely ignored */
|
||||
(void) sd_nvic_critical_region_exit(nested);
|
||||
#else
|
||||
app_util_enable_irq();
|
||||
(void)nested;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
uint8_t privilege_level_get(void)
|
||||
{
|
||||
#if __CORTEX_M == (0x00U) || defined(_WIN32) || defined(__unix) || defined(__APPLE__)
|
||||
/* the Cortex-M0 has no concept of privilege */
|
||||
return APP_LEVEL_PRIVILEGED;
|
||||
#elif __CORTEX_M == (0x04U)
|
||||
uint32_t isr_vector_num = __get_IPSR() & IPSR_ISR_Msk ;
|
||||
if (0 == isr_vector_num)
|
||||
{
|
||||
/* Thread Mode, check nPRIV */
|
||||
int32_t control = __get_CONTROL();
|
||||
return control & CONTROL_nPRIV_Msk ? APP_LEVEL_UNPRIVILEGED : APP_LEVEL_PRIVILEGED;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Handler Mode, always privileged */
|
||||
return APP_LEVEL_PRIVILEGED;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
uint8_t current_int_priority_get(void)
|
||||
{
|
||||
uint32_t isr_vector_num = __get_IPSR() & IPSR_ISR_Msk ;
|
||||
if (isr_vector_num > 0)
|
||||
{
|
||||
int32_t irq_type = ((int32_t)isr_vector_num - EXTERNAL_INT_VECTOR_OFFSET);
|
||||
return (NVIC_GetPriority((IRQn_Type)irq_type) & 0xFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
return APP_IRQ_PRIORITY_THREAD;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (c) 2014 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "app_util_platform.h"
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
/* Global nvic state instance, required by nrf_nvic.h */
|
||||
nrf_nvic_state_t nrf_nvic_state;
|
||||
#endif
|
||||
|
||||
static uint32_t m_in_critical_region = 0;
|
||||
|
||||
void app_util_disable_irq(void)
|
||||
{
|
||||
__disable_irq();
|
||||
m_in_critical_region++;
|
||||
}
|
||||
|
||||
void app_util_enable_irq(void)
|
||||
{
|
||||
m_in_critical_region--;
|
||||
if (m_in_critical_region == 0)
|
||||
{
|
||||
__enable_irq();
|
||||
}
|
||||
}
|
||||
|
||||
void app_util_critical_region_enter(uint8_t *p_nested)
|
||||
{
|
||||
#if __CORTEX_M == (0x04U)
|
||||
ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
|
||||
#endif
|
||||
|
||||
#if defined(SOFTDEVICE_PRESENT)
|
||||
/* return value can be safely ignored */
|
||||
(void) sd_nvic_critical_region_enter(p_nested);
|
||||
#else
|
||||
(void)p_nested;
|
||||
app_util_disable_irq();
|
||||
#endif
|
||||
}
|
||||
|
||||
void app_util_critical_region_exit(uint8_t nested)
|
||||
{
|
||||
#if __CORTEX_M == (0x04U)
|
||||
ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get())
|
||||
#endif
|
||||
|
||||
#if defined(SOFTDEVICE_PRESENT)
|
||||
/* return value can be safely ignored */
|
||||
(void) sd_nvic_critical_region_exit(nested);
|
||||
#else
|
||||
app_util_enable_irq();
|
||||
(void)nested;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
uint8_t privilege_level_get(void)
|
||||
{
|
||||
#if __CORTEX_M == (0x00U) || defined(_WIN32) || defined(__unix) || defined(__APPLE__)
|
||||
/* the Cortex-M0 has no concept of privilege */
|
||||
return APP_LEVEL_PRIVILEGED;
|
||||
#elif __CORTEX_M == (0x04U)
|
||||
uint32_t isr_vector_num = __get_IPSR() & IPSR_ISR_Msk ;
|
||||
if (0 == isr_vector_num)
|
||||
{
|
||||
/* Thread Mode, check nPRIV */
|
||||
int32_t control = __get_CONTROL();
|
||||
return control & CONTROL_nPRIV_Msk ? APP_LEVEL_UNPRIVILEGED : APP_LEVEL_PRIVILEGED;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Handler Mode, always privileged */
|
||||
return APP_LEVEL_PRIVILEGED;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
uint8_t current_int_priority_get(void)
|
||||
{
|
||||
uint32_t isr_vector_num = __get_IPSR() & IPSR_ISR_Msk ;
|
||||
if (isr_vector_num > 0)
|
||||
{
|
||||
int32_t irq_type = ((int32_t)isr_vector_num - EXTERNAL_INT_VECTOR_OFFSET);
|
||||
return (NVIC_GetPriority((IRQn_Type)irq_type) & 0xFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
return APP_IRQ_PRIORITY_THREAD;
|
||||
}
|
||||
}
|
||||
|
||||
+279
-279
@@ -1,279 +1,279 @@
|
||||
/**
|
||||
* Copyright (c) 2014 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@file
|
||||
*
|
||||
* @defgroup app_util_platform Utility Functions and Definitions (Platform)
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief Various types and definitions available to all applications when using SoftDevice.
|
||||
*/
|
||||
|
||||
#ifndef APP_UTIL_PLATFORM_H__
|
||||
#define APP_UTIL_PLATFORM_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "compiler_abstraction.h"
|
||||
#include "nrf.h"
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
#include "nrf_soc.h"
|
||||
#include "nrf_nvic.h"
|
||||
#endif
|
||||
#include "nrf_assert.h"
|
||||
#include "app_error.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if __CORTEX_M == (0x00U)
|
||||
#define _PRIO_SD_HIGH 0
|
||||
#define _PRIO_APP_HIGH 1
|
||||
#define _PRIO_APP_MID 1
|
||||
#define _PRIO_SD_LOW 2
|
||||
#define _PRIO_APP_LOW 3
|
||||
#define _PRIO_APP_LOWEST 3
|
||||
#define _PRIO_THREAD 4
|
||||
#elif __CORTEX_M == (0x04U)
|
||||
#define _PRIO_SD_HIGH 0
|
||||
#define _PRIO_SD_MID 1
|
||||
#define _PRIO_APP_HIGH 2
|
||||
#define _PRIO_APP_MID 3
|
||||
#define _PRIO_SD_LOW 4
|
||||
#define _PRIO_SD_LOWEST 5
|
||||
#define _PRIO_APP_LOW 6
|
||||
#define _PRIO_APP_LOWEST 7
|
||||
#define _PRIO_THREAD 15
|
||||
#else
|
||||
#error "No platform defined"
|
||||
#endif
|
||||
|
||||
|
||||
//lint -save -e113 -e452
|
||||
/**@brief The interrupt priorities available to the application while the SoftDevice is active. */
|
||||
typedef enum
|
||||
{
|
||||
#ifndef SOFTDEVICE_PRESENT
|
||||
APP_IRQ_PRIORITY_HIGHEST = _PRIO_SD_HIGH,
|
||||
#else
|
||||
APP_IRQ_PRIORITY_HIGHEST = _PRIO_APP_HIGH,
|
||||
#endif
|
||||
APP_IRQ_PRIORITY_HIGH = _PRIO_APP_HIGH,
|
||||
#ifndef SOFTDEVICE_PRESENT
|
||||
APP_IRQ_PRIORITY_MID = _PRIO_SD_LOW,
|
||||
#else
|
||||
APP_IRQ_PRIORITY_MID = _PRIO_APP_MID,
|
||||
#endif
|
||||
APP_IRQ_PRIORITY_LOW = _PRIO_APP_LOW,
|
||||
APP_IRQ_PRIORITY_LOWEST = _PRIO_APP_LOWEST,
|
||||
APP_IRQ_PRIORITY_THREAD = _PRIO_THREAD /**< "Interrupt level" when running in Thread Mode. */
|
||||
} app_irq_priority_t;
|
||||
//lint -restore
|
||||
|
||||
|
||||
/*@brief The privilege levels available to applications in Thread Mode */
|
||||
typedef enum
|
||||
{
|
||||
APP_LEVEL_UNPRIVILEGED,
|
||||
APP_LEVEL_PRIVILEGED
|
||||
} app_level_t;
|
||||
|
||||
/**@cond NO_DOXYGEN */
|
||||
#define EXTERNAL_INT_VECTOR_OFFSET 16
|
||||
/**@endcond */
|
||||
|
||||
/**@brief Macro for setting a breakpoint.
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
#define NRF_BREAKPOINT __asm__("BKPT 0");
|
||||
#else
|
||||
#define NRF_BREAKPOINT __BKPT(0)
|
||||
#endif
|
||||
|
||||
/** @brief Macro for setting a breakpoint.
|
||||
*
|
||||
* If it is possible to detect debugger presence then it is set only in that case.
|
||||
*
|
||||
*/
|
||||
#if __CORTEX_M == 0x04
|
||||
#define NRF_BREAKPOINT_COND do { \
|
||||
/* C_DEBUGEN == 1 -> Debugger Connected */ \
|
||||
if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) \
|
||||
{ \
|
||||
/* Generate breakpoint if debugger is connected */ \
|
||||
NRF_BREAKPOINT; \
|
||||
} \
|
||||
}while (0)
|
||||
#else
|
||||
#define NRF_BREAKPOINT_COND NRF_BREAKPOINT
|
||||
#endif // __CORTEX_M == 0x04
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#define PACKED(TYPE) __packed TYPE
|
||||
#define PACKED_STRUCT PACKED(struct)
|
||||
#elif defined ( __GNUC__ )
|
||||
#define PACKED __attribute__((packed))
|
||||
#define PACKED_STRUCT struct PACKED
|
||||
#elif defined (__ICCARM__)
|
||||
#define PACKED_STRUCT __packed struct
|
||||
#endif
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#define PRAGMA_OPTIMIZATION_FORCE_START _Pragma ("push") \
|
||||
_Pragma ("O3")
|
||||
#define PRAGMA_OPTIMIZATION_FORCE_END _Pragma ("pop")
|
||||
#elif defined ( __GNUC__ )
|
||||
#define PRAGMA_OPTIMIZATION_FORCE_START _Pragma("GCC push_options") \
|
||||
_Pragma ("GCC optimize (\"Os\")")
|
||||
#define PRAGMA_OPTIMIZATION_FORCE_END _Pragma ("GCC pop_options")
|
||||
#elif defined (__ICCARM__)
|
||||
#define PRAGMA_OPTIMIZATION_FORCE_START _Pragma ("optimize=high z")
|
||||
#define PRAGMA_OPTIMIZATION_FORCE_END
|
||||
#endif
|
||||
|
||||
|
||||
void app_util_critical_region_enter (uint8_t *p_nested);
|
||||
void app_util_critical_region_exit (uint8_t nested);
|
||||
|
||||
/**@brief Macro for entering a critical region.
|
||||
*
|
||||
* @note Due to implementation details, there must exist one and only one call to
|
||||
* CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
|
||||
* in the same scope.
|
||||
*/
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
#define CRITICAL_REGION_ENTER() \
|
||||
{ \
|
||||
uint8_t __CR_NESTED = 0; \
|
||||
app_util_critical_region_enter(&__CR_NESTED);
|
||||
#else
|
||||
#define CRITICAL_REGION_ENTER() app_util_critical_region_enter(NULL)
|
||||
#endif
|
||||
|
||||
/**@brief Macro for leaving a critical region.
|
||||
*
|
||||
* @note Due to implementation details, there must exist one and only one call to
|
||||
* CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
|
||||
* in the same scope.
|
||||
*/
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
#define CRITICAL_REGION_EXIT() \
|
||||
app_util_critical_region_exit(__CR_NESTED); \
|
||||
}
|
||||
#else
|
||||
#define CRITICAL_REGION_EXIT() app_util_critical_region_exit(0)
|
||||
#endif
|
||||
|
||||
/* Workaround for Keil 4 */
|
||||
#ifndef IPSR_ISR_Msk
|
||||
#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**@brief Macro to enable anonymous unions from a certain point in the code.
|
||||
*/
|
||||
#if defined(__CC_ARM)
|
||||
#define ANON_UNIONS_ENABLE _Pragma("push") \
|
||||
_Pragma("anon_unions") \
|
||||
struct semicolon_swallower
|
||||
#elif defined(__ICCARM__)
|
||||
#define ANON_UNIONS_ENABLE _Pragma("language=extended") \
|
||||
struct semicolon_swallower
|
||||
#else
|
||||
#define ANON_UNIONS_ENABLE struct semicolon_swallower
|
||||
// No action will be taken.
|
||||
// For GCC anonymous unions are enabled by default.
|
||||
#endif
|
||||
|
||||
/**@brief Macro to disable anonymous unions from a certain point in the code.
|
||||
* @note Call only after first calling @ref ANON_UNIONS_ENABLE.
|
||||
*/
|
||||
#if defined(__CC_ARM)
|
||||
#define ANON_UNIONS_DISABLE _Pragma("pop") \
|
||||
struct semicolon_swallower
|
||||
#elif defined(__ICCARM__)
|
||||
#define ANON_UNIONS_DISABLE struct semicolon_swallower
|
||||
// for IAR leave anonymous unions enabled
|
||||
#else
|
||||
#define ANON_UNIONS_DISABLE struct semicolon_swallower
|
||||
// No action will be taken.
|
||||
// For GCC anonymous unions are enabled by default.
|
||||
#endif
|
||||
|
||||
/**@brief Macro for adding pragma directive only for GCC.
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
#define GCC_PRAGMA(v) _Pragma(v)
|
||||
#else
|
||||
#define GCC_PRAGMA(v)
|
||||
#endif
|
||||
|
||||
/* Workaround for Keil 4 */
|
||||
#ifndef CONTROL_nPRIV_Msk
|
||||
#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV Mask */
|
||||
#endif
|
||||
|
||||
/**@brief Function for finding the current interrupt level.
|
||||
*
|
||||
* @return Current interrupt level.
|
||||
* @retval APP_IRQ_PRIORITY_HIGH We are running in Application High interrupt level.
|
||||
* @retval APP_IRQ_PRIORITY_LOW We are running in Application Low interrupt level.
|
||||
* @retval APP_IRQ_PRIORITY_THREAD We are running in Thread Mode.
|
||||
*/
|
||||
uint8_t current_int_priority_get(void);
|
||||
|
||||
|
||||
/**@brief Function for finding out the current privilege level.
|
||||
*
|
||||
* @return Current privilege level.
|
||||
* @retval APP_LEVEL_UNPRIVILEGED We are running in unprivileged level.
|
||||
* @retval APP_LEVEL_PRIVILEGED We are running in privileged level.
|
||||
*/
|
||||
uint8_t privilege_level_get(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APP_UTIL_PLATFORM_H__
|
||||
|
||||
/** @} */
|
||||
/**
|
||||
* Copyright (c) 2014 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@file
|
||||
*
|
||||
* @defgroup app_util_platform Utility Functions and Definitions (Platform)
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief Various types and definitions available to all applications when using SoftDevice.
|
||||
*/
|
||||
|
||||
#ifndef APP_UTIL_PLATFORM_H__
|
||||
#define APP_UTIL_PLATFORM_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "compiler_abstraction.h"
|
||||
#include "nrf.h"
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
#include "nrf_soc.h"
|
||||
#include "nrf_nvic.h"
|
||||
#endif
|
||||
#include "nrf_assert.h"
|
||||
#include "app_error.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if __CORTEX_M == (0x00U)
|
||||
#define _PRIO_SD_HIGH 0
|
||||
#define _PRIO_APP_HIGH 1
|
||||
#define _PRIO_APP_MID 1
|
||||
#define _PRIO_SD_LOW 2
|
||||
#define _PRIO_APP_LOW 3
|
||||
#define _PRIO_APP_LOWEST 3
|
||||
#define _PRIO_THREAD 4
|
||||
#elif __CORTEX_M == (0x04U)
|
||||
#define _PRIO_SD_HIGH 0
|
||||
#define _PRIO_SD_MID 1
|
||||
#define _PRIO_APP_HIGH 2
|
||||
#define _PRIO_APP_MID 3
|
||||
#define _PRIO_SD_LOW 4
|
||||
#define _PRIO_SD_LOWEST 5
|
||||
#define _PRIO_APP_LOW 6
|
||||
#define _PRIO_APP_LOWEST 7
|
||||
#define _PRIO_THREAD 15
|
||||
#else
|
||||
#error "No platform defined"
|
||||
#endif
|
||||
|
||||
|
||||
//lint -save -e113 -e452
|
||||
/**@brief The interrupt priorities available to the application while the SoftDevice is active. */
|
||||
typedef enum
|
||||
{
|
||||
#ifndef SOFTDEVICE_PRESENT
|
||||
APP_IRQ_PRIORITY_HIGHEST = _PRIO_SD_HIGH,
|
||||
#else
|
||||
APP_IRQ_PRIORITY_HIGHEST = _PRIO_APP_HIGH,
|
||||
#endif
|
||||
APP_IRQ_PRIORITY_HIGH = _PRIO_APP_HIGH,
|
||||
#ifndef SOFTDEVICE_PRESENT
|
||||
APP_IRQ_PRIORITY_MID = _PRIO_SD_LOW,
|
||||
#else
|
||||
APP_IRQ_PRIORITY_MID = _PRIO_APP_MID,
|
||||
#endif
|
||||
APP_IRQ_PRIORITY_LOW = _PRIO_APP_LOW,
|
||||
APP_IRQ_PRIORITY_LOWEST = _PRIO_APP_LOWEST,
|
||||
APP_IRQ_PRIORITY_THREAD = _PRIO_THREAD /**< "Interrupt level" when running in Thread Mode. */
|
||||
} app_irq_priority_t;
|
||||
//lint -restore
|
||||
|
||||
|
||||
/*@brief The privilege levels available to applications in Thread Mode */
|
||||
typedef enum
|
||||
{
|
||||
APP_LEVEL_UNPRIVILEGED,
|
||||
APP_LEVEL_PRIVILEGED
|
||||
} app_level_t;
|
||||
|
||||
/**@cond NO_DOXYGEN */
|
||||
#define EXTERNAL_INT_VECTOR_OFFSET 16
|
||||
/**@endcond */
|
||||
|
||||
/**@brief Macro for setting a breakpoint.
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
#define NRF_BREAKPOINT __asm__("BKPT 0");
|
||||
#else
|
||||
#define NRF_BREAKPOINT __BKPT(0)
|
||||
#endif
|
||||
|
||||
/** @brief Macro for setting a breakpoint.
|
||||
*
|
||||
* If it is possible to detect debugger presence then it is set only in that case.
|
||||
*
|
||||
*/
|
||||
#if __CORTEX_M == 0x04
|
||||
#define NRF_BREAKPOINT_COND do { \
|
||||
/* C_DEBUGEN == 1 -> Debugger Connected */ \
|
||||
if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) \
|
||||
{ \
|
||||
/* Generate breakpoint if debugger is connected */ \
|
||||
NRF_BREAKPOINT; \
|
||||
} \
|
||||
}while (0)
|
||||
#else
|
||||
#define NRF_BREAKPOINT_COND NRF_BREAKPOINT
|
||||
#endif // __CORTEX_M == 0x04
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#define PACKED(TYPE) __packed TYPE
|
||||
#define PACKED_STRUCT PACKED(struct)
|
||||
#elif defined ( __GNUC__ )
|
||||
#define PACKED __attribute__((packed))
|
||||
#define PACKED_STRUCT struct PACKED
|
||||
#elif defined (__ICCARM__)
|
||||
#define PACKED_STRUCT __packed struct
|
||||
#endif
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
#define PRAGMA_OPTIMIZATION_FORCE_START _Pragma ("push") \
|
||||
_Pragma ("O3")
|
||||
#define PRAGMA_OPTIMIZATION_FORCE_END _Pragma ("pop")
|
||||
#elif defined ( __GNUC__ )
|
||||
#define PRAGMA_OPTIMIZATION_FORCE_START _Pragma("GCC push_options") \
|
||||
_Pragma ("GCC optimize (\"Os\")")
|
||||
#define PRAGMA_OPTIMIZATION_FORCE_END _Pragma ("GCC pop_options")
|
||||
#elif defined (__ICCARM__)
|
||||
#define PRAGMA_OPTIMIZATION_FORCE_START _Pragma ("optimize=high z")
|
||||
#define PRAGMA_OPTIMIZATION_FORCE_END
|
||||
#endif
|
||||
|
||||
|
||||
void app_util_critical_region_enter (uint8_t *p_nested);
|
||||
void app_util_critical_region_exit (uint8_t nested);
|
||||
|
||||
/**@brief Macro for entering a critical region.
|
||||
*
|
||||
* @note Due to implementation details, there must exist one and only one call to
|
||||
* CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
|
||||
* in the same scope.
|
||||
*/
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
#define CRITICAL_REGION_ENTER() \
|
||||
{ \
|
||||
uint8_t __CR_NESTED = 0; \
|
||||
app_util_critical_region_enter(&__CR_NESTED);
|
||||
#else
|
||||
#define CRITICAL_REGION_ENTER() app_util_critical_region_enter(NULL)
|
||||
#endif
|
||||
|
||||
/**@brief Macro for leaving a critical region.
|
||||
*
|
||||
* @note Due to implementation details, there must exist one and only one call to
|
||||
* CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
|
||||
* in the same scope.
|
||||
*/
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
#define CRITICAL_REGION_EXIT() \
|
||||
app_util_critical_region_exit(__CR_NESTED); \
|
||||
}
|
||||
#else
|
||||
#define CRITICAL_REGION_EXIT() app_util_critical_region_exit(0)
|
||||
#endif
|
||||
|
||||
/* Workaround for Keil 4 */
|
||||
#ifndef IPSR_ISR_Msk
|
||||
#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**@brief Macro to enable anonymous unions from a certain point in the code.
|
||||
*/
|
||||
#if defined(__CC_ARM)
|
||||
#define ANON_UNIONS_ENABLE _Pragma("push") \
|
||||
_Pragma("anon_unions") \
|
||||
struct semicolon_swallower
|
||||
#elif defined(__ICCARM__)
|
||||
#define ANON_UNIONS_ENABLE _Pragma("language=extended") \
|
||||
struct semicolon_swallower
|
||||
#else
|
||||
#define ANON_UNIONS_ENABLE struct semicolon_swallower
|
||||
// No action will be taken.
|
||||
// For GCC anonymous unions are enabled by default.
|
||||
#endif
|
||||
|
||||
/**@brief Macro to disable anonymous unions from a certain point in the code.
|
||||
* @note Call only after first calling @ref ANON_UNIONS_ENABLE.
|
||||
*/
|
||||
#if defined(__CC_ARM)
|
||||
#define ANON_UNIONS_DISABLE _Pragma("pop") \
|
||||
struct semicolon_swallower
|
||||
#elif defined(__ICCARM__)
|
||||
#define ANON_UNIONS_DISABLE struct semicolon_swallower
|
||||
// for IAR leave anonymous unions enabled
|
||||
#else
|
||||
#define ANON_UNIONS_DISABLE struct semicolon_swallower
|
||||
// No action will be taken.
|
||||
// For GCC anonymous unions are enabled by default.
|
||||
#endif
|
||||
|
||||
/**@brief Macro for adding pragma directive only for GCC.
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
#define GCC_PRAGMA(v) _Pragma(v)
|
||||
#else
|
||||
#define GCC_PRAGMA(v)
|
||||
#endif
|
||||
|
||||
/* Workaround for Keil 4 */
|
||||
#ifndef CONTROL_nPRIV_Msk
|
||||
#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV Mask */
|
||||
#endif
|
||||
|
||||
/**@brief Function for finding the current interrupt level.
|
||||
*
|
||||
* @return Current interrupt level.
|
||||
* @retval APP_IRQ_PRIORITY_HIGH We are running in Application High interrupt level.
|
||||
* @retval APP_IRQ_PRIORITY_LOW We are running in Application Low interrupt level.
|
||||
* @retval APP_IRQ_PRIORITY_THREAD We are running in Thread Mode.
|
||||
*/
|
||||
uint8_t current_int_priority_get(void);
|
||||
|
||||
|
||||
/**@brief Function for finding out the current privilege level.
|
||||
*
|
||||
* @return Current privilege level.
|
||||
* @retval APP_LEVEL_UNPRIVILEGED We are running in unprivileged level.
|
||||
* @retval APP_LEVEL_PRIVILEGED We are running in privileged level.
|
||||
*/
|
||||
uint8_t privilege_level_get(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APP_UTIL_PLATFORM_H__
|
||||
|
||||
/** @} */
|
||||
|
||||
+215
-215
@@ -1,215 +1,215 @@
|
||||
/**
|
||||
* Copyright (c) 2008 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @file
|
||||
* @brief Common defines and macros for firmware developed by Nordic Semiconductor.
|
||||
*/
|
||||
|
||||
#ifndef NORDIC_COMMON_H__
|
||||
#define NORDIC_COMMON_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Check if selected module is enabled
|
||||
*
|
||||
* This is save function for driver enable checking.
|
||||
* Correct from Lint point of view (not using default of undefined value).
|
||||
*
|
||||
* Usage:
|
||||
* @code
|
||||
#if NRF_MODULE_ENABLED(UART)
|
||||
...
|
||||
#endif
|
||||
* @endcode
|
||||
*
|
||||
* @param module The module name.
|
||||
*
|
||||
* @retval 1 The macro <module>_ENABLE is defined and is non-zero.
|
||||
* @retval 0 The macro <module>_ENABLE is not defined or it equals zero.
|
||||
*
|
||||
* @note
|
||||
* This macro intentionally does not implement second expansion level.
|
||||
* The name of the module to be checked has to be given directly as a parameter.
|
||||
* And given parameter would be connected with @c _ENABLED postfix directly
|
||||
* without evaluating its value.
|
||||
*/
|
||||
//lint -emacro(491,NRF_MODULE_ENABLED) // Suppers warning 491 "non-standard use of 'defined' preprocessor operator"
|
||||
#ifdef NRF_MODULE_ENABLE_ALL
|
||||
#warning "Do not use NRF_MODULE_ENABLE_ALL for real builds."
|
||||
#define NRF_MODULE_ENABLED(module) 1
|
||||
#else
|
||||
#define NRF_MODULE_ENABLED(module) \
|
||||
((defined(module ## _ENABLED) && (module ## _ENABLED)) ? 1 : 0)
|
||||
#endif
|
||||
/** The upper 8 bits of a 32 bit value */
|
||||
//lint -emacro(572,MSB_32) // Suppress warning 572 "Excessive shift value"
|
||||
#define MSB_32(a) (((a) & 0xFF000000) >> 24)
|
||||
/** The lower 8 bits (of a 32 bit value) */
|
||||
#define LSB_32(a) ((a) & 0x000000FF)
|
||||
|
||||
/** The upper 8 bits of a 16 bit value */
|
||||
//lint -emacro(572,MSB_16) // Suppress warning 572 "Excessive shift value"
|
||||
#define MSB_16(a) (((a) & 0xFF00) >> 8)
|
||||
/** The lower 8 bits (of a 16 bit value) */
|
||||
#define LSB_16(a) ((a) & 0x00FF)
|
||||
|
||||
/** Leaves the minimum of the two 32-bit arguments */
|
||||
/*lint -emacro(506, MIN) */ /* Suppress "Constant value Boolean */
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
/** Leaves the maximum of the two 32-bit arguments */
|
||||
/*lint -emacro(506, MAX) */ /* Suppress "Constant value Boolean */
|
||||
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
||||
|
||||
/**@brief Concatenates two parameters.
|
||||
*
|
||||
* It realizes two level expansion to make it sure that all the parameters
|
||||
* are actually expanded before gluing them together.
|
||||
*
|
||||
* @param p1 First parameter to concatenating
|
||||
* @param p2 Second parameter to concatenating
|
||||
*
|
||||
* @return Two parameters glued together.
|
||||
* They have to create correct C mnemonic in other case
|
||||
* preprocessor error would be generated.
|
||||
*
|
||||
* @sa CONCAT_3
|
||||
*/
|
||||
#define CONCAT_2(p1, p2) CONCAT_2_(p1, p2)
|
||||
/** Auxiliary macro used by @ref CONCAT_2 */
|
||||
#define CONCAT_2_(p1, p2) p1##p2
|
||||
|
||||
/**@brief Concatenates three parameters.
|
||||
*
|
||||
* It realizes two level expansion to make it sure that all the parameters
|
||||
* are actually expanded before gluing them together.
|
||||
*
|
||||
* @param p1 First parameter to concatenating
|
||||
* @param p2 Second parameter to concatenating
|
||||
* @param p3 Third parameter to concatenating
|
||||
*
|
||||
* @return Three parameters glued together.
|
||||
* They have to create correct C mnemonic in other case
|
||||
* preprocessor error would be generated.
|
||||
*
|
||||
* @sa CONCAT_2
|
||||
*/
|
||||
#define CONCAT_3(p1, p2, p3) CONCAT_3_(p1, p2, p3)
|
||||
/** Auxiliary macro used by @ref CONCAT_3 */
|
||||
#define CONCAT_3_(p1, p2, p3) p1##p2##p3
|
||||
|
||||
#define STRINGIFY_(val) #val
|
||||
/** Converts a macro argument into a character constant.
|
||||
*/
|
||||
#define STRINGIFY(val) STRINGIFY_(val)
|
||||
|
||||
/** Counts number of elements inside the array
|
||||
*/
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
/**@brief Set a bit in the uint32 word.
|
||||
*
|
||||
* @param[in] W Word whose bit is being set.
|
||||
* @param[in] B Bit number in the word to be set.
|
||||
*/
|
||||
#define SET_BIT(W, B) ((W) |= (uint32_t)(1U << (B)))
|
||||
|
||||
|
||||
/**@brief Clears a bit in the uint32 word.
|
||||
*
|
||||
* @param[in] W Word whose bit is to be cleared.
|
||||
* @param[in] B Bit number in the word to be cleared.
|
||||
*/
|
||||
#define CLR_BIT(W, B) ((W) &= (~(uint32_t)(1U << (B))))
|
||||
|
||||
|
||||
/**@brief Checks if a bit is set.
|
||||
*
|
||||
* @param[in] W Word whose bit is to be checked.
|
||||
* @param[in] B Bit number in the word to be checked.
|
||||
*
|
||||
* @retval 1 if bit is set.
|
||||
* @retval 0 if bit is not set.
|
||||
*/
|
||||
#define IS_SET(W, B) (((W) >> (B)) & 1)
|
||||
|
||||
#define BIT_0 0x01 /**< The value of bit 0 */
|
||||
#define BIT_1 0x02 /**< The value of bit 1 */
|
||||
#define BIT_2 0x04 /**< The value of bit 2 */
|
||||
#define BIT_3 0x08 /**< The value of bit 3 */
|
||||
#define BIT_4 0x10 /**< The value of bit 4 */
|
||||
#define BIT_5 0x20 /**< The value of bit 5 */
|
||||
#define BIT_6 0x40 /**< The value of bit 6 */
|
||||
#define BIT_7 0x80 /**< The value of bit 7 */
|
||||
#define BIT_8 0x0100 /**< The value of bit 8 */
|
||||
#define BIT_9 0x0200 /**< The value of bit 9 */
|
||||
#define BIT_10 0x0400 /**< The value of bit 10 */
|
||||
#define BIT_11 0x0800 /**< The value of bit 11 */
|
||||
#define BIT_12 0x1000 /**< The value of bit 12 */
|
||||
#define BIT_13 0x2000 /**< The value of bit 13 */
|
||||
#define BIT_14 0x4000 /**< The value of bit 14 */
|
||||
#define BIT_15 0x8000 /**< The value of bit 15 */
|
||||
#define BIT_16 0x00010000 /**< The value of bit 16 */
|
||||
#define BIT_17 0x00020000 /**< The value of bit 17 */
|
||||
#define BIT_18 0x00040000 /**< The value of bit 18 */
|
||||
#define BIT_19 0x00080000 /**< The value of bit 19 */
|
||||
#define BIT_20 0x00100000 /**< The value of bit 20 */
|
||||
#define BIT_21 0x00200000 /**< The value of bit 21 */
|
||||
#define BIT_22 0x00400000 /**< The value of bit 22 */
|
||||
#define BIT_23 0x00800000 /**< The value of bit 23 */
|
||||
#define BIT_24 0x01000000 /**< The value of bit 24 */
|
||||
#define BIT_25 0x02000000 /**< The value of bit 25 */
|
||||
#define BIT_26 0x04000000 /**< The value of bit 26 */
|
||||
#define BIT_27 0x08000000 /**< The value of bit 27 */
|
||||
#define BIT_28 0x10000000 /**< The value of bit 28 */
|
||||
#define BIT_29 0x20000000 /**< The value of bit 29 */
|
||||
#define BIT_30 0x40000000 /**< The value of bit 30 */
|
||||
#define BIT_31 0x80000000 /**< The value of bit 31 */
|
||||
|
||||
#define UNUSED_VARIABLE(X) ((void)(X))
|
||||
#define UNUSED_PARAMETER(X) UNUSED_VARIABLE(X)
|
||||
#define UNUSED_RETURN_VALUE(X) UNUSED_VARIABLE(X)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NORDIC_COMMON_H__
|
||||
/**
|
||||
* Copyright (c) 2008 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @file
|
||||
* @brief Common defines and macros for firmware developed by Nordic Semiconductor.
|
||||
*/
|
||||
|
||||
#ifndef NORDIC_COMMON_H__
|
||||
#define NORDIC_COMMON_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Check if selected module is enabled
|
||||
*
|
||||
* This is save function for driver enable checking.
|
||||
* Correct from Lint point of view (not using default of undefined value).
|
||||
*
|
||||
* Usage:
|
||||
* @code
|
||||
#if NRF_MODULE_ENABLED(UART)
|
||||
...
|
||||
#endif
|
||||
* @endcode
|
||||
*
|
||||
* @param module The module name.
|
||||
*
|
||||
* @retval 1 The macro <module>_ENABLE is defined and is non-zero.
|
||||
* @retval 0 The macro <module>_ENABLE is not defined or it equals zero.
|
||||
*
|
||||
* @note
|
||||
* This macro intentionally does not implement second expansion level.
|
||||
* The name of the module to be checked has to be given directly as a parameter.
|
||||
* And given parameter would be connected with @c _ENABLED postfix directly
|
||||
* without evaluating its value.
|
||||
*/
|
||||
//lint -emacro(491,NRF_MODULE_ENABLED) // Suppers warning 491 "non-standard use of 'defined' preprocessor operator"
|
||||
#ifdef NRF_MODULE_ENABLE_ALL
|
||||
#warning "Do not use NRF_MODULE_ENABLE_ALL for real builds."
|
||||
#define NRF_MODULE_ENABLED(module) 1
|
||||
#else
|
||||
#define NRF_MODULE_ENABLED(module) \
|
||||
((defined(module ## _ENABLED) && (module ## _ENABLED)) ? 1 : 0)
|
||||
#endif
|
||||
/** The upper 8 bits of a 32 bit value */
|
||||
//lint -emacro(572,MSB_32) // Suppress warning 572 "Excessive shift value"
|
||||
#define MSB_32(a) (((a) & 0xFF000000) >> 24)
|
||||
/** The lower 8 bits (of a 32 bit value) */
|
||||
#define LSB_32(a) ((a) & 0x000000FF)
|
||||
|
||||
/** The upper 8 bits of a 16 bit value */
|
||||
//lint -emacro(572,MSB_16) // Suppress warning 572 "Excessive shift value"
|
||||
#define MSB_16(a) (((a) & 0xFF00) >> 8)
|
||||
/** The lower 8 bits (of a 16 bit value) */
|
||||
#define LSB_16(a) ((a) & 0x00FF)
|
||||
|
||||
/** Leaves the minimum of the two 32-bit arguments */
|
||||
/*lint -emacro(506, MIN) */ /* Suppress "Constant value Boolean */
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
/** Leaves the maximum of the two 32-bit arguments */
|
||||
/*lint -emacro(506, MAX) */ /* Suppress "Constant value Boolean */
|
||||
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
||||
|
||||
/**@brief Concatenates two parameters.
|
||||
*
|
||||
* It realizes two level expansion to make it sure that all the parameters
|
||||
* are actually expanded before gluing them together.
|
||||
*
|
||||
* @param p1 First parameter to concatenating
|
||||
* @param p2 Second parameter to concatenating
|
||||
*
|
||||
* @return Two parameters glued together.
|
||||
* They have to create correct C mnemonic in other case
|
||||
* preprocessor error would be generated.
|
||||
*
|
||||
* @sa CONCAT_3
|
||||
*/
|
||||
#define CONCAT_2(p1, p2) CONCAT_2_(p1, p2)
|
||||
/** Auxiliary macro used by @ref CONCAT_2 */
|
||||
#define CONCAT_2_(p1, p2) p1##p2
|
||||
|
||||
/**@brief Concatenates three parameters.
|
||||
*
|
||||
* It realizes two level expansion to make it sure that all the parameters
|
||||
* are actually expanded before gluing them together.
|
||||
*
|
||||
* @param p1 First parameter to concatenating
|
||||
* @param p2 Second parameter to concatenating
|
||||
* @param p3 Third parameter to concatenating
|
||||
*
|
||||
* @return Three parameters glued together.
|
||||
* They have to create correct C mnemonic in other case
|
||||
* preprocessor error would be generated.
|
||||
*
|
||||
* @sa CONCAT_2
|
||||
*/
|
||||
#define CONCAT_3(p1, p2, p3) CONCAT_3_(p1, p2, p3)
|
||||
/** Auxiliary macro used by @ref CONCAT_3 */
|
||||
#define CONCAT_3_(p1, p2, p3) p1##p2##p3
|
||||
|
||||
#define STRINGIFY_(val) #val
|
||||
/** Converts a macro argument into a character constant.
|
||||
*/
|
||||
#define STRINGIFY(val) STRINGIFY_(val)
|
||||
|
||||
/** Counts number of elements inside the array
|
||||
*/
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
/**@brief Set a bit in the uint32 word.
|
||||
*
|
||||
* @param[in] W Word whose bit is being set.
|
||||
* @param[in] B Bit number in the word to be set.
|
||||
*/
|
||||
#define SET_BIT(W, B) ((W) |= (uint32_t)(1U << (B)))
|
||||
|
||||
|
||||
/**@brief Clears a bit in the uint32 word.
|
||||
*
|
||||
* @param[in] W Word whose bit is to be cleared.
|
||||
* @param[in] B Bit number in the word to be cleared.
|
||||
*/
|
||||
#define CLR_BIT(W, B) ((W) &= (~(uint32_t)(1U << (B))))
|
||||
|
||||
|
||||
/**@brief Checks if a bit is set.
|
||||
*
|
||||
* @param[in] W Word whose bit is to be checked.
|
||||
* @param[in] B Bit number in the word to be checked.
|
||||
*
|
||||
* @retval 1 if bit is set.
|
||||
* @retval 0 if bit is not set.
|
||||
*/
|
||||
#define IS_SET(W, B) (((W) >> (B)) & 1)
|
||||
|
||||
#define BIT_0 0x01 /**< The value of bit 0 */
|
||||
#define BIT_1 0x02 /**< The value of bit 1 */
|
||||
#define BIT_2 0x04 /**< The value of bit 2 */
|
||||
#define BIT_3 0x08 /**< The value of bit 3 */
|
||||
#define BIT_4 0x10 /**< The value of bit 4 */
|
||||
#define BIT_5 0x20 /**< The value of bit 5 */
|
||||
#define BIT_6 0x40 /**< The value of bit 6 */
|
||||
#define BIT_7 0x80 /**< The value of bit 7 */
|
||||
#define BIT_8 0x0100 /**< The value of bit 8 */
|
||||
#define BIT_9 0x0200 /**< The value of bit 9 */
|
||||
#define BIT_10 0x0400 /**< The value of bit 10 */
|
||||
#define BIT_11 0x0800 /**< The value of bit 11 */
|
||||
#define BIT_12 0x1000 /**< The value of bit 12 */
|
||||
#define BIT_13 0x2000 /**< The value of bit 13 */
|
||||
#define BIT_14 0x4000 /**< The value of bit 14 */
|
||||
#define BIT_15 0x8000 /**< The value of bit 15 */
|
||||
#define BIT_16 0x00010000 /**< The value of bit 16 */
|
||||
#define BIT_17 0x00020000 /**< The value of bit 17 */
|
||||
#define BIT_18 0x00040000 /**< The value of bit 18 */
|
||||
#define BIT_19 0x00080000 /**< The value of bit 19 */
|
||||
#define BIT_20 0x00100000 /**< The value of bit 20 */
|
||||
#define BIT_21 0x00200000 /**< The value of bit 21 */
|
||||
#define BIT_22 0x00400000 /**< The value of bit 22 */
|
||||
#define BIT_23 0x00800000 /**< The value of bit 23 */
|
||||
#define BIT_24 0x01000000 /**< The value of bit 24 */
|
||||
#define BIT_25 0x02000000 /**< The value of bit 25 */
|
||||
#define BIT_26 0x04000000 /**< The value of bit 26 */
|
||||
#define BIT_27 0x08000000 /**< The value of bit 27 */
|
||||
#define BIT_28 0x10000000 /**< The value of bit 28 */
|
||||
#define BIT_29 0x20000000 /**< The value of bit 29 */
|
||||
#define BIT_30 0x40000000 /**< The value of bit 30 */
|
||||
#define BIT_31 0x80000000 /**< The value of bit 31 */
|
||||
|
||||
#define UNUSED_VARIABLE(X) ((void)(X))
|
||||
#define UNUSED_PARAMETER(X) UNUSED_VARIABLE(X)
|
||||
#define UNUSED_RETURN_VALUE(X) UNUSED_VARIABLE(X)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NORDIC_COMMON_H__
|
||||
|
||||
+122
-122
@@ -1,122 +1,122 @@
|
||||
/**
|
||||
* Copyright (c) 2006 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @file
|
||||
* @brief Utilities for verifying program logic
|
||||
*/
|
||||
|
||||
#ifndef NRF_ASSERT_H_
|
||||
#define NRF_ASSERT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "nrf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Function for handling assertions.
|
||||
*
|
||||
*
|
||||
* @note
|
||||
* This function is called when an assertion has triggered.
|
||||
*
|
||||
* @note
|
||||
* This function is deprecated and will be removed in future releases.
|
||||
* Use app_error_fault_handler instead.
|
||||
*
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
//lint -save -esym(14, assert_nrf_callback)
|
||||
void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name);
|
||||
//lint -restore
|
||||
|
||||
#if (defined(DEBUG_NRF) || defined(DEBUG_NRF_USER))
|
||||
#define NRF_ASSERT_PRESENT 1
|
||||
#else
|
||||
#define NRF_ASSERT_PRESENT 0
|
||||
#endif
|
||||
|
||||
//#if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER)
|
||||
|
||||
/*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. */
|
||||
|
||||
#ifdef _lint
|
||||
#define ASSERT(expr) \
|
||||
if (expr) \
|
||||
{ \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
while (1); \
|
||||
}
|
||||
#else //_lint
|
||||
#define ASSERT(expr) \
|
||||
if (NRF_ASSERT_PRESENT) \
|
||||
{ \
|
||||
if (expr) \
|
||||
{ \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
assert_nrf_callback((uint16_t)__LINE__, (uint8_t *)__FILE__); \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_ASSERT_H_ */
|
||||
/**
|
||||
* Copyright (c) 2006 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @file
|
||||
* @brief Utilities for verifying program logic
|
||||
*/
|
||||
|
||||
#ifndef NRF_ASSERT_H_
|
||||
#define NRF_ASSERT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "nrf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Function for handling assertions.
|
||||
*
|
||||
*
|
||||
* @note
|
||||
* This function is called when an assertion has triggered.
|
||||
*
|
||||
* @note
|
||||
* This function is deprecated and will be removed in future releases.
|
||||
* Use app_error_fault_handler instead.
|
||||
*
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
//lint -save -esym(14, assert_nrf_callback)
|
||||
void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name);
|
||||
//lint -restore
|
||||
|
||||
#if (defined(DEBUG_NRF) || defined(DEBUG_NRF_USER))
|
||||
#define NRF_ASSERT_PRESENT 1
|
||||
#else
|
||||
#define NRF_ASSERT_PRESENT 0
|
||||
#endif
|
||||
|
||||
//#if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER)
|
||||
|
||||
/*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. */
|
||||
|
||||
#ifdef _lint
|
||||
#define ASSERT(expr) \
|
||||
if (expr) \
|
||||
{ \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
while (1); \
|
||||
}
|
||||
#else //_lint
|
||||
#define ASSERT(expr) \
|
||||
if (NRF_ASSERT_PRESENT) \
|
||||
{ \
|
||||
if (expr) \
|
||||
{ \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
assert_nrf_callback((uint16_t)__LINE__, (uint8_t *)__FILE__); \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_ASSERT_H_ */
|
||||
|
||||
+95
-95
@@ -1,95 +1,95 @@
|
||||
/**
|
||||
* Copyright (c) 2012 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/* Header guard */
|
||||
|
||||
#ifndef SOFTDEVICE_PRESENT
|
||||
|
||||
/**
|
||||
@defgroup nrf_error Global Error Codes
|
||||
@{
|
||||
|
||||
@brief Global Error definitions
|
||||
*/
|
||||
|
||||
#ifndef NRF_ERROR_H__
|
||||
#define NRF_ERROR_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup NRF_ERRORS_BASE Error Codes Base number definitions
|
||||
* @{ */
|
||||
#define NRF_ERROR_BASE_NUM (0x0) ///< Global error base
|
||||
#define NRF_ERROR_SDM_BASE_NUM (0x1000) ///< SDM error base
|
||||
#define NRF_ERROR_SOC_BASE_NUM (0x2000) ///< SoC error base
|
||||
#define NRF_ERROR_STK_BASE_NUM (0x3000) ///< STK error base
|
||||
/** @} */
|
||||
|
||||
#define NRF_SUCCESS (NRF_ERROR_BASE_NUM + 0) ///< Successful command
|
||||
#define NRF_ERROR_SVC_HANDLER_MISSING (NRF_ERROR_BASE_NUM + 1) ///< SVC handler is missing
|
||||
#define NRF_ERROR_SOFTDEVICE_NOT_ENABLED (NRF_ERROR_BASE_NUM + 2) ///< SoftDevice has not been enabled
|
||||
#define NRF_ERROR_INTERNAL (NRF_ERROR_BASE_NUM + 3) ///< Internal Error
|
||||
#define NRF_ERROR_NO_MEM (NRF_ERROR_BASE_NUM + 4) ///< No Memory for operation
|
||||
#define NRF_ERROR_NOT_FOUND (NRF_ERROR_BASE_NUM + 5) ///< Not found
|
||||
#define NRF_ERROR_NOT_SUPPORTED (NRF_ERROR_BASE_NUM + 6) ///< Not supported
|
||||
#define NRF_ERROR_INVALID_PARAM (NRF_ERROR_BASE_NUM + 7) ///< Invalid Parameter
|
||||
#define NRF_ERROR_INVALID_STATE (NRF_ERROR_BASE_NUM + 8) ///< Invalid state, operation disallowed in this state
|
||||
#define NRF_ERROR_INVALID_LENGTH (NRF_ERROR_BASE_NUM + 9) ///< Invalid Length
|
||||
#define NRF_ERROR_INVALID_FLAGS (NRF_ERROR_BASE_NUM + 10) ///< Invalid Flags
|
||||
#define NRF_ERROR_INVALID_DATA (NRF_ERROR_BASE_NUM + 11) ///< Invalid Data
|
||||
#define NRF_ERROR_DATA_SIZE (NRF_ERROR_BASE_NUM + 12) ///< Data size exceeds limit
|
||||
#define NRF_ERROR_TIMEOUT (NRF_ERROR_BASE_NUM + 13) ///< Operation timed out
|
||||
#define NRF_ERROR_NULL (NRF_ERROR_BASE_NUM + 14) ///< Null Pointer
|
||||
#define NRF_ERROR_FORBIDDEN (NRF_ERROR_BASE_NUM + 15) ///< Forbidden Operation
|
||||
#define NRF_ERROR_INVALID_ADDR (NRF_ERROR_BASE_NUM + 16) ///< Bad Memory Address
|
||||
#define NRF_ERROR_BUSY (NRF_ERROR_BASE_NUM + 17) ///< Busy
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_ERROR_H__
|
||||
|
||||
/**
|
||||
@}
|
||||
*/
|
||||
|
||||
#endif // SOFTDEVICE_PRESENT
|
||||
/**
|
||||
* Copyright (c) 2012 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/* Header guard */
|
||||
|
||||
#ifndef SOFTDEVICE_PRESENT
|
||||
|
||||
/**
|
||||
@defgroup nrf_error Global Error Codes
|
||||
@{
|
||||
|
||||
@brief Global Error definitions
|
||||
*/
|
||||
|
||||
#ifndef NRF_ERROR_H__
|
||||
#define NRF_ERROR_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup NRF_ERRORS_BASE Error Codes Base number definitions
|
||||
* @{ */
|
||||
#define NRF_ERROR_BASE_NUM (0x0) ///< Global error base
|
||||
#define NRF_ERROR_SDM_BASE_NUM (0x1000) ///< SDM error base
|
||||
#define NRF_ERROR_SOC_BASE_NUM (0x2000) ///< SoC error base
|
||||
#define NRF_ERROR_STK_BASE_NUM (0x3000) ///< STK error base
|
||||
/** @} */
|
||||
|
||||
#define NRF_SUCCESS (NRF_ERROR_BASE_NUM + 0) ///< Successful command
|
||||
#define NRF_ERROR_SVC_HANDLER_MISSING (NRF_ERROR_BASE_NUM + 1) ///< SVC handler is missing
|
||||
#define NRF_ERROR_SOFTDEVICE_NOT_ENABLED (NRF_ERROR_BASE_NUM + 2) ///< SoftDevice has not been enabled
|
||||
#define NRF_ERROR_INTERNAL (NRF_ERROR_BASE_NUM + 3) ///< Internal Error
|
||||
#define NRF_ERROR_NO_MEM (NRF_ERROR_BASE_NUM + 4) ///< No Memory for operation
|
||||
#define NRF_ERROR_NOT_FOUND (NRF_ERROR_BASE_NUM + 5) ///< Not found
|
||||
#define NRF_ERROR_NOT_SUPPORTED (NRF_ERROR_BASE_NUM + 6) ///< Not supported
|
||||
#define NRF_ERROR_INVALID_PARAM (NRF_ERROR_BASE_NUM + 7) ///< Invalid Parameter
|
||||
#define NRF_ERROR_INVALID_STATE (NRF_ERROR_BASE_NUM + 8) ///< Invalid state, operation disallowed in this state
|
||||
#define NRF_ERROR_INVALID_LENGTH (NRF_ERROR_BASE_NUM + 9) ///< Invalid Length
|
||||
#define NRF_ERROR_INVALID_FLAGS (NRF_ERROR_BASE_NUM + 10) ///< Invalid Flags
|
||||
#define NRF_ERROR_INVALID_DATA (NRF_ERROR_BASE_NUM + 11) ///< Invalid Data
|
||||
#define NRF_ERROR_DATA_SIZE (NRF_ERROR_BASE_NUM + 12) ///< Data size exceeds limit
|
||||
#define NRF_ERROR_TIMEOUT (NRF_ERROR_BASE_NUM + 13) ///< Operation timed out
|
||||
#define NRF_ERROR_NULL (NRF_ERROR_BASE_NUM + 14) ///< Null Pointer
|
||||
#define NRF_ERROR_FORBIDDEN (NRF_ERROR_BASE_NUM + 15) ///< Forbidden Operation
|
||||
#define NRF_ERROR_INVALID_ADDR (NRF_ERROR_BASE_NUM + 16) ///< Bad Memory Address
|
||||
#define NRF_ERROR_BUSY (NRF_ERROR_BASE_NUM + 17) ///< Busy
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_ERROR_H__
|
||||
|
||||
/**
|
||||
@}
|
||||
*/
|
||||
|
||||
#endif // SOFTDEVICE_PRESENT
|
||||
|
||||
+291
-291
@@ -1,291 +1,291 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@file
|
||||
*
|
||||
* @defgroup nrf_log Logger module
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief The nrf_log module interface.
|
||||
*/
|
||||
|
||||
#ifndef NRF_LOG_H_
|
||||
#define NRF_LOG_H_
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include "nrf_section.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_LOG)
|
||||
#include "nrf_strerror.h"
|
||||
#define NRF_LOG_ERROR_STRING_GET(code) nrf_strerror_get(code)
|
||||
#else
|
||||
#define NRF_LOG_ERROR_STRING_GET(code) ""
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Severity level for the module.
|
||||
*
|
||||
* The severity level can be defined in a module to override the default.
|
||||
*/
|
||||
#ifndef NRF_LOG_LEVEL
|
||||
#define NRF_LOG_LEVEL NRF_LOG_DEFAULT_LEVEL
|
||||
#endif
|
||||
|
||||
/** @brief Initial severity if filtering is enabled.
|
||||
*/
|
||||
#ifndef NRF_LOG_INITIAL_LEVEL
|
||||
#define NRF_LOG_INITIAL_LEVEL NRF_LOG_LEVEL
|
||||
#endif
|
||||
|
||||
|
||||
#include "nrf_log_internal.h"
|
||||
|
||||
/** @def NRF_LOG_ERROR
|
||||
* @brief Macro for logging error messages. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_WARNING
|
||||
* @brief Macro for logging error messages. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes warning logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_INFO
|
||||
* @brief Macro for logging error messages. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes info logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_DEBUG
|
||||
* @brief Macro for logging error messages. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes debug logs.
|
||||
*/
|
||||
|
||||
#define NRF_LOG_ERROR(...) NRF_LOG_INTERNAL_ERROR(__VA_ARGS__)
|
||||
#define NRF_LOG_WARNING(...) NRF_LOG_INTERNAL_WARNING( __VA_ARGS__)
|
||||
#define NRF_LOG_INFO(...) NRF_LOG_INTERNAL_INFO( __VA_ARGS__)
|
||||
#define NRF_LOG_DEBUG(...) NRF_LOG_INTERNAL_DEBUG( __VA_ARGS__)
|
||||
|
||||
/** @def NRF_LOG_INST_ERROR
|
||||
* @brief Macro for logging error messages for a given module instance. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_INST_WARNING
|
||||
* @brief Macro for logging error messages for a given module instance. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_INST_INFO
|
||||
* @brief Macro for logging error messages for a given module instance. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_INST_DEBUG
|
||||
* @brief Macro for logging error messages for given module instance. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*/
|
||||
#define NRF_LOG_INST_ERROR(p_inst,...) NRF_LOG_INTERNAL_INST_ERROR(p_inst,__VA_ARGS__)
|
||||
#define NRF_LOG_INST_WARNING(p_inst,...) NRF_LOG_INTERNAL_INST_WARNING(p_inst,__VA_ARGS__)
|
||||
#define NRF_LOG_INST_INFO(p_inst,...) NRF_LOG_INTERNAL_INST_INFO(p_inst, __VA_ARGS__)
|
||||
#define NRF_LOG_INST_DEBUG(p_inst,...) NRF_LOG_INTERNAL_INST_DEBUG(p_inst, __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Macro for logging a formatted string without any prefix or timestamp.
|
||||
*/
|
||||
#define NRF_LOG_RAW_INFO(...) NRF_LOG_INTERNAL_RAW_INFO( __VA_ARGS__)
|
||||
|
||||
/** @def NRF_LOG_HEXDUMP_ERROR
|
||||
* @brief Macro for logging raw bytes.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_WARNING
|
||||
* @brief Macro for logging raw bytes.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes warning logs.
|
||||
*
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_INFO
|
||||
* @brief Macro for logging raw bytes.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes info logs.
|
||||
*
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_DEBUG
|
||||
* @brief Macro for logging raw bytes.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes debug logs.
|
||||
*
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
#define NRF_LOG_HEXDUMP_ERROR(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_ERROR(p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_WARNING(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_WARNING(p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_INFO(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_INFO(p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_DEBUG(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_DEBUG(p_data, len)
|
||||
|
||||
/** @def NRF_LOG_HEXDUMP_INST_ERROR
|
||||
* @brief Macro for logging raw bytes for a specific module instance.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_INST_WARNING
|
||||
* @brief Macro for logging raw bytes for a specific module instance.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_INST_INFO
|
||||
* @brief Macro for logging raw bytes for a specific module instance.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_INST_DEBUG
|
||||
* @brief Macro for logging raw bytes for a specific module instance.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
#define NRF_LOG_HEXDUMP_INST_ERROR(p_inst, p_data, len) NRF_LOG_INTERNAL_HEXDUMP_INST_ERROR(p_inst, p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_INST_WARNING(p_inst, p_data, len) NRF_LOG_INTERNAL_HEXDUMP_INST_WARNING(p_inst, p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_INST_INFO(p_inst, p_data, len) NRF_LOG_INTERNAL_HEXDUMP_INST_INFO(p_inst, p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_INST_DEBUG(p_inst, p_data, len) NRF_LOG_INTERNAL_HEXDUMP_INST_DEBUG(p_inst, p_data, len)
|
||||
|
||||
/**
|
||||
* @brief Macro for logging hexdump without any prefix or timestamp.
|
||||
*/
|
||||
#define NRF_LOG_RAW_HEXDUMP_INFO(p_data, len) NRF_LOG_INTERNAL_RAW_HEXDUMP_INFO(p_data, len)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Macro for copying a string to internal logger buffer if logs are deferred.
|
||||
*
|
||||
* @param _str String.
|
||||
*/
|
||||
#define NRF_LOG_PUSH(_str) NRF_LOG_INTERNAL_LOG_PUSH(_str)
|
||||
|
||||
/**
|
||||
* @brief Function for copying a string to the internal logger buffer if logs are deferred.
|
||||
*
|
||||
* Use this function to store a string that is volatile (for example allocated
|
||||
* on stack) or that may change before the deferred logs are processed. Such string is copied
|
||||
* into the internal logger buffer and is persistent until the log is processed.
|
||||
*
|
||||
* @note If the logs are not deferred, then this function returns the input parameter.
|
||||
*
|
||||
* @param p_str Pointer to the user string.
|
||||
*
|
||||
* @return Address to the location where the string is stored in the internal logger buffer.
|
||||
*/
|
||||
uint32_t nrf_log_push(char * const p_str);
|
||||
|
||||
/**
|
||||
* @brief Macro to be used in a formatted string to a pass float number to the log.
|
||||
*
|
||||
* Use this macro in a formatted string instead of the %f specifier together with
|
||||
* @ref NRF_LOG_FLOAT macro.
|
||||
* Example: NRF_LOG_INFO("My float number" NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(f)))
|
||||
*/
|
||||
#define NRF_LOG_FLOAT_MARKER "%s%d.%02d"
|
||||
|
||||
/**
|
||||
* @brief Macro for dissecting a float number into two numbers (integer and residuum).
|
||||
*/
|
||||
#define NRF_LOG_FLOAT(val) (uint32_t)(((val) < 0 && (val) > -1.0) ? "-" : ""), \
|
||||
(int32_t)(val), \
|
||||
(int32_t)((((val) > 0) ? (val) - (int32_t)(val) \
|
||||
: (int32_t)(val) - (val))*100)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Macro for registering an independent module.
|
||||
*
|
||||
* Registration creates set of dynamic (RAM) and constant variables associated with the module.
|
||||
*/
|
||||
#define NRF_LOG_MODULE_REGISTER() NRF_LOG_INTERNAL_MODULE_REGISTER()
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_LOG_H_
|
||||
|
||||
/** @} */
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@file
|
||||
*
|
||||
* @defgroup nrf_log Logger module
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief The nrf_log module interface.
|
||||
*/
|
||||
|
||||
#ifndef NRF_LOG_H_
|
||||
#define NRF_LOG_H_
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include "nrf_section.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_LOG)
|
||||
#include "nrf_strerror.h"
|
||||
#define NRF_LOG_ERROR_STRING_GET(code) nrf_strerror_get(code)
|
||||
#else
|
||||
#define NRF_LOG_ERROR_STRING_GET(code) ""
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Severity level for the module.
|
||||
*
|
||||
* The severity level can be defined in a module to override the default.
|
||||
*/
|
||||
#ifndef NRF_LOG_LEVEL
|
||||
#define NRF_LOG_LEVEL NRF_LOG_DEFAULT_LEVEL
|
||||
#endif
|
||||
|
||||
/** @brief Initial severity if filtering is enabled.
|
||||
*/
|
||||
#ifndef NRF_LOG_INITIAL_LEVEL
|
||||
#define NRF_LOG_INITIAL_LEVEL NRF_LOG_LEVEL
|
||||
#endif
|
||||
|
||||
|
||||
#include "nrf_log_internal.h"
|
||||
|
||||
/** @def NRF_LOG_ERROR
|
||||
* @brief Macro for logging error messages. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_WARNING
|
||||
* @brief Macro for logging error messages. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes warning logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_INFO
|
||||
* @brief Macro for logging error messages. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes info logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_DEBUG
|
||||
* @brief Macro for logging error messages. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes debug logs.
|
||||
*/
|
||||
|
||||
#define NRF_LOG_ERROR(...) NRF_LOG_INTERNAL_ERROR(__VA_ARGS__)
|
||||
#define NRF_LOG_WARNING(...) NRF_LOG_INTERNAL_WARNING( __VA_ARGS__)
|
||||
#define NRF_LOG_INFO(...) NRF_LOG_INTERNAL_INFO( __VA_ARGS__)
|
||||
#define NRF_LOG_DEBUG(...) NRF_LOG_INTERNAL_DEBUG( __VA_ARGS__)
|
||||
|
||||
/** @def NRF_LOG_INST_ERROR
|
||||
* @brief Macro for logging error messages for a given module instance. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_INST_WARNING
|
||||
* @brief Macro for logging error messages for a given module instance. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_INST_INFO
|
||||
* @brief Macro for logging error messages for a given module instance. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*/
|
||||
|
||||
/** @def NRF_LOG_INST_DEBUG
|
||||
* @brief Macro for logging error messages for given module instance. It takes a printf-like, formatted
|
||||
* string with up to seven arguments.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
*
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*/
|
||||
#define NRF_LOG_INST_ERROR(p_inst,...) NRF_LOG_INTERNAL_INST_ERROR(p_inst,__VA_ARGS__)
|
||||
#define NRF_LOG_INST_WARNING(p_inst,...) NRF_LOG_INTERNAL_INST_WARNING(p_inst,__VA_ARGS__)
|
||||
#define NRF_LOG_INST_INFO(p_inst,...) NRF_LOG_INTERNAL_INST_INFO(p_inst, __VA_ARGS__)
|
||||
#define NRF_LOG_INST_DEBUG(p_inst,...) NRF_LOG_INTERNAL_INST_DEBUG(p_inst, __VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Macro for logging a formatted string without any prefix or timestamp.
|
||||
*/
|
||||
#define NRF_LOG_RAW_INFO(...) NRF_LOG_INTERNAL_RAW_INFO( __VA_ARGS__)
|
||||
|
||||
/** @def NRF_LOG_HEXDUMP_ERROR
|
||||
* @brief Macro for logging raw bytes.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_WARNING
|
||||
* @brief Macro for logging raw bytes.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes warning logs.
|
||||
*
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_INFO
|
||||
* @brief Macro for logging raw bytes.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes info logs.
|
||||
*
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_DEBUG
|
||||
* @brief Macro for logging raw bytes.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes debug logs.
|
||||
*
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
#define NRF_LOG_HEXDUMP_ERROR(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_ERROR(p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_WARNING(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_WARNING(p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_INFO(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_INFO(p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_DEBUG(p_data, len) NRF_LOG_INTERNAL_HEXDUMP_DEBUG(p_data, len)
|
||||
|
||||
/** @def NRF_LOG_HEXDUMP_INST_ERROR
|
||||
* @brief Macro for logging raw bytes for a specific module instance.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_INST_WARNING
|
||||
* @brief Macro for logging raw bytes for a specific module instance.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_INST_INFO
|
||||
* @brief Macro for logging raw bytes for a specific module instance.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
/** @def NRF_LOG_HEXDUMP_INST_DEBUG
|
||||
* @brief Macro for logging raw bytes for a specific module instance.
|
||||
* @details This macro is compiled only if @ref NRF_LOG_LEVEL includes error logs.
|
||||
*
|
||||
* @param p_inst Pointer to the instance with logging support.
|
||||
* @param p_data Pointer to data.
|
||||
* @param len Data length in bytes.
|
||||
*/
|
||||
#define NRF_LOG_HEXDUMP_INST_ERROR(p_inst, p_data, len) NRF_LOG_INTERNAL_HEXDUMP_INST_ERROR(p_inst, p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_INST_WARNING(p_inst, p_data, len) NRF_LOG_INTERNAL_HEXDUMP_INST_WARNING(p_inst, p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_INST_INFO(p_inst, p_data, len) NRF_LOG_INTERNAL_HEXDUMP_INST_INFO(p_inst, p_data, len)
|
||||
#define NRF_LOG_HEXDUMP_INST_DEBUG(p_inst, p_data, len) NRF_LOG_INTERNAL_HEXDUMP_INST_DEBUG(p_inst, p_data, len)
|
||||
|
||||
/**
|
||||
* @brief Macro for logging hexdump without any prefix or timestamp.
|
||||
*/
|
||||
#define NRF_LOG_RAW_HEXDUMP_INFO(p_data, len) NRF_LOG_INTERNAL_RAW_HEXDUMP_INFO(p_data, len)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Macro for copying a string to internal logger buffer if logs are deferred.
|
||||
*
|
||||
* @param _str String.
|
||||
*/
|
||||
#define NRF_LOG_PUSH(_str) NRF_LOG_INTERNAL_LOG_PUSH(_str)
|
||||
|
||||
/**
|
||||
* @brief Function for copying a string to the internal logger buffer if logs are deferred.
|
||||
*
|
||||
* Use this function to store a string that is volatile (for example allocated
|
||||
* on stack) or that may change before the deferred logs are processed. Such string is copied
|
||||
* into the internal logger buffer and is persistent until the log is processed.
|
||||
*
|
||||
* @note If the logs are not deferred, then this function returns the input parameter.
|
||||
*
|
||||
* @param p_str Pointer to the user string.
|
||||
*
|
||||
* @return Address to the location where the string is stored in the internal logger buffer.
|
||||
*/
|
||||
uint32_t nrf_log_push(char * const p_str);
|
||||
|
||||
/**
|
||||
* @brief Macro to be used in a formatted string to a pass float number to the log.
|
||||
*
|
||||
* Use this macro in a formatted string instead of the %f specifier together with
|
||||
* @ref NRF_LOG_FLOAT macro.
|
||||
* Example: NRF_LOG_INFO("My float number" NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(f)))
|
||||
*/
|
||||
#define NRF_LOG_FLOAT_MARKER "%s%d.%02d"
|
||||
|
||||
/**
|
||||
* @brief Macro for dissecting a float number into two numbers (integer and residuum).
|
||||
*/
|
||||
#define NRF_LOG_FLOAT(val) (uint32_t)(((val) < 0 && (val) > -1.0) ? "-" : ""), \
|
||||
(int32_t)(val), \
|
||||
(int32_t)((((val) > 0) ? (val) - (int32_t)(val) \
|
||||
: (int32_t)(val) - (val))*100)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Macro for registering an independent module.
|
||||
*
|
||||
* Registration creates set of dynamic (RAM) and constant variables associated with the module.
|
||||
*/
|
||||
#define NRF_LOG_MODULE_REGISTER() NRF_LOG_INTERNAL_MODULE_REGISTER()
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_LOG_H_
|
||||
|
||||
/** @} */
|
||||
|
||||
+528
-528
File diff suppressed because it is too large
Load Diff
+77
-77
@@ -1,77 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) 2013 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @cond */
|
||||
/**@file
|
||||
*
|
||||
* @ingroup experimental_api
|
||||
* @defgroup sdk_common SDK Common Header
|
||||
* @brief All common headers needed for SDK examples will be included here so that application
|
||||
* developer does not have to include headers on him/herself.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SDK_COMMON_H__
|
||||
#define SDK_COMMON_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "sdk_config.h"
|
||||
#include "nordic_common.h"
|
||||
#include "compiler_abstraction.h"
|
||||
#include "sdk_os.h"
|
||||
#include "sdk_errors.h"
|
||||
#include "app_util.h"
|
||||
#include "sdk_macros.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/** @} */
|
||||
/** @endcond */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_COMMON_H__
|
||||
|
||||
/**
|
||||
* Copyright (c) 2013 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @cond */
|
||||
/**@file
|
||||
*
|
||||
* @ingroup experimental_api
|
||||
* @defgroup sdk_common SDK Common Header
|
||||
* @brief All common headers needed for SDK examples will be included here so that application
|
||||
* developer does not have to include headers on him/herself.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SDK_COMMON_H__
|
||||
#define SDK_COMMON_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "sdk_config.h"
|
||||
#include "nordic_common.h"
|
||||
#include "compiler_abstraction.h"
|
||||
#include "sdk_os.h"
|
||||
#include "sdk_errors.h"
|
||||
#include "app_util.h"
|
||||
#include "sdk_macros.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/** @} */
|
||||
/** @endcond */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_COMMON_H__
|
||||
|
||||
|
||||
+781
-781
File diff suppressed because it is too large
Load Diff
+167
-167
@@ -1,167 +1,167 @@
|
||||
/**
|
||||
* Copyright (c) 2013 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@file
|
||||
*
|
||||
* @defgroup sdk_error SDK Error codes
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
* @{
|
||||
* @details Error codes are 32-bit unsigned integers with the most significant 16-bit reserved for
|
||||
* identifying the module where the error occurred while the least least significant LSB
|
||||
* are used to provide the cause or nature of error. Each module is assigned a 16-bit
|
||||
* unsigned integer. Which it will use to identify all errors that occurred in it. 16-bit
|
||||
* LSB range is with module id as the MSB in the 32-bit error code is reserved for the
|
||||
* module. As an example, if 0x8800 identifies a certain SDK module, all values from
|
||||
* 0x88000000 - 0x8800FFFF are reserved for this module.
|
||||
* It should be noted that common error reasons have been assigned values to make it
|
||||
* possible to decode error reason easily. As an example, lets module uninitialized has
|
||||
* been assigned an error code 0x000A0. Then, if application encounters an error code
|
||||
* 0xZZZZ00A0, it knows that it accessing a certain module without initializing it.
|
||||
* Apart from this, each module is allowed to define error codes that are not covered by
|
||||
* the common ones, however, these values are defined in a range that does not conflict
|
||||
* with common error values. For module, specific error however, it is possible that the
|
||||
* same error value is used by two different modules to indicated errors of very different
|
||||
* nature. If error is already defined by the NRF common error codes, these are reused.
|
||||
* A range is reserved for application as well, it can use this range for defining
|
||||
* application specific errors.
|
||||
*
|
||||
* @note Success code, NRF_SUCCESS, does not include any module identifier.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SDK_ERRORS_H__
|
||||
#define SDK_ERRORS_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "nrf_error.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup sdk_err_base Base defined for SDK Modules
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_SDK_ERROR_BASE (NRF_ERROR_BASE_NUM + 0x8000) /**< Base value defined for SDK module identifiers. */
|
||||
#define NRF_ERROR_SDK_COMMON_ERROR_BASE (NRF_ERROR_BASE_NUM + 0x0080) /**< Base error value to be used for SDK error values. */
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup sdk_module_codes Codes reserved as identification for module where the error occurred.
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_MEMORY_MANAGER_ERR_BASE (0x8100) /**< Base address for Memory Manager related errors. */
|
||||
#define NRF_ERROR_PERIPH_DRIVERS_ERR_BASE (0x8200) /**< Base address for Peripheral drivers related errors. */
|
||||
#define NRF_ERROR_GAZELLE_ERR_BASE (0x8300) /**< Base address for Gazelle related errors. */
|
||||
#define NRF_ERROR_BLE_IPSP_ERR_BASE (0x8400) /**< Base address for BLE IPSP related errors. */
|
||||
#define NRF_ERROR_CRYPTO_ERR_BASE (0x8500) /**< Base address for crypto related errors. */
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup sdk_iot_errors Codes reserved as identification for IoT errors.
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_IOT_ERR_BASE_START (0xA000)
|
||||
#define NRF_ERROR_IOT_ERR_BASE_STOP (0xAFFF)
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup sdk_common_errors Codes reserved as identification for common errors.
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_MODULE_NOT_INITIALIZED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0000) ///< Module not initialized
|
||||
#define NRF_ERROR_MUTEX_INIT_FAILED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0001) ///< Mutex initialization failed
|
||||
#define NRF_ERROR_MUTEX_LOCK_FAILED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0002) ///< Mutex lock failed
|
||||
#define NRF_ERROR_MUTEX_UNLOCK_FAILED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0003) ///< Mutex unlock failed
|
||||
#define NRF_ERROR_MUTEX_COND_INIT_FAILED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0004) ///< Mutex conditional initialization failed
|
||||
#define NRF_ERROR_MODULE_ALREADY_INITIALIZED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0005) ///< Module already initialized
|
||||
#define NRF_ERROR_STORAGE_FULL (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0006) ///< Storage full
|
||||
#define NRF_ERROR_API_NOT_IMPLEMENTED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0010) ///< API not implemented
|
||||
#define NRF_ERROR_FEATURE_NOT_ENABLED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0011) ///< Feature not enabled
|
||||
#define NRF_ERROR_IO_PENDING (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0012) ///< Input/Output pending
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup drv_specific_errors Error / status codes specific to drivers.
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_DRV_TWI_ERR_OVERRUN (NRF_ERROR_PERIPH_DRIVERS_ERR_BASE + 0x0000)
|
||||
#define NRF_ERROR_DRV_TWI_ERR_ANACK (NRF_ERROR_PERIPH_DRIVERS_ERR_BASE + 0x0001)
|
||||
#define NRF_ERROR_DRV_TWI_ERR_DNACK (NRF_ERROR_PERIPH_DRIVERS_ERR_BASE + 0x0002)
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup ble_ipsp_errors IPSP codes
|
||||
* @brief Error and status codes specific to IPSP.
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_BLE_IPSP_RX_PKT_TRUNCATED (NRF_ERROR_BLE_IPSP_ERR_BASE + 0x0000)
|
||||
#define NRF_ERROR_BLE_IPSP_CHANNEL_ALREADY_EXISTS (NRF_ERROR_BLE_IPSP_ERR_BASE + 0x0001)
|
||||
#define NRF_ERROR_BLE_IPSP_LINK_DISCONNECTED (NRF_ERROR_BLE_IPSP_ERR_BASE + 0x0002)
|
||||
#define NRF_ERROR_BLE_IPSP_PEER_REJECTED (NRF_ERROR_BLE_IPSP_ERR_BASE + 0x0003)
|
||||
/* @} */
|
||||
|
||||
|
||||
/**
|
||||
* @brief API Result.
|
||||
*
|
||||
* @details Indicates success or failure of an API procedure. In case of failure, a comprehensive
|
||||
* error code indicating cause or reason for failure is provided.
|
||||
*
|
||||
* Though called an API result, it could used in Asynchronous notifications callback along
|
||||
* with asynchronous callback as event result. This mechanism is employed when an event
|
||||
* marks the end of procedure initiated using API. API result, in this case, will only be
|
||||
* an indicative of whether the procedure has been requested successfully.
|
||||
*/
|
||||
typedef uint32_t ret_code_t;
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_ERRORS_H__
|
||||
/**
|
||||
* Copyright (c) 2013 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@file
|
||||
*
|
||||
* @defgroup sdk_error SDK Error codes
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
* @{
|
||||
* @details Error codes are 32-bit unsigned integers with the most significant 16-bit reserved for
|
||||
* identifying the module where the error occurred while the least least significant LSB
|
||||
* are used to provide the cause or nature of error. Each module is assigned a 16-bit
|
||||
* unsigned integer. Which it will use to identify all errors that occurred in it. 16-bit
|
||||
* LSB range is with module id as the MSB in the 32-bit error code is reserved for the
|
||||
* module. As an example, if 0x8800 identifies a certain SDK module, all values from
|
||||
* 0x88000000 - 0x8800FFFF are reserved for this module.
|
||||
* It should be noted that common error reasons have been assigned values to make it
|
||||
* possible to decode error reason easily. As an example, lets module uninitialized has
|
||||
* been assigned an error code 0x000A0. Then, if application encounters an error code
|
||||
* 0xZZZZ00A0, it knows that it accessing a certain module without initializing it.
|
||||
* Apart from this, each module is allowed to define error codes that are not covered by
|
||||
* the common ones, however, these values are defined in a range that does not conflict
|
||||
* with common error values. For module, specific error however, it is possible that the
|
||||
* same error value is used by two different modules to indicated errors of very different
|
||||
* nature. If error is already defined by the NRF common error codes, these are reused.
|
||||
* A range is reserved for application as well, it can use this range for defining
|
||||
* application specific errors.
|
||||
*
|
||||
* @note Success code, NRF_SUCCESS, does not include any module identifier.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SDK_ERRORS_H__
|
||||
#define SDK_ERRORS_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "nrf_error.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup sdk_err_base Base defined for SDK Modules
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_SDK_ERROR_BASE (NRF_ERROR_BASE_NUM + 0x8000) /**< Base value defined for SDK module identifiers. */
|
||||
#define NRF_ERROR_SDK_COMMON_ERROR_BASE (NRF_ERROR_BASE_NUM + 0x0080) /**< Base error value to be used for SDK error values. */
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup sdk_module_codes Codes reserved as identification for module where the error occurred.
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_MEMORY_MANAGER_ERR_BASE (0x8100) /**< Base address for Memory Manager related errors. */
|
||||
#define NRF_ERROR_PERIPH_DRIVERS_ERR_BASE (0x8200) /**< Base address for Peripheral drivers related errors. */
|
||||
#define NRF_ERROR_GAZELLE_ERR_BASE (0x8300) /**< Base address for Gazelle related errors. */
|
||||
#define NRF_ERROR_BLE_IPSP_ERR_BASE (0x8400) /**< Base address for BLE IPSP related errors. */
|
||||
#define NRF_ERROR_CRYPTO_ERR_BASE (0x8500) /**< Base address for crypto related errors. */
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup sdk_iot_errors Codes reserved as identification for IoT errors.
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_IOT_ERR_BASE_START (0xA000)
|
||||
#define NRF_ERROR_IOT_ERR_BASE_STOP (0xAFFF)
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup sdk_common_errors Codes reserved as identification for common errors.
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_MODULE_NOT_INITIALIZED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0000) ///< Module not initialized
|
||||
#define NRF_ERROR_MUTEX_INIT_FAILED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0001) ///< Mutex initialization failed
|
||||
#define NRF_ERROR_MUTEX_LOCK_FAILED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0002) ///< Mutex lock failed
|
||||
#define NRF_ERROR_MUTEX_UNLOCK_FAILED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0003) ///< Mutex unlock failed
|
||||
#define NRF_ERROR_MUTEX_COND_INIT_FAILED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0004) ///< Mutex conditional initialization failed
|
||||
#define NRF_ERROR_MODULE_ALREADY_INITIALIZED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0005) ///< Module already initialized
|
||||
#define NRF_ERROR_STORAGE_FULL (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0006) ///< Storage full
|
||||
#define NRF_ERROR_API_NOT_IMPLEMENTED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0010) ///< API not implemented
|
||||
#define NRF_ERROR_FEATURE_NOT_ENABLED (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0011) ///< Feature not enabled
|
||||
#define NRF_ERROR_IO_PENDING (NRF_ERROR_SDK_COMMON_ERROR_BASE + 0x0012) ///< Input/Output pending
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup drv_specific_errors Error / status codes specific to drivers.
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_DRV_TWI_ERR_OVERRUN (NRF_ERROR_PERIPH_DRIVERS_ERR_BASE + 0x0000)
|
||||
#define NRF_ERROR_DRV_TWI_ERR_ANACK (NRF_ERROR_PERIPH_DRIVERS_ERR_BASE + 0x0001)
|
||||
#define NRF_ERROR_DRV_TWI_ERR_DNACK (NRF_ERROR_PERIPH_DRIVERS_ERR_BASE + 0x0002)
|
||||
/** @} */
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup ble_ipsp_errors IPSP codes
|
||||
* @brief Error and status codes specific to IPSP.
|
||||
* @{
|
||||
*/
|
||||
#define NRF_ERROR_BLE_IPSP_RX_PKT_TRUNCATED (NRF_ERROR_BLE_IPSP_ERR_BASE + 0x0000)
|
||||
#define NRF_ERROR_BLE_IPSP_CHANNEL_ALREADY_EXISTS (NRF_ERROR_BLE_IPSP_ERR_BASE + 0x0001)
|
||||
#define NRF_ERROR_BLE_IPSP_LINK_DISCONNECTED (NRF_ERROR_BLE_IPSP_ERR_BASE + 0x0002)
|
||||
#define NRF_ERROR_BLE_IPSP_PEER_REJECTED (NRF_ERROR_BLE_IPSP_ERR_BASE + 0x0003)
|
||||
/* @} */
|
||||
|
||||
|
||||
/**
|
||||
* @brief API Result.
|
||||
*
|
||||
* @details Indicates success or failure of an API procedure. In case of failure, a comprehensive
|
||||
* error code indicating cause or reason for failure is provided.
|
||||
*
|
||||
* Though called an API result, it could used in Asynchronous notifications callback along
|
||||
* with asynchronous callback as event result. This mechanism is employed when an event
|
||||
* marks the end of procedure initiated using API. API result, in this case, will only be
|
||||
* an indicative of whether the procedure has been requested successfully.
|
||||
*/
|
||||
typedef uint32_t ret_code_t;
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_ERRORS_H__
|
||||
|
||||
+215
-215
@@ -1,215 +1,215 @@
|
||||
/**
|
||||
* Copyright (c) 2013 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@file
|
||||
*
|
||||
|
||||
* @defgroup sdk_common_macros SDK Common Header
|
||||
* @ingroup app_common
|
||||
* @brief Macros for parameter checking and similar tasks
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SDK_MACROS_H__
|
||||
#define SDK_MACROS_H__
|
||||
|
||||
#include "nrf_assert.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Macro for parameter checking.
|
||||
*
|
||||
* If @p _cond evaluates to true, does nothing. Otherwise,
|
||||
* if @p _module ## _PARAM_CHECK_DISABLED is @e not set (default), prints an error message
|
||||
* if @p _printfn is provided, and returns from the calling function context with code @p _err.
|
||||
* If @p _module ## _PARAM_CHECK_DISABLED is set, behaves like the ASSERT macro.
|
||||
*
|
||||
* Parameter checking implemented using this macro can be optionally turned off for release code.
|
||||
* Only disable runtime parameter checks if size if a major concern.
|
||||
*
|
||||
* @param _module The module name.
|
||||
* @param _cond The condition to be evaluated.
|
||||
* @param _err The error to be returned.
|
||||
* @param _printfn A printf-compatible function used to log the error.
|
||||
* Leave empty if no logging is needed.
|
||||
*
|
||||
* @hideinitializer
|
||||
*/
|
||||
/*lint -esym(666, NRF_PARAM_CHECK*) : Expression with side effects passed to macro */
|
||||
#define NRF_PARAM_CHECK(_module, _cond, _err, _printfn) \
|
||||
do \
|
||||
{ \
|
||||
if ((_cond)) \
|
||||
{ \
|
||||
/* Do nothing. */ \
|
||||
} \
|
||||
else if (!(_module ## _PARAM_CHECK_DISABLED)) \
|
||||
{ \
|
||||
_printfn("%s check failed in %s() with value 0x%x.", #_cond, __func__, _err); \
|
||||
return (_err); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
ASSERT((_cond)); \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
|
||||
/**@brief Macro for verifying statement to be true. It will cause the exterior function to return
|
||||
* err_code if the statement is not true.
|
||||
*
|
||||
* @param[in] statement Statement to test.
|
||||
* @param[in] err_code Error value to return if test was invalid.
|
||||
*
|
||||
* @retval nothing, but will cause the exterior function to return @p err_code if @p statement
|
||||
* is false.
|
||||
*/
|
||||
#define VERIFY_TRUE(statement, err_code) \
|
||||
do \
|
||||
{ \
|
||||
if (!(statement)) \
|
||||
{ \
|
||||
return err_code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/**@brief Macro for verifying statement to be true. It will cause the exterior function to return
|
||||
* if the statement is not true.
|
||||
*
|
||||
* @param[in] statement Statement to test.
|
||||
*/
|
||||
#define VERIFY_TRUE_VOID(statement) VERIFY_TRUE((statement), )
|
||||
|
||||
|
||||
/**@brief Macro for verifying statement to be false. It will cause the exterior function to return
|
||||
* err_code if the statement is not false.
|
||||
*
|
||||
* @param[in] statement Statement to test.
|
||||
* @param[in] err_code Error value to return if test was invalid.
|
||||
*
|
||||
* @retval nothing, but will cause the exterior function to return @p err_code if @p statement
|
||||
* is true.
|
||||
*/
|
||||
#define VERIFY_FALSE(statement, err_code) \
|
||||
do \
|
||||
{ \
|
||||
if ((statement)) \
|
||||
{ \
|
||||
return err_code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/**@brief Macro for verifying statement to be false. It will cause the exterior function to return
|
||||
* if the statement is not false.
|
||||
*
|
||||
* @param[in] statement Statement to test.
|
||||
*/
|
||||
#define VERIFY_FALSE_VOID(statement) VERIFY_FALSE((statement), )
|
||||
|
||||
|
||||
/**@brief Macro for verifying that a function returned NRF_SUCCESS. It will cause the exterior
|
||||
* function to return error code of statement if it is not @ref NRF_SUCCESS.
|
||||
*
|
||||
* @param[in] statement Statement to check against NRF_SUCCESS.
|
||||
*/
|
||||
#define VERIFY_SUCCESS(statement) \
|
||||
do \
|
||||
{ \
|
||||
uint32_t _err_code = (uint32_t) (statement); \
|
||||
if (_err_code != NRF_SUCCESS) \
|
||||
{ \
|
||||
return _err_code; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
/**@brief Macro for verifying that a function returned NRF_SUCCESS. It will cause the exterior
|
||||
* function to return if the err_code is not @ref NRF_SUCCESS.
|
||||
*
|
||||
* @param[in] err_code The error code to check.
|
||||
*/
|
||||
#define VERIFY_SUCCESS_VOID(err_code) VERIFY_TRUE_VOID((err_code) == NRF_SUCCESS)
|
||||
|
||||
|
||||
/**@brief Macro for verifying that the module is initialized. It will cause the exterior function to
|
||||
* return @ref NRF_ERROR_INVALID_STATE if not.
|
||||
*
|
||||
* @note MODULE_INITIALIZED must be defined in each module using this macro. MODULE_INITIALIZED
|
||||
* should be true if the module is initialized, false if not.
|
||||
*/
|
||||
#define VERIFY_MODULE_INITIALIZED() VERIFY_TRUE((MODULE_INITIALIZED), NRF_ERROR_INVALID_STATE)
|
||||
|
||||
|
||||
/**@brief Macro for verifying that the module is initialized. It will cause the exterior function to
|
||||
* return if not.
|
||||
*
|
||||
* @note MODULE_INITIALIZED must be defined in each module using this macro. MODULE_INITIALIZED
|
||||
* should be true if the module is initialized, false if not.
|
||||
*/
|
||||
#define VERIFY_MODULE_INITIALIZED_VOID() VERIFY_TRUE_VOID((MODULE_INITIALIZED))
|
||||
|
||||
|
||||
/**@brief Macro for verifying that the module is initialized. It will cause the exterior function to
|
||||
* return if not.
|
||||
*
|
||||
* @param[in] param The variable to check if is NULL.
|
||||
*/
|
||||
#define VERIFY_PARAM_NOT_NULL(param) VERIFY_FALSE(((param) == NULL), NRF_ERROR_NULL)
|
||||
|
||||
|
||||
/**@brief Macro for verifying that the module is initialized. It will cause the exterior function to
|
||||
* return if not.
|
||||
*
|
||||
* @param[in] param The variable to check if is NULL.
|
||||
*/
|
||||
#define VERIFY_PARAM_NOT_NULL_VOID(param) VERIFY_FALSE_VOID(((param) == NULL))
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_MACROS_H__
|
||||
|
||||
/**
|
||||
* Copyright (c) 2013 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@file
|
||||
*
|
||||
|
||||
* @defgroup sdk_common_macros SDK Common Header
|
||||
* @ingroup app_common
|
||||
* @brief Macros for parameter checking and similar tasks
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SDK_MACROS_H__
|
||||
#define SDK_MACROS_H__
|
||||
|
||||
#include "nrf_assert.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Macro for parameter checking.
|
||||
*
|
||||
* If @p _cond evaluates to true, does nothing. Otherwise,
|
||||
* if @p _module ## _PARAM_CHECK_DISABLED is @e not set (default), prints an error message
|
||||
* if @p _printfn is provided, and returns from the calling function context with code @p _err.
|
||||
* If @p _module ## _PARAM_CHECK_DISABLED is set, behaves like the ASSERT macro.
|
||||
*
|
||||
* Parameter checking implemented using this macro can be optionally turned off for release code.
|
||||
* Only disable runtime parameter checks if size if a major concern.
|
||||
*
|
||||
* @param _module The module name.
|
||||
* @param _cond The condition to be evaluated.
|
||||
* @param _err The error to be returned.
|
||||
* @param _printfn A printf-compatible function used to log the error.
|
||||
* Leave empty if no logging is needed.
|
||||
*
|
||||
* @hideinitializer
|
||||
*/
|
||||
/*lint -esym(666, NRF_PARAM_CHECK*) : Expression with side effects passed to macro */
|
||||
#define NRF_PARAM_CHECK(_module, _cond, _err, _printfn) \
|
||||
do \
|
||||
{ \
|
||||
if ((_cond)) \
|
||||
{ \
|
||||
/* Do nothing. */ \
|
||||
} \
|
||||
else if (!(_module ## _PARAM_CHECK_DISABLED)) \
|
||||
{ \
|
||||
_printfn("%s check failed in %s() with value 0x%x.", #_cond, __func__, _err); \
|
||||
return (_err); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
ASSERT((_cond)); \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
|
||||
/**@brief Macro for verifying statement to be true. It will cause the exterior function to return
|
||||
* err_code if the statement is not true.
|
||||
*
|
||||
* @param[in] statement Statement to test.
|
||||
* @param[in] err_code Error value to return if test was invalid.
|
||||
*
|
||||
* @retval nothing, but will cause the exterior function to return @p err_code if @p statement
|
||||
* is false.
|
||||
*/
|
||||
#define VERIFY_TRUE(statement, err_code) \
|
||||
do \
|
||||
{ \
|
||||
if (!(statement)) \
|
||||
{ \
|
||||
return err_code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/**@brief Macro for verifying statement to be true. It will cause the exterior function to return
|
||||
* if the statement is not true.
|
||||
*
|
||||
* @param[in] statement Statement to test.
|
||||
*/
|
||||
#define VERIFY_TRUE_VOID(statement) VERIFY_TRUE((statement), )
|
||||
|
||||
|
||||
/**@brief Macro for verifying statement to be false. It will cause the exterior function to return
|
||||
* err_code if the statement is not false.
|
||||
*
|
||||
* @param[in] statement Statement to test.
|
||||
* @param[in] err_code Error value to return if test was invalid.
|
||||
*
|
||||
* @retval nothing, but will cause the exterior function to return @p err_code if @p statement
|
||||
* is true.
|
||||
*/
|
||||
#define VERIFY_FALSE(statement, err_code) \
|
||||
do \
|
||||
{ \
|
||||
if ((statement)) \
|
||||
{ \
|
||||
return err_code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/**@brief Macro for verifying statement to be false. It will cause the exterior function to return
|
||||
* if the statement is not false.
|
||||
*
|
||||
* @param[in] statement Statement to test.
|
||||
*/
|
||||
#define VERIFY_FALSE_VOID(statement) VERIFY_FALSE((statement), )
|
||||
|
||||
|
||||
/**@brief Macro for verifying that a function returned NRF_SUCCESS. It will cause the exterior
|
||||
* function to return error code of statement if it is not @ref NRF_SUCCESS.
|
||||
*
|
||||
* @param[in] statement Statement to check against NRF_SUCCESS.
|
||||
*/
|
||||
#define VERIFY_SUCCESS(statement) \
|
||||
do \
|
||||
{ \
|
||||
uint32_t _err_code = (uint32_t) (statement); \
|
||||
if (_err_code != NRF_SUCCESS) \
|
||||
{ \
|
||||
return _err_code; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
/**@brief Macro for verifying that a function returned NRF_SUCCESS. It will cause the exterior
|
||||
* function to return if the err_code is not @ref NRF_SUCCESS.
|
||||
*
|
||||
* @param[in] err_code The error code to check.
|
||||
*/
|
||||
#define VERIFY_SUCCESS_VOID(err_code) VERIFY_TRUE_VOID((err_code) == NRF_SUCCESS)
|
||||
|
||||
|
||||
/**@brief Macro for verifying that the module is initialized. It will cause the exterior function to
|
||||
* return @ref NRF_ERROR_INVALID_STATE if not.
|
||||
*
|
||||
* @note MODULE_INITIALIZED must be defined in each module using this macro. MODULE_INITIALIZED
|
||||
* should be true if the module is initialized, false if not.
|
||||
*/
|
||||
#define VERIFY_MODULE_INITIALIZED() VERIFY_TRUE((MODULE_INITIALIZED), NRF_ERROR_INVALID_STATE)
|
||||
|
||||
|
||||
/**@brief Macro for verifying that the module is initialized. It will cause the exterior function to
|
||||
* return if not.
|
||||
*
|
||||
* @note MODULE_INITIALIZED must be defined in each module using this macro. MODULE_INITIALIZED
|
||||
* should be true if the module is initialized, false if not.
|
||||
*/
|
||||
#define VERIFY_MODULE_INITIALIZED_VOID() VERIFY_TRUE_VOID((MODULE_INITIALIZED))
|
||||
|
||||
|
||||
/**@brief Macro for verifying that the module is initialized. It will cause the exterior function to
|
||||
* return if not.
|
||||
*
|
||||
* @param[in] param The variable to check if is NULL.
|
||||
*/
|
||||
#define VERIFY_PARAM_NOT_NULL(param) VERIFY_FALSE(((param) == NULL), NRF_ERROR_NULL)
|
||||
|
||||
|
||||
/**@brief Macro for verifying that the module is initialized. It will cause the exterior function to
|
||||
* return if not.
|
||||
*
|
||||
* @param[in] param The variable to check if is NULL.
|
||||
*/
|
||||
#define VERIFY_PARAM_NOT_NULL_VOID(param) VERIFY_FALSE_VOID(((param) == NULL))
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_MACROS_H__
|
||||
|
||||
|
||||
+76
-76
@@ -1,76 +1,76 @@
|
||||
/**
|
||||
* Copyright (c) 2013 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @cond */
|
||||
/**@file
|
||||
*
|
||||
* @defgroup sdk_os SDK OS Abstraction
|
||||
* @ingroup experimental_api
|
||||
* @details In order to made SDK modules independent of use of an embedded OS, and permit
|
||||
* application with varied task architecture, SDK abstracts the OS specific
|
||||
* elements here in order to make all other modules agnostic to the OS or task
|
||||
* architecture.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SDK_OS_H__
|
||||
#define SDK_OS_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SDK_MUTEX_DEFINE(X)
|
||||
#define SDK_MUTEX_INIT(X)
|
||||
#define SDK_MUTEX_LOCK(X)
|
||||
#define SDK_MUTEX_UNLOCK(X)
|
||||
|
||||
/**
|
||||
* @defgroup os_data_type Data types.
|
||||
*/
|
||||
|
||||
/** @} */
|
||||
/** @endcond */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_OS_H__
|
||||
|
||||
/**
|
||||
* Copyright (c) 2013 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @cond */
|
||||
/**@file
|
||||
*
|
||||
* @defgroup sdk_os SDK OS Abstraction
|
||||
* @ingroup experimental_api
|
||||
* @details In order to made SDK modules independent of use of an embedded OS, and permit
|
||||
* application with varied task architecture, SDK abstracts the OS specific
|
||||
* elements here in order to make all other modules agnostic to the OS or task
|
||||
* architecture.
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SDK_OS_H__
|
||||
#define SDK_OS_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SDK_MUTEX_DEFINE(X)
|
||||
#define SDK_MUTEX_INIT(X)
|
||||
#define SDK_MUTEX_LOCK(X)
|
||||
#define SDK_MUTEX_UNLOCK(X)
|
||||
|
||||
/**
|
||||
* @defgroup os_data_type Data types.
|
||||
*/
|
||||
|
||||
/** @} */
|
||||
/** @endcond */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_OS_H__
|
||||
|
||||
|
||||
+86
-86
@@ -1,86 +1,86 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @file
|
||||
* @brief Definition file for resource usage by SoftDevice, ESB and Gazell.
|
||||
*/
|
||||
|
||||
#ifndef SDK_RESOURCES_H__
|
||||
#define SDK_RESOURCES_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(SOFTDEVICE_PRESENT) || defined (BLE_STACK_SUPPORT_REQD) || defined (ANT_STACK_SUPPORT_REQD)
|
||||
#include "nrf_sd_def.h"
|
||||
#else
|
||||
#define SD_PPI_RESTRICTED 0uL /**< 1 if PPI peripheral is restricted, 0 otherwise. */
|
||||
#define SD_PPI_CHANNELS_USED 0uL /**< PPI channels utilized by SotfDevice (not available to th spplication). */
|
||||
#define SD_PPI_GROUPS_USED 0uL /**< PPI groups utilized by SotfDevice (not available to th spplication). */
|
||||
#define SD_TIMERS_USED 0uL /**< Timers used by SoftDevice. */
|
||||
#define SD_SWI_USED 0uL /**< Software interrupts used by SoftDevice. */
|
||||
#endif
|
||||
|
||||
#ifdef GAZELL_PRESENT
|
||||
#include "nrf_gzll_resources.h"
|
||||
#else
|
||||
#define GZLL_PPI_CHANNELS_USED 0uL /**< PPI channels utilized by Gazell (not available to th spplication). */
|
||||
#define GZLL_TIMERS_USED 0uL /**< Timers used by Gazell. */
|
||||
#define GZLL_SWI_USED 0uL /**< Software interrupts used by Gazell */
|
||||
#endif
|
||||
|
||||
#ifdef ESB_PRESENT
|
||||
#include "nrf_esb_resources.h"
|
||||
#else
|
||||
#define ESB_PPI_CHANNELS_USED 0uL /**< PPI channels utilized by ESB (not available to th spplication). */
|
||||
#define ESB_TIMERS_USED 0uL /**< Timers used by ESB. */
|
||||
#define ESB_SWI_USED 0uL /**< Software interrupts used by ESB */
|
||||
#endif
|
||||
|
||||
#define NRF_PPI_CHANNELS_USED (SD_PPI_CHANNELS_USED | GZLL_PPI_CHANNELS_USED | ESB_PPI_CHANNELS_USED)
|
||||
#define NRF_PPI_GROUPS_USED (SD_PPI_GROUPS_USED)
|
||||
#define NRF_SWI_USED (SD_SWI_USED | GZLL_SWI_USED | ESB_SWI_USED)
|
||||
#define NRF_TIMERS_USED (SD_TIMERS_USED | GZLL_TIMERS_USED | ESB_TIMERS_USED)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_RESOURCES_H__
|
||||
/**
|
||||
* Copyright (c) 2015 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @file
|
||||
* @brief Definition file for resource usage by SoftDevice, ESB and Gazell.
|
||||
*/
|
||||
|
||||
#ifndef SDK_RESOURCES_H__
|
||||
#define SDK_RESOURCES_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(SOFTDEVICE_PRESENT) || defined (BLE_STACK_SUPPORT_REQD) || defined (ANT_STACK_SUPPORT_REQD)
|
||||
#include "nrf_sd_def.h"
|
||||
#else
|
||||
#define SD_PPI_RESTRICTED 0uL /**< 1 if PPI peripheral is restricted, 0 otherwise. */
|
||||
#define SD_PPI_CHANNELS_USED 0uL /**< PPI channels utilized by SotfDevice (not available to th spplication). */
|
||||
#define SD_PPI_GROUPS_USED 0uL /**< PPI groups utilized by SotfDevice (not available to th spplication). */
|
||||
#define SD_TIMERS_USED 0uL /**< Timers used by SoftDevice. */
|
||||
#define SD_SWI_USED 0uL /**< Software interrupts used by SoftDevice. */
|
||||
#endif
|
||||
|
||||
#ifdef GAZELL_PRESENT
|
||||
#include "nrf_gzll_resources.h"
|
||||
#else
|
||||
#define GZLL_PPI_CHANNELS_USED 0uL /**< PPI channels utilized by Gazell (not available to th spplication). */
|
||||
#define GZLL_TIMERS_USED 0uL /**< Timers used by Gazell. */
|
||||
#define GZLL_SWI_USED 0uL /**< Software interrupts used by Gazell */
|
||||
#endif
|
||||
|
||||
#ifdef ESB_PRESENT
|
||||
#include "nrf_esb_resources.h"
|
||||
#else
|
||||
#define ESB_PPI_CHANNELS_USED 0uL /**< PPI channels utilized by ESB (not available to th spplication). */
|
||||
#define ESB_TIMERS_USED 0uL /**< Timers used by ESB. */
|
||||
#define ESB_SWI_USED 0uL /**< Software interrupts used by ESB */
|
||||
#endif
|
||||
|
||||
#define NRF_PPI_CHANNELS_USED (SD_PPI_CHANNELS_USED | GZLL_PPI_CHANNELS_USED | ESB_PPI_CHANNELS_USED)
|
||||
#define NRF_PPI_GROUPS_USED (SD_PPI_GROUPS_USED)
|
||||
#define NRF_SWI_USED (SD_SWI_USED | GZLL_SWI_USED | ESB_SWI_USED)
|
||||
#define NRF_TIMERS_USED (SD_TIMERS_USED | GZLL_TIMERS_USED | ESB_TIMERS_USED)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SDK_RESOURCES_H__
|
||||
|
||||
+601
-601
File diff suppressed because it is too large
Load Diff
+297
-297
@@ -1,297 +1,297 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_DRV_CLOCK_H__
|
||||
#define NRF_DRV_CLOCK_H__
|
||||
|
||||
#include <nrfx_clock.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_drv_clock Clock driver - legacy layer
|
||||
* @{
|
||||
* @ingroup nrf_clock
|
||||
*
|
||||
* @brief Layer providing compatibility with the former API.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Clock events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_DRV_CLOCK_EVT_HFCLK_STARTED, ///< HFCLK has been started.
|
||||
NRF_DRV_CLOCK_EVT_LFCLK_STARTED, ///< LFCLK has been started.
|
||||
NRF_DRV_CLOCK_EVT_CAL_DONE, ///< Calibration is done.
|
||||
NRF_DRV_CLOCK_EVT_CAL_ABORTED, ///< Calibration has been aborted.
|
||||
} nrf_drv_clock_evt_type_t;
|
||||
|
||||
/**
|
||||
* @brief Clock event handler.
|
||||
*
|
||||
* @param[in] event Event.
|
||||
*/
|
||||
typedef void (*nrf_drv_clock_event_handler_t)(nrf_drv_clock_evt_type_t event);
|
||||
|
||||
// Forward declaration of the nrf_drv_clock_handler_item_t type.
|
||||
typedef struct nrf_drv_clock_handler_item_s nrf_drv_clock_handler_item_t;
|
||||
|
||||
struct nrf_drv_clock_handler_item_s
|
||||
{
|
||||
nrf_drv_clock_handler_item_t * p_next; ///< A pointer to the next handler that should be called when the clock is started.
|
||||
nrf_drv_clock_event_handler_t event_handler; ///< Function to be called when the clock is started.
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Function for checking if driver is already initialized
|
||||
*
|
||||
* @retval true Driver is initialized
|
||||
* @retval false Driver is uninitialized
|
||||
*/
|
||||
bool nrf_drv_clock_init_check(void);
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the nrf_drv_clock module.
|
||||
*
|
||||
* After initialization, the module is in power off state (clocks are not requested).
|
||||
*
|
||||
* @retval NRF_SUCCESS If the procedure was successful.
|
||||
* @retval NRF_ERROR_MODULE_ALREADY_INITIALIZED If the driver was already initialized.
|
||||
*/
|
||||
ret_code_t nrf_drv_clock_init(void);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the clock module.
|
||||
*
|
||||
*/
|
||||
void nrf_drv_clock_uninit(void);
|
||||
|
||||
/**
|
||||
* @brief Function for requesting the LFCLK.
|
||||
*
|
||||
* The low-frequency clock can be requested by different modules
|
||||
* or contexts. The driver ensures that the clock will be started only when it is requested
|
||||
* the first time. If the clock is not ready but it was already started, the handler item that is
|
||||
* provided as an input parameter is added to the list of handlers that will be notified
|
||||
* when the clock is started. If the clock is already enabled, user callback is called from the
|
||||
* current context.
|
||||
*
|
||||
* The first request will start the selected LFCLK source. If an event handler is
|
||||
* provided, it will be called once the LFCLK is started. If the LFCLK was already started at this
|
||||
* time, the event handler will be called from the context of this function. Additionally,
|
||||
* the @ref nrf_drv_clock_lfclk_is_running function can be polled to check if the clock has started.
|
||||
*
|
||||
* @note When a SoftDevice is enabled, the LFCLK is always running and the driver cannot control it.
|
||||
*
|
||||
* @note The handler item provided by the user cannot be an automatic variable.
|
||||
*
|
||||
* @param[in] p_handler_item A pointer to the event handler structure.
|
||||
*/
|
||||
void nrf_drv_clock_lfclk_request(nrf_drv_clock_handler_item_t * p_handler_item);
|
||||
|
||||
/**
|
||||
* @brief Function for releasing the LFCLK.
|
||||
*
|
||||
* If there are no more requests, the LFCLK source will be stopped.
|
||||
*
|
||||
* @note When a SoftDevice is enabled, the LFCLK is always running.
|
||||
*/
|
||||
void nrf_drv_clock_lfclk_release(void);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the LFCLK state.
|
||||
*
|
||||
* @retval true If the LFCLK is running.
|
||||
* @retval false If the LFCLK is not running.
|
||||
*/
|
||||
bool nrf_drv_clock_lfclk_is_running(void);
|
||||
|
||||
/**
|
||||
* @brief Function for requesting the high-accuracy source HFCLK.
|
||||
*
|
||||
* The high-accuracy source
|
||||
* can be requested by different modules or contexts. The driver ensures that the high-accuracy
|
||||
* clock will be started only when it is requested the first time. If the clock is not ready
|
||||
* but it was already started, the handler item that is provided as an input parameter is added
|
||||
* to the list of handlers that will be notified when the clock is started.
|
||||
*
|
||||
* If an event handler is provided, it will be called once the clock is started. If the clock was already
|
||||
* started at this time, the event handler will be called from the context of this function. Additionally,
|
||||
* the @ref nrf_drv_clock_hfclk_is_running function can be polled to check if the clock has started.
|
||||
*
|
||||
* @note If a SoftDevice is running, the clock is managed by the SoftDevice and all requests are handled by
|
||||
* the SoftDevice. This function cannot be called from all interrupt priority levels in that case.
|
||||
* @note The handler item provided by the user cannot be an automatic variable.
|
||||
*
|
||||
* @param[in] p_handler_item A pointer to the event handler structure.
|
||||
*/
|
||||
void nrf_drv_clock_hfclk_request(nrf_drv_clock_handler_item_t * p_handler_item);
|
||||
|
||||
/**
|
||||
* @brief Function for releasing the high-accuracy source HFCLK.
|
||||
*
|
||||
* If there are no more requests, the high-accuracy source will be released.
|
||||
*/
|
||||
void nrf_drv_clock_hfclk_release(void);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the HFCLK state.
|
||||
*
|
||||
* @retval true If the HFCLK is running (for \nRFXX XTAL source).
|
||||
* @retval false If the HFCLK is not running.
|
||||
*/
|
||||
bool nrf_drv_clock_hfclk_is_running(void);
|
||||
|
||||
/**
|
||||
* @brief Function for starting a single calibration process.
|
||||
*
|
||||
* This function can also delay the start of calibration by a user-specified value. The delay will use
|
||||
* a low-power timer that is part of the CLOCK module. @ref nrf_drv_clock_is_calibrating can be called to
|
||||
* check if calibration is still in progress. If a handler is provided, the user can be notified when
|
||||
* calibration is completed. The ext calibration can be started from the handler context.
|
||||
*
|
||||
* The calibration process consists of three phases:
|
||||
* - Delay (optional)
|
||||
* - Requesting the high-accuracy HFCLK
|
||||
* - Hardware-supported calibration
|
||||
*
|
||||
* @param[in] delay Time after which the calibration will be started (in 0.25 s units).
|
||||
* @param[in] handler NULL or user function to be called when calibration is completed or aborted.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the procedure was successful.
|
||||
* @retval NRF_ERROR_FORBIDDEN If a SoftDevice is present or the selected LFCLK source is not an RC oscillator.
|
||||
* @retval NRF_ERROR_INVALID_STATE If the low-frequency clock is off.
|
||||
* @retval NRF_ERROR_BUSY If calibration is in progress.
|
||||
*/
|
||||
ret_code_t nrf_drv_clock_calibration_start(uint8_t delay, nrf_drv_clock_event_handler_t handler);
|
||||
|
||||
/**
|
||||
* @brief Function for aborting calibration.
|
||||
*
|
||||
* This function aborts on-going calibration. If calibration was started, it cannot be stopped. If a handler
|
||||
* was provided by @ref nrf_drv_clock_calibration_start, this handler will be called once
|
||||
* aborted calibration is completed. @ref nrf_drv_clock_is_calibrating can also be used to check
|
||||
* if the system is calibrating.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the procedure was successful.
|
||||
* @retval NRF_ERROR_FORBIDDEN If a SoftDevice is present or the selected LFCLK source is not an RC oscillator.
|
||||
*/
|
||||
ret_code_t nrf_drv_clock_calibration_abort(void);
|
||||
|
||||
/**
|
||||
* @brief Function for checking if calibration is in progress.
|
||||
*
|
||||
* This function indicates that the system is
|
||||
* in calibration if it is in any of the calibration process phases (see @ref nrf_drv_clock_calibration_start).
|
||||
*
|
||||
* @param[out] p_is_calibrating True if calibration is in progress, false if not.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the procedure was successful.
|
||||
* @retval NRF_ERROR_FORBIDDEN If a SoftDevice is present or the selected LFCLK source is not an RC oscillator.
|
||||
*/
|
||||
ret_code_t nrf_drv_clock_is_calibrating(bool * p_is_calibrating);
|
||||
|
||||
/**@brief Function for returning a requested task address for the clock driver module.
|
||||
*
|
||||
* @param[in] task One of the peripheral tasks.
|
||||
*
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_drv_clock_ppi_task_addr(nrf_clock_task_t task);
|
||||
|
||||
/**@brief Function for returning a requested event address for the clock driver module.
|
||||
*
|
||||
* @param[in] event One of the peripheral events.
|
||||
*
|
||||
* @return Event address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_drv_clock_ppi_event_addr(nrf_clock_event_t event);
|
||||
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
/**
|
||||
* @brief Function called by the SoftDevice handler if an @ref NRF_SOC_EVTS event is received from the SoftDevice.
|
||||
*
|
||||
* @param[in] evt_id One of NRF_SOC_EVTS values.
|
||||
*/
|
||||
void nrf_drv_clock_on_soc_event(uint32_t evt_id);
|
||||
|
||||
/**
|
||||
* @brief Function called by the SoftDevice handler when the SoftDevice has been enabled.
|
||||
*
|
||||
* This function is called just after the SoftDevice has been properly enabled.
|
||||
* Its main purpose is to mark that LFCLK has been requested by SD.
|
||||
*/
|
||||
void nrf_drv_clock_on_sd_enable(void);
|
||||
|
||||
/**
|
||||
* @brief Function called by the SoftDevice handler when the SoftDevice has been disabled.
|
||||
*
|
||||
* This function is called just after the SoftDevice has been properly disabled.
|
||||
* It has two purposes:
|
||||
* 1. Releases the LFCLK from the SD.
|
||||
* 2. Reinitializes an interrupt after the SD releases POWER_CLOCK_IRQ.
|
||||
*/
|
||||
void nrf_drv_clock_on_sd_disable(void);
|
||||
|
||||
#endif
|
||||
/**
|
||||
*@}
|
||||
**/
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
__STATIC_INLINE uint32_t nrf_drv_clock_ppi_task_addr(nrf_clock_task_t task)
|
||||
{
|
||||
return nrf_clock_task_address_get(task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_drv_clock_ppi_event_addr(nrf_clock_event_t event)
|
||||
{
|
||||
return nrf_clock_event_address_get(event);
|
||||
}
|
||||
#endif //SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_DRV_CLOCK_H__
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_DRV_CLOCK_H__
|
||||
#define NRF_DRV_CLOCK_H__
|
||||
|
||||
#include <nrfx_clock.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_drv_clock Clock driver - legacy layer
|
||||
* @{
|
||||
* @ingroup nrf_clock
|
||||
*
|
||||
* @brief Layer providing compatibility with the former API.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Clock events.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_DRV_CLOCK_EVT_HFCLK_STARTED, ///< HFCLK has been started.
|
||||
NRF_DRV_CLOCK_EVT_LFCLK_STARTED, ///< LFCLK has been started.
|
||||
NRF_DRV_CLOCK_EVT_CAL_DONE, ///< Calibration is done.
|
||||
NRF_DRV_CLOCK_EVT_CAL_ABORTED, ///< Calibration has been aborted.
|
||||
} nrf_drv_clock_evt_type_t;
|
||||
|
||||
/**
|
||||
* @brief Clock event handler.
|
||||
*
|
||||
* @param[in] event Event.
|
||||
*/
|
||||
typedef void (*nrf_drv_clock_event_handler_t)(nrf_drv_clock_evt_type_t event);
|
||||
|
||||
// Forward declaration of the nrf_drv_clock_handler_item_t type.
|
||||
typedef struct nrf_drv_clock_handler_item_s nrf_drv_clock_handler_item_t;
|
||||
|
||||
struct nrf_drv_clock_handler_item_s
|
||||
{
|
||||
nrf_drv_clock_handler_item_t * p_next; ///< A pointer to the next handler that should be called when the clock is started.
|
||||
nrf_drv_clock_event_handler_t event_handler; ///< Function to be called when the clock is started.
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Function for checking if driver is already initialized
|
||||
*
|
||||
* @retval true Driver is initialized
|
||||
* @retval false Driver is uninitialized
|
||||
*/
|
||||
bool nrf_drv_clock_init_check(void);
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the nrf_drv_clock module.
|
||||
*
|
||||
* After initialization, the module is in power off state (clocks are not requested).
|
||||
*
|
||||
* @retval NRF_SUCCESS If the procedure was successful.
|
||||
* @retval NRF_ERROR_MODULE_ALREADY_INITIALIZED If the driver was already initialized.
|
||||
*/
|
||||
ret_code_t nrf_drv_clock_init(void);
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the clock module.
|
||||
*
|
||||
*/
|
||||
void nrf_drv_clock_uninit(void);
|
||||
|
||||
/**
|
||||
* @brief Function for requesting the LFCLK.
|
||||
*
|
||||
* The low-frequency clock can be requested by different modules
|
||||
* or contexts. The driver ensures that the clock will be started only when it is requested
|
||||
* the first time. If the clock is not ready but it was already started, the handler item that is
|
||||
* provided as an input parameter is added to the list of handlers that will be notified
|
||||
* when the clock is started. If the clock is already enabled, user callback is called from the
|
||||
* current context.
|
||||
*
|
||||
* The first request will start the selected LFCLK source. If an event handler is
|
||||
* provided, it will be called once the LFCLK is started. If the LFCLK was already started at this
|
||||
* time, the event handler will be called from the context of this function. Additionally,
|
||||
* the @ref nrf_drv_clock_lfclk_is_running function can be polled to check if the clock has started.
|
||||
*
|
||||
* @note When a SoftDevice is enabled, the LFCLK is always running and the driver cannot control it.
|
||||
*
|
||||
* @note The handler item provided by the user cannot be an automatic variable.
|
||||
*
|
||||
* @param[in] p_handler_item A pointer to the event handler structure.
|
||||
*/
|
||||
void nrf_drv_clock_lfclk_request(nrf_drv_clock_handler_item_t * p_handler_item);
|
||||
|
||||
/**
|
||||
* @brief Function for releasing the LFCLK.
|
||||
*
|
||||
* If there are no more requests, the LFCLK source will be stopped.
|
||||
*
|
||||
* @note When a SoftDevice is enabled, the LFCLK is always running.
|
||||
*/
|
||||
void nrf_drv_clock_lfclk_release(void);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the LFCLK state.
|
||||
*
|
||||
* @retval true If the LFCLK is running.
|
||||
* @retval false If the LFCLK is not running.
|
||||
*/
|
||||
bool nrf_drv_clock_lfclk_is_running(void);
|
||||
|
||||
/**
|
||||
* @brief Function for requesting the high-accuracy source HFCLK.
|
||||
*
|
||||
* The high-accuracy source
|
||||
* can be requested by different modules or contexts. The driver ensures that the high-accuracy
|
||||
* clock will be started only when it is requested the first time. If the clock is not ready
|
||||
* but it was already started, the handler item that is provided as an input parameter is added
|
||||
* to the list of handlers that will be notified when the clock is started.
|
||||
*
|
||||
* If an event handler is provided, it will be called once the clock is started. If the clock was already
|
||||
* started at this time, the event handler will be called from the context of this function. Additionally,
|
||||
* the @ref nrf_drv_clock_hfclk_is_running function can be polled to check if the clock has started.
|
||||
*
|
||||
* @note If a SoftDevice is running, the clock is managed by the SoftDevice and all requests are handled by
|
||||
* the SoftDevice. This function cannot be called from all interrupt priority levels in that case.
|
||||
* @note The handler item provided by the user cannot be an automatic variable.
|
||||
*
|
||||
* @param[in] p_handler_item A pointer to the event handler structure.
|
||||
*/
|
||||
void nrf_drv_clock_hfclk_request(nrf_drv_clock_handler_item_t * p_handler_item);
|
||||
|
||||
/**
|
||||
* @brief Function for releasing the high-accuracy source HFCLK.
|
||||
*
|
||||
* If there are no more requests, the high-accuracy source will be released.
|
||||
*/
|
||||
void nrf_drv_clock_hfclk_release(void);
|
||||
|
||||
/**
|
||||
* @brief Function for checking the HFCLK state.
|
||||
*
|
||||
* @retval true If the HFCLK is running (for \nRFXX XTAL source).
|
||||
* @retval false If the HFCLK is not running.
|
||||
*/
|
||||
bool nrf_drv_clock_hfclk_is_running(void);
|
||||
|
||||
/**
|
||||
* @brief Function for starting a single calibration process.
|
||||
*
|
||||
* This function can also delay the start of calibration by a user-specified value. The delay will use
|
||||
* a low-power timer that is part of the CLOCK module. @ref nrf_drv_clock_is_calibrating can be called to
|
||||
* check if calibration is still in progress. If a handler is provided, the user can be notified when
|
||||
* calibration is completed. The ext calibration can be started from the handler context.
|
||||
*
|
||||
* The calibration process consists of three phases:
|
||||
* - Delay (optional)
|
||||
* - Requesting the high-accuracy HFCLK
|
||||
* - Hardware-supported calibration
|
||||
*
|
||||
* @param[in] delay Time after which the calibration will be started (in 0.25 s units).
|
||||
* @param[in] handler NULL or user function to be called when calibration is completed or aborted.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the procedure was successful.
|
||||
* @retval NRF_ERROR_FORBIDDEN If a SoftDevice is present or the selected LFCLK source is not an RC oscillator.
|
||||
* @retval NRF_ERROR_INVALID_STATE If the low-frequency clock is off.
|
||||
* @retval NRF_ERROR_BUSY If calibration is in progress.
|
||||
*/
|
||||
ret_code_t nrf_drv_clock_calibration_start(uint8_t delay, nrf_drv_clock_event_handler_t handler);
|
||||
|
||||
/**
|
||||
* @brief Function for aborting calibration.
|
||||
*
|
||||
* This function aborts on-going calibration. If calibration was started, it cannot be stopped. If a handler
|
||||
* was provided by @ref nrf_drv_clock_calibration_start, this handler will be called once
|
||||
* aborted calibration is completed. @ref nrf_drv_clock_is_calibrating can also be used to check
|
||||
* if the system is calibrating.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the procedure was successful.
|
||||
* @retval NRF_ERROR_FORBIDDEN If a SoftDevice is present or the selected LFCLK source is not an RC oscillator.
|
||||
*/
|
||||
ret_code_t nrf_drv_clock_calibration_abort(void);
|
||||
|
||||
/**
|
||||
* @brief Function for checking if calibration is in progress.
|
||||
*
|
||||
* This function indicates that the system is
|
||||
* in calibration if it is in any of the calibration process phases (see @ref nrf_drv_clock_calibration_start).
|
||||
*
|
||||
* @param[out] p_is_calibrating True if calibration is in progress, false if not.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the procedure was successful.
|
||||
* @retval NRF_ERROR_FORBIDDEN If a SoftDevice is present or the selected LFCLK source is not an RC oscillator.
|
||||
*/
|
||||
ret_code_t nrf_drv_clock_is_calibrating(bool * p_is_calibrating);
|
||||
|
||||
/**@brief Function for returning a requested task address for the clock driver module.
|
||||
*
|
||||
* @param[in] task One of the peripheral tasks.
|
||||
*
|
||||
* @return Task address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_drv_clock_ppi_task_addr(nrf_clock_task_t task);
|
||||
|
||||
/**@brief Function for returning a requested event address for the clock driver module.
|
||||
*
|
||||
* @param[in] event One of the peripheral events.
|
||||
*
|
||||
* @return Event address.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_drv_clock_ppi_event_addr(nrf_clock_event_t event);
|
||||
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
/**
|
||||
* @brief Function called by the SoftDevice handler if an @ref NRF_SOC_EVTS event is received from the SoftDevice.
|
||||
*
|
||||
* @param[in] evt_id One of NRF_SOC_EVTS values.
|
||||
*/
|
||||
void nrf_drv_clock_on_soc_event(uint32_t evt_id);
|
||||
|
||||
/**
|
||||
* @brief Function called by the SoftDevice handler when the SoftDevice has been enabled.
|
||||
*
|
||||
* This function is called just after the SoftDevice has been properly enabled.
|
||||
* Its main purpose is to mark that LFCLK has been requested by SD.
|
||||
*/
|
||||
void nrf_drv_clock_on_sd_enable(void);
|
||||
|
||||
/**
|
||||
* @brief Function called by the SoftDevice handler when the SoftDevice has been disabled.
|
||||
*
|
||||
* This function is called just after the SoftDevice has been properly disabled.
|
||||
* It has two purposes:
|
||||
* 1. Releases the LFCLK from the SD.
|
||||
* 2. Reinitializes an interrupt after the SD releases POWER_CLOCK_IRQ.
|
||||
*/
|
||||
void nrf_drv_clock_on_sd_disable(void);
|
||||
|
||||
#endif
|
||||
/**
|
||||
*@}
|
||||
**/
|
||||
|
||||
#ifndef SUPPRESS_INLINE_IMPLEMENTATION
|
||||
__STATIC_INLINE uint32_t nrf_drv_clock_ppi_task_addr(nrf_clock_task_t task)
|
||||
{
|
||||
return nrf_clock_task_address_get(task);
|
||||
}
|
||||
|
||||
__STATIC_INLINE uint32_t nrf_drv_clock_ppi_event_addr(nrf_clock_event_t event)
|
||||
{
|
||||
return nrf_clock_event_address_get(event);
|
||||
}
|
||||
#endif //SUPPRESS_INLINE_IMPLEMENTATION
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_DRV_CLOCK_H__
|
||||
|
||||
+63
-63
@@ -1,63 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NRF_DRV_COMMON_H__
|
||||
#define NRF_DRV_COMMON_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define INTERRUPT_PRIORITY_VALIDATION(pri) STATIC_ASSERT(INTERRUPT_PRIORITY_IS_VALID((pri)))
|
||||
#define INTERRUPT_PRIORITY_ASSERT(pri) ASSERT(INTERRUPT_PRIORITY_IS_VALID((pri)))
|
||||
|
||||
#define nrf_drv_irq_handler_t nrfx_irq_handler_t
|
||||
#define nrf_drv_bitpos_to_event nrfx_bitpos_to_event
|
||||
#define nrf_drv_event_to_bitpos nrfx_event_to_bitpos
|
||||
#define nrf_drv_get_IRQn nrfx_get_irq_number
|
||||
#define nrf_drv_is_in_RAM nrfx_is_in_ram
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_DRV_COMMON_H__
|
||||
/**
|
||||
* Copyright (c) 2015 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NRF_DRV_COMMON_H__
|
||||
#define NRF_DRV_COMMON_H__
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define INTERRUPT_PRIORITY_VALIDATION(pri) STATIC_ASSERT(INTERRUPT_PRIORITY_IS_VALID((pri)))
|
||||
#define INTERRUPT_PRIORITY_ASSERT(pri) ASSERT(INTERRUPT_PRIORITY_IS_VALID((pri)))
|
||||
|
||||
#define nrf_drv_irq_handler_t nrfx_irq_handler_t
|
||||
#define nrf_drv_bitpos_to_event nrfx_bitpos_to_event
|
||||
#define nrf_drv_event_to_bitpos nrfx_event_to_bitpos
|
||||
#define nrf_drv_get_IRQn nrfx_get_irq_number
|
||||
#define nrf_drv_is_in_RAM nrfx_is_in_ram
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_DRV_COMMON_H__
|
||||
|
||||
+416
-416
@@ -1,416 +1,416 @@
|
||||
/**
|
||||
* Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(POWER)
|
||||
#include "nrf_drv_power.h"
|
||||
#include <nrf_drv_clock.h>
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
#include "nrf_sdh.h"
|
||||
#include "nrf_sdh_soc.h"
|
||||
#endif
|
||||
|
||||
#include <app_util.h>
|
||||
|
||||
// The structure with default configuration data.
|
||||
static const nrfx_power_config_t m_drv_power_config_default =
|
||||
{
|
||||
.dcdcen = NRFX_POWER_CONFIG_DEFAULT_DCDCEN,
|
||||
#if NRF_POWER_HAS_VDDH
|
||||
.dcdcenhv = NRFX_POWER_CONFIG_DEFAULT_DCDCENHV,
|
||||
#endif
|
||||
};
|
||||
|
||||
static bool m_initialized;
|
||||
|
||||
bool nrf_drv_power_init_check(void)
|
||||
{
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
ret_code_t nrf_drv_power_init(nrf_drv_power_config_t const * p_config)
|
||||
{
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if (m_initialized)
|
||||
{
|
||||
return NRF_ERROR_MODULE_ALREADY_INITIALIZED;
|
||||
}
|
||||
if (nrf_sdh_is_enabled())
|
||||
{
|
||||
return NRF_ERROR_INVALID_STATE;
|
||||
}
|
||||
#endif
|
||||
if (p_config == NULL)
|
||||
{
|
||||
p_config = &m_drv_power_config_default;
|
||||
}
|
||||
|
||||
ret_code_t err_code = nrfx_power_init(p_config);
|
||||
if (err_code == NRFX_SUCCESS)
|
||||
{
|
||||
m_initialized = true;
|
||||
}
|
||||
return err_code;
|
||||
}
|
||||
|
||||
void nrf_drv_power_uninit()
|
||||
{
|
||||
nrfx_power_uninit();
|
||||
nrf_drv_power_pof_uninit();
|
||||
#if NRF_POWER_HAS_SLEEPEVT
|
||||
nrf_drv_power_sleepevt_uninit();
|
||||
#endif
|
||||
#if NRF_POWER_HAS_USBREG
|
||||
nrf_drv_power_usbevt_uninit();
|
||||
#endif
|
||||
m_initialized = false;
|
||||
}
|
||||
|
||||
ret_code_t nrf_drv_power_pof_init(nrf_drv_power_pofwarn_config_t const * p_config)
|
||||
{
|
||||
ret_code_t err_code = NRF_SUCCESS;
|
||||
nrfx_power_pof_init(p_config);
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if (nrf_sdh_is_enabled())
|
||||
{
|
||||
/* Currently when SD is enabled - the configuration can be changed
|
||||
* in very limited range.
|
||||
* It is the SoftDevice limitation.
|
||||
*/
|
||||
#if NRF_POWER_HAS_VDDH
|
||||
if (p_config->thrvddh != nrf_power_pofcon_vddh_get())
|
||||
{
|
||||
/* Cannot change THRVDDH with current SD API */
|
||||
return NRF_ERROR_INVALID_STATE;
|
||||
}
|
||||
#endif
|
||||
if (p_config->thr != nrf_power_pofcon_get(NULL))
|
||||
{
|
||||
/* Only limited number of THR values are supported and
|
||||
* the values taken by SD is different than the one in hardware
|
||||
*/
|
||||
uint8_t thr;
|
||||
switch(p_config->thr)
|
||||
{
|
||||
case NRF_POWER_POFTHR_V21:
|
||||
thr = NRF_POWER_THRESHOLD_V21;
|
||||
break;
|
||||
case NRF_POWER_POFTHR_V23:
|
||||
thr = NRF_POWER_THRESHOLD_V23;
|
||||
break;
|
||||
case NRF_POWER_POFTHR_V25:
|
||||
thr = NRF_POWER_THRESHOLD_V25;
|
||||
break;
|
||||
case NRF_POWER_POFTHR_V27:
|
||||
thr = NRF_POWER_THRESHOLD_V27;
|
||||
break;
|
||||
default:
|
||||
/* Cannot configure */
|
||||
nrfx_power_pof_uninit();
|
||||
return NRF_ERROR_INVALID_STATE;
|
||||
}
|
||||
err_code = sd_power_pof_threshold_set(thr);
|
||||
if (err_code != NRF_SUCCESS)
|
||||
{
|
||||
return err_code;
|
||||
}
|
||||
}
|
||||
err_code = sd_power_pof_enable(true);
|
||||
}
|
||||
else
|
||||
#endif /* SOFTDEVICE_PRESENT */
|
||||
{
|
||||
nrfx_power_pof_enable(p_config);
|
||||
}
|
||||
return err_code;
|
||||
}
|
||||
|
||||
void nrf_drv_power_pof_uninit()
|
||||
{
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if (nrf_sdh_is_enabled())
|
||||
{
|
||||
ret_code_t err_code = sd_power_pof_enable(false);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
UNUSED_VARIABLE(err_code); //handle no-debug case
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nrfx_power_pof_disable();
|
||||
}
|
||||
nrfx_power_pof_uninit();
|
||||
}
|
||||
|
||||
#if NRF_POWER_HAS_SLEEPEVT
|
||||
ret_code_t nrf_drv_power_sleepevt_init(nrf_drv_power_sleepevt_config_t const * p_config)
|
||||
{
|
||||
if (p_config->handler != NULL)
|
||||
{
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if (nrf_sdh_is_enabled())
|
||||
{
|
||||
if ((p_config->en_enter) || (p_config->en_exit))
|
||||
{
|
||||
return NRF_ERROR_INVALID_STATE;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nrfx_power_sleepevt_enable(p_config);
|
||||
}
|
||||
}
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
void nrf_drv_power_sleepevt_uninit(void)
|
||||
{
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if (nrf_sdh_is_enabled())
|
||||
{
|
||||
/* Nothing to do */
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nrfx_power_sleepevt_disable();
|
||||
}
|
||||
nrfx_power_sleepevt_uninit();
|
||||
}
|
||||
#endif /* NRF_POWER_HAS_SLEEPEVT */
|
||||
|
||||
#if NRF_POWER_HAS_USBREG
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
static ret_code_t nrf_drv_power_sd_usbevt_enable(bool enable)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
err_code = sd_power_usbdetected_enable(enable);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
if (err_code != NRF_SUCCESS)
|
||||
{
|
||||
return err_code;
|
||||
}
|
||||
|
||||
err_code = sd_power_usbpwrrdy_enable(enable);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
if (err_code != NRF_SUCCESS)
|
||||
{
|
||||
return err_code;
|
||||
}
|
||||
|
||||
err_code = sd_power_usbremoved_enable(enable);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
return err_code;
|
||||
}
|
||||
#endif // SOFTDEVICE_PRESENT
|
||||
|
||||
ret_code_t nrf_drv_power_usbevt_init(nrf_drv_power_usbevt_config_t const * p_config)
|
||||
{
|
||||
nrf_drv_power_usbevt_uninit();
|
||||
nrfx_power_usbevt_init(p_config);
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if (nrf_sdh_is_enabled())
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_power_sd_usbevt_enable(true);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
if (err_code != NRF_SUCCESS)
|
||||
{
|
||||
return err_code;
|
||||
}
|
||||
|
||||
uint32_t regstatus;
|
||||
err_code = sd_power_usbregstatus_get(®status);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
if (err_code != NRF_SUCCESS)
|
||||
{
|
||||
return err_code;
|
||||
}
|
||||
|
||||
if (regstatus & POWER_USBREGSTATUS_VBUSDETECT_Msk)
|
||||
{
|
||||
nrfx_power_usb_event_handler_t usbevt_handler = nrfx_power_usb_handler_get();
|
||||
ASSERT(usbevt_handler != NULL);
|
||||
usbevt_handler(NRFX_POWER_USB_EVT_DETECTED);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nrfx_power_usbevt_enable();
|
||||
}
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
void nrf_drv_power_usbevt_uninit(void)
|
||||
{
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
CRITICAL_REGION_ENTER();
|
||||
if (nrf_sdh_is_enabled())
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_power_sd_usbevt_enable(false);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
UNUSED_VARIABLE(err_code);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nrfx_power_usbevt_disable();
|
||||
}
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
CRITICAL_REGION_EXIT();
|
||||
#endif
|
||||
nrfx_power_usbevt_uninit();
|
||||
}
|
||||
#endif /* NRF_POWER_HAS_USBREG */
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
static void nrf_drv_power_sdh_soc_evt_handler(uint32_t evt_id, void * p_context);
|
||||
static void nrf_drv_power_sdh_state_evt_handler(nrf_sdh_state_evt_t state, void * p_context);
|
||||
|
||||
NRF_SDH_SOC_OBSERVER(m_soc_observer, POWER_CONFIG_SOC_OBSERVER_PRIO,
|
||||
nrf_drv_power_sdh_soc_evt_handler, NULL);
|
||||
|
||||
NRF_SDH_STATE_OBSERVER(m_sd_observer, POWER_CONFIG_STATE_OBSERVER_PRIO) =
|
||||
{
|
||||
.handler = nrf_drv_power_sdh_state_evt_handler,
|
||||
.p_context = NULL
|
||||
};
|
||||
|
||||
static void nrf_drv_power_sdh_soc_evt_handler(uint32_t evt_id, void * p_context)
|
||||
{
|
||||
if (evt_id == NRF_EVT_POWER_FAILURE_WARNING)
|
||||
{
|
||||
nrfx_power_pofwarn_event_handler_t pofwarn_handler = nrfx_power_pof_handler_get();
|
||||
/* Cannot be null if event is enabled */
|
||||
ASSERT(pofwarn_handler != NULL);
|
||||
pofwarn_handler();
|
||||
}
|
||||
|
||||
#if NRF_POWER_HAS_USBREG
|
||||
nrfx_power_usb_event_handler_t usbevt_handler = nrfx_power_usb_handler_get();
|
||||
if (usbevt_handler != NULL)
|
||||
{
|
||||
switch (evt_id)
|
||||
{
|
||||
case NRF_EVT_POWER_USB_POWER_READY:
|
||||
usbevt_handler(NRFX_POWER_USB_EVT_READY);
|
||||
break;
|
||||
|
||||
case NRF_EVT_POWER_USB_DETECTED:
|
||||
usbevt_handler(NRFX_POWER_USB_EVT_DETECTED);
|
||||
break;
|
||||
|
||||
case NRF_EVT_POWER_USB_REMOVED:
|
||||
usbevt_handler(NRFX_POWER_USB_EVT_REMOVED);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void nrf_drv_power_on_sd_enable(void)
|
||||
{
|
||||
ASSERT(m_initialized); /* This module has to be enabled first */
|
||||
CRITICAL_REGION_ENTER();
|
||||
if (nrfx_power_pof_handler_get() != NULL)
|
||||
{
|
||||
ret_code_t err_code = sd_power_pof_enable(true);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
UNUSED_VARIABLE(err_code); //handle no-debug case
|
||||
}
|
||||
CRITICAL_REGION_EXIT();
|
||||
|
||||
#if NRF_POWER_HAS_USBREG
|
||||
if (nrfx_power_usb_handler_get() != NULL)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_power_sd_usbevt_enable(true);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
UNUSED_VARIABLE(err_code); //handle no-debug case
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void nrf_drv_power_on_sd_disable(void)
|
||||
{
|
||||
/* Reinit interrupts */
|
||||
ASSERT(m_initialized);
|
||||
NRFX_IRQ_PRIORITY_SET(POWER_CLOCK_IRQn, CLOCK_CONFIG_IRQ_PRIORITY);
|
||||
NRFX_IRQ_ENABLE(POWER_CLOCK_IRQn);
|
||||
if (nrfx_power_pof_handler_get() != NULL)
|
||||
{
|
||||
nrf_power_int_enable(NRF_POWER_INT_POFWARN_MASK);
|
||||
}
|
||||
|
||||
#if NRF_POWER_HAS_USBREG
|
||||
if (nrfx_power_usb_handler_get() != NULL)
|
||||
{
|
||||
nrf_power_int_enable(
|
||||
NRF_POWER_INT_USBDETECTED_MASK |
|
||||
NRF_POWER_INT_USBREMOVED_MASK |
|
||||
NRF_POWER_INT_USBPWRRDY_MASK);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void nrf_drv_power_sdh_state_evt_handler(nrf_sdh_state_evt_t state, void * p_context)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case NRF_SDH_EVT_STATE_ENABLED:
|
||||
nrf_drv_power_on_sd_enable();
|
||||
break;
|
||||
|
||||
case NRF_SDH_EVT_STATE_DISABLED:
|
||||
nrf_drv_power_on_sd_disable();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SOFTDEVICE_PRESENT
|
||||
#endif //POWER_ENABLED
|
||||
/**
|
||||
* Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(POWER)
|
||||
#include "nrf_drv_power.h"
|
||||
#include <nrf_drv_clock.h>
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
#include "nrf_sdh.h"
|
||||
#include "nrf_sdh_soc.h"
|
||||
#endif
|
||||
|
||||
#include <app_util.h>
|
||||
|
||||
// The structure with default configuration data.
|
||||
static const nrfx_power_config_t m_drv_power_config_default =
|
||||
{
|
||||
.dcdcen = NRFX_POWER_CONFIG_DEFAULT_DCDCEN,
|
||||
#if NRF_POWER_HAS_VDDH
|
||||
.dcdcenhv = NRFX_POWER_CONFIG_DEFAULT_DCDCENHV,
|
||||
#endif
|
||||
};
|
||||
|
||||
static bool m_initialized;
|
||||
|
||||
bool nrf_drv_power_init_check(void)
|
||||
{
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
ret_code_t nrf_drv_power_init(nrf_drv_power_config_t const * p_config)
|
||||
{
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if (m_initialized)
|
||||
{
|
||||
return NRF_ERROR_MODULE_ALREADY_INITIALIZED;
|
||||
}
|
||||
if (nrf_sdh_is_enabled())
|
||||
{
|
||||
return NRF_ERROR_INVALID_STATE;
|
||||
}
|
||||
#endif
|
||||
if (p_config == NULL)
|
||||
{
|
||||
p_config = &m_drv_power_config_default;
|
||||
}
|
||||
|
||||
ret_code_t err_code = nrfx_power_init(p_config);
|
||||
if (err_code == NRFX_SUCCESS)
|
||||
{
|
||||
m_initialized = true;
|
||||
}
|
||||
return err_code;
|
||||
}
|
||||
|
||||
void nrf_drv_power_uninit()
|
||||
{
|
||||
nrfx_power_uninit();
|
||||
nrf_drv_power_pof_uninit();
|
||||
#if NRF_POWER_HAS_SLEEPEVT
|
||||
nrf_drv_power_sleepevt_uninit();
|
||||
#endif
|
||||
#if NRF_POWER_HAS_USBREG
|
||||
nrf_drv_power_usbevt_uninit();
|
||||
#endif
|
||||
m_initialized = false;
|
||||
}
|
||||
|
||||
ret_code_t nrf_drv_power_pof_init(nrf_drv_power_pofwarn_config_t const * p_config)
|
||||
{
|
||||
ret_code_t err_code = NRF_SUCCESS;
|
||||
nrfx_power_pof_init(p_config);
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if (nrf_sdh_is_enabled())
|
||||
{
|
||||
/* Currently when SD is enabled - the configuration can be changed
|
||||
* in very limited range.
|
||||
* It is the SoftDevice limitation.
|
||||
*/
|
||||
#if NRF_POWER_HAS_VDDH
|
||||
if (p_config->thrvddh != nrf_power_pofcon_vddh_get())
|
||||
{
|
||||
/* Cannot change THRVDDH with current SD API */
|
||||
return NRF_ERROR_INVALID_STATE;
|
||||
}
|
||||
#endif
|
||||
if (p_config->thr != nrf_power_pofcon_get(NULL))
|
||||
{
|
||||
/* Only limited number of THR values are supported and
|
||||
* the values taken by SD is different than the one in hardware
|
||||
*/
|
||||
uint8_t thr;
|
||||
switch(p_config->thr)
|
||||
{
|
||||
case NRF_POWER_POFTHR_V21:
|
||||
thr = NRF_POWER_THRESHOLD_V21;
|
||||
break;
|
||||
case NRF_POWER_POFTHR_V23:
|
||||
thr = NRF_POWER_THRESHOLD_V23;
|
||||
break;
|
||||
case NRF_POWER_POFTHR_V25:
|
||||
thr = NRF_POWER_THRESHOLD_V25;
|
||||
break;
|
||||
case NRF_POWER_POFTHR_V27:
|
||||
thr = NRF_POWER_THRESHOLD_V27;
|
||||
break;
|
||||
default:
|
||||
/* Cannot configure */
|
||||
nrfx_power_pof_uninit();
|
||||
return NRF_ERROR_INVALID_STATE;
|
||||
}
|
||||
err_code = sd_power_pof_threshold_set(thr);
|
||||
if (err_code != NRF_SUCCESS)
|
||||
{
|
||||
return err_code;
|
||||
}
|
||||
}
|
||||
err_code = sd_power_pof_enable(true);
|
||||
}
|
||||
else
|
||||
#endif /* SOFTDEVICE_PRESENT */
|
||||
{
|
||||
nrfx_power_pof_enable(p_config);
|
||||
}
|
||||
return err_code;
|
||||
}
|
||||
|
||||
void nrf_drv_power_pof_uninit()
|
||||
{
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if (nrf_sdh_is_enabled())
|
||||
{
|
||||
ret_code_t err_code = sd_power_pof_enable(false);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
UNUSED_VARIABLE(err_code); //handle no-debug case
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nrfx_power_pof_disable();
|
||||
}
|
||||
nrfx_power_pof_uninit();
|
||||
}
|
||||
|
||||
#if NRF_POWER_HAS_SLEEPEVT
|
||||
ret_code_t nrf_drv_power_sleepevt_init(nrf_drv_power_sleepevt_config_t const * p_config)
|
||||
{
|
||||
if (p_config->handler != NULL)
|
||||
{
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if (nrf_sdh_is_enabled())
|
||||
{
|
||||
if ((p_config->en_enter) || (p_config->en_exit))
|
||||
{
|
||||
return NRF_ERROR_INVALID_STATE;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nrfx_power_sleepevt_enable(p_config);
|
||||
}
|
||||
}
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
void nrf_drv_power_sleepevt_uninit(void)
|
||||
{
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if (nrf_sdh_is_enabled())
|
||||
{
|
||||
/* Nothing to do */
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nrfx_power_sleepevt_disable();
|
||||
}
|
||||
nrfx_power_sleepevt_uninit();
|
||||
}
|
||||
#endif /* NRF_POWER_HAS_SLEEPEVT */
|
||||
|
||||
#if NRF_POWER_HAS_USBREG
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
static ret_code_t nrf_drv_power_sd_usbevt_enable(bool enable)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
err_code = sd_power_usbdetected_enable(enable);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
if (err_code != NRF_SUCCESS)
|
||||
{
|
||||
return err_code;
|
||||
}
|
||||
|
||||
err_code = sd_power_usbpwrrdy_enable(enable);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
if (err_code != NRF_SUCCESS)
|
||||
{
|
||||
return err_code;
|
||||
}
|
||||
|
||||
err_code = sd_power_usbremoved_enable(enable);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
return err_code;
|
||||
}
|
||||
#endif // SOFTDEVICE_PRESENT
|
||||
|
||||
ret_code_t nrf_drv_power_usbevt_init(nrf_drv_power_usbevt_config_t const * p_config)
|
||||
{
|
||||
nrf_drv_power_usbevt_uninit();
|
||||
nrfx_power_usbevt_init(p_config);
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
if (nrf_sdh_is_enabled())
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_power_sd_usbevt_enable(true);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
if (err_code != NRF_SUCCESS)
|
||||
{
|
||||
return err_code;
|
||||
}
|
||||
|
||||
uint32_t regstatus;
|
||||
err_code = sd_power_usbregstatus_get(®status);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
if (err_code != NRF_SUCCESS)
|
||||
{
|
||||
return err_code;
|
||||
}
|
||||
|
||||
if (regstatus & POWER_USBREGSTATUS_VBUSDETECT_Msk)
|
||||
{
|
||||
nrfx_power_usb_event_handler_t usbevt_handler = nrfx_power_usb_handler_get();
|
||||
ASSERT(usbevt_handler != NULL);
|
||||
usbevt_handler(NRFX_POWER_USB_EVT_DETECTED);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nrfx_power_usbevt_enable();
|
||||
}
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
void nrf_drv_power_usbevt_uninit(void)
|
||||
{
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
CRITICAL_REGION_ENTER();
|
||||
if (nrf_sdh_is_enabled())
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_power_sd_usbevt_enable(false);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
UNUSED_VARIABLE(err_code);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nrfx_power_usbevt_disable();
|
||||
}
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
CRITICAL_REGION_EXIT();
|
||||
#endif
|
||||
nrfx_power_usbevt_uninit();
|
||||
}
|
||||
#endif /* NRF_POWER_HAS_USBREG */
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
static void nrf_drv_power_sdh_soc_evt_handler(uint32_t evt_id, void * p_context);
|
||||
static void nrf_drv_power_sdh_state_evt_handler(nrf_sdh_state_evt_t state, void * p_context);
|
||||
|
||||
NRF_SDH_SOC_OBSERVER(m_soc_observer, POWER_CONFIG_SOC_OBSERVER_PRIO,
|
||||
nrf_drv_power_sdh_soc_evt_handler, NULL);
|
||||
|
||||
NRF_SDH_STATE_OBSERVER(m_sd_observer, POWER_CONFIG_STATE_OBSERVER_PRIO) =
|
||||
{
|
||||
.handler = nrf_drv_power_sdh_state_evt_handler,
|
||||
.p_context = NULL
|
||||
};
|
||||
|
||||
static void nrf_drv_power_sdh_soc_evt_handler(uint32_t evt_id, void * p_context)
|
||||
{
|
||||
if (evt_id == NRF_EVT_POWER_FAILURE_WARNING)
|
||||
{
|
||||
nrfx_power_pofwarn_event_handler_t pofwarn_handler = nrfx_power_pof_handler_get();
|
||||
/* Cannot be null if event is enabled */
|
||||
ASSERT(pofwarn_handler != NULL);
|
||||
pofwarn_handler();
|
||||
}
|
||||
|
||||
#if NRF_POWER_HAS_USBREG
|
||||
nrfx_power_usb_event_handler_t usbevt_handler = nrfx_power_usb_handler_get();
|
||||
if (usbevt_handler != NULL)
|
||||
{
|
||||
switch (evt_id)
|
||||
{
|
||||
case NRF_EVT_POWER_USB_POWER_READY:
|
||||
usbevt_handler(NRFX_POWER_USB_EVT_READY);
|
||||
break;
|
||||
|
||||
case NRF_EVT_POWER_USB_DETECTED:
|
||||
usbevt_handler(NRFX_POWER_USB_EVT_DETECTED);
|
||||
break;
|
||||
|
||||
case NRF_EVT_POWER_USB_REMOVED:
|
||||
usbevt_handler(NRFX_POWER_USB_EVT_REMOVED);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void nrf_drv_power_on_sd_enable(void)
|
||||
{
|
||||
ASSERT(m_initialized); /* This module has to be enabled first */
|
||||
CRITICAL_REGION_ENTER();
|
||||
if (nrfx_power_pof_handler_get() != NULL)
|
||||
{
|
||||
ret_code_t err_code = sd_power_pof_enable(true);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
UNUSED_VARIABLE(err_code); //handle no-debug case
|
||||
}
|
||||
CRITICAL_REGION_EXIT();
|
||||
|
||||
#if NRF_POWER_HAS_USBREG
|
||||
if (nrfx_power_usb_handler_get() != NULL)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_power_sd_usbevt_enable(true);
|
||||
ASSERT(err_code == NRF_SUCCESS);
|
||||
UNUSED_VARIABLE(err_code); //handle no-debug case
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void nrf_drv_power_on_sd_disable(void)
|
||||
{
|
||||
/* Reinit interrupts */
|
||||
ASSERT(m_initialized);
|
||||
NRFX_IRQ_PRIORITY_SET(POWER_CLOCK_IRQn, CLOCK_CONFIG_IRQ_PRIORITY);
|
||||
NRFX_IRQ_ENABLE(POWER_CLOCK_IRQn);
|
||||
if (nrfx_power_pof_handler_get() != NULL)
|
||||
{
|
||||
nrf_power_int_enable(NRF_POWER_INT_POFWARN_MASK);
|
||||
}
|
||||
|
||||
#if NRF_POWER_HAS_USBREG
|
||||
if (nrfx_power_usb_handler_get() != NULL)
|
||||
{
|
||||
nrf_power_int_enable(
|
||||
NRF_POWER_INT_USBDETECTED_MASK |
|
||||
NRF_POWER_INT_USBREMOVED_MASK |
|
||||
NRF_POWER_INT_USBPWRRDY_MASK);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void nrf_drv_power_sdh_state_evt_handler(nrf_sdh_state_evt_t state, void * p_context)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case NRF_SDH_EVT_STATE_ENABLED:
|
||||
nrf_drv_power_on_sd_enable();
|
||||
break;
|
||||
|
||||
case NRF_SDH_EVT_STATE_DISABLED:
|
||||
nrf_drv_power_on_sd_disable();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SOFTDEVICE_PRESENT
|
||||
#endif //POWER_ENABLED
|
||||
|
||||
+232
-232
@@ -1,232 +1,232 @@
|
||||
/**
|
||||
* Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NRF_DRV_POWER_H__
|
||||
#define NRF_DRV_POWER_H__
|
||||
|
||||
#include <nrfx_power.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_drv_power POWER driver - legacy layer
|
||||
* @{
|
||||
* @ingroup nrf_power
|
||||
*
|
||||
* @brief Layer providing compatibility with the former API.
|
||||
*/
|
||||
|
||||
/** @brief Type definition for forwarding the new implementation. */
|
||||
typedef nrfx_power_config_t nrf_drv_power_config_t;
|
||||
/** @brief Type definition for forwarding the new implementation. */
|
||||
typedef nrfx_power_pofwarn_config_t nrf_drv_power_pofwarn_config_t;
|
||||
#if NRF_POWER_HAS_SLEEPEVT || defined(__SDK_DOXYGEN__)
|
||||
/** @brief Type definition for forwarding the new implementation. */
|
||||
typedef nrfx_power_sleepevt_config_t nrf_drv_power_sleepevt_config_t;
|
||||
#endif
|
||||
#if NRF_POWER_HAS_USBREG || defined(__SDK_DOXYGEN__)
|
||||
/** @brief Type definition for forwarding the new implementation. */
|
||||
typedef nrfx_power_usbevt_config_t nrf_drv_power_usbevt_config_t;
|
||||
#endif
|
||||
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_MODE_CONSTLAT NRFX_POWER_MODE_CONSTLAT
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_MODE_LOWPWR NRFX_POWER_MODE_LOWPWR
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_mode_t nrfx_power_mode_t
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_SLEEP_EVT_ENTER NRFX_POWER_SLEEP_EVT_ENTER
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_SLEEP_EVT_EXIT NRFX_POWER_SLEEP_EVT_EXIT
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_sleep_evt_t nrfx_power_sleep_evt_t
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_USB_EVT_DETECTED NRFX_POWER_USB_EVT_DETECTED
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_USB_EVT_REMOVED NRFX_POWER_USB_EVT_REMOVED
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_USB_EVT_READY NRFX_POWER_USB_EVT_READY
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_usb_evt_t nrfx_power_usb_evt_t
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_USB_STATE_DISCONNECTED NRFX_POWER_USB_STATE_DISCONNECTED
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_USB_STATE_CONNECTED NRFX_POWER_USB_STATE_CONNECTED
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_USB_STATE_READY NRFX_POWER_USB_STATE_READY
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_usb_state_t nrfx_power_usb_state_t
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_pofwarn_event_handler_t nrfx_power_pofwarn_event_handler_t
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_sleep_event_handler_t nrfx_power_sleep_event_handler_t
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_usb_event_handler_t nrfx_power_usb_event_handler_t
|
||||
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_usbstatus_get nrfx_power_usbstatus_get
|
||||
|
||||
/**
|
||||
* @brief Function for checking if driver is already initialized
|
||||
*
|
||||
* This function is used to check whether common POWER_CLOCK interrupt
|
||||
* should be disabled or not if @ref nrf_drv_clock tries to disable the interrupt.
|
||||
*
|
||||
* @retval true Driver is initialized
|
||||
* @retval false Driver is uninitialized
|
||||
*
|
||||
* @sa nrf_drv_power_uninit
|
||||
*/
|
||||
bool nrf_drv_power_init_check(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize power module driver
|
||||
*
|
||||
* Enabled power module driver would process all the interrupts from power system.
|
||||
*
|
||||
* @param[in] p_config Driver configuration. Can be NULL - the default configuration
|
||||
* from @em sdk_config.h file would be used then.
|
||||
*
|
||||
* @retval NRF_ERROR_INVALID_STATE Power driver has to be enabled
|
||||
* before SoftDevice.
|
||||
* @retval NRF_ERROR_MODULE_ALREADY_INITIALIZED Module is initialized already.
|
||||
* @retval NRF_SUCCESS Successfully initialized.
|
||||
*/
|
||||
ret_code_t nrf_drv_power_init(nrf_drv_power_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Unintialize power module driver
|
||||
*
|
||||
* Disables all the interrupt handling in the module.
|
||||
*
|
||||
* @sa nrf_drv_power_init
|
||||
*/
|
||||
void nrf_drv_power_uninit(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize power failure comparator
|
||||
*
|
||||
* Configures and setups the power failure comparator and enables it.
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
* If event handler is set to NULL, interrupt would be disabled.
|
||||
*
|
||||
* @retval NRF_ERROR_INVALID_STATE POF is initialized when SD is enabled and
|
||||
* the configuration differs from the old one and
|
||||
* is not possible to be set using SD interface.
|
||||
* @retval NRF_SUCCESS Successfully initialized and configured.
|
||||
*/
|
||||
ret_code_t nrf_drv_power_pof_init(nrf_drv_power_pofwarn_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Turn off the power failure comparator
|
||||
*
|
||||
* Disables and clears the settings of the power failure comparator.
|
||||
*/
|
||||
void nrf_drv_power_pof_uninit(void);
|
||||
|
||||
#if NRF_POWER_HAS_SLEEPEVT || defined(__SDK_DOXYGEN__)
|
||||
|
||||
/**
|
||||
* @brief Initialize sleep entering and exiting events processing
|
||||
*
|
||||
* Configures and setups the sleep event processing.
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
*
|
||||
* @sa nrf_drv_power_sleepevt_uninit
|
||||
*
|
||||
* @note Sleep events are not available when SoftDevice is enabled.
|
||||
* @note If sleep event is enabled when SoftDevice is initialized, sleep events
|
||||
* would be automatically disabled - it is the limitation of the
|
||||
* SoftDevice itself.
|
||||
*
|
||||
* @retval NRF_ERROR_INVALID_STATE This event cannot be initialized
|
||||
* when SD is enabled.
|
||||
* @retval NRF_SUCCESS Successfully initialized and configured.
|
||||
*/
|
||||
ret_code_t nrf_drv_power_sleepevt_init(nrf_drv_power_sleepevt_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Uninitialize sleep entering and exiting events processing
|
||||
*
|
||||
* @sa nrf_drv_power_sleepevt_init
|
||||
*/
|
||||
void nrf_drv_power_sleepevt_uninit(void);
|
||||
|
||||
#endif // NRF_POWER_HAS_SLEEPEVT || defined(__SDK_DOXYGEN__)
|
||||
|
||||
#if NRF_POWER_HAS_USBREG || defined(__SDK_DOXYGEN__)
|
||||
|
||||
/**
|
||||
* @brief Initialize USB power event processing
|
||||
*
|
||||
* Configures and setups the USB power event processing.
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
*
|
||||
* @sa nrf_drv_power_usbevt_uninit
|
||||
*
|
||||
* @retval NRF_ERROR_INVALID_STATE This event cannot be initialized
|
||||
* when SD is enabled and SD does not support
|
||||
* USB power events.
|
||||
* @retval NRF_SUCCESS Successfully initialized and configured.
|
||||
*/
|
||||
ret_code_t nrf_drv_power_usbevt_init(nrf_drv_power_usbevt_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Uninitalize USB power event processing
|
||||
*
|
||||
* @sa nrf_drv_power_usbevt_init
|
||||
*/
|
||||
void nrf_drv_power_usbevt_uninit(void);
|
||||
|
||||
#endif // NRF_POWER_HAS_USBREG || defined(__SDK_DOXYGEN__)
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_DRV_POWER_H__
|
||||
/**
|
||||
* Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NRF_DRV_POWER_H__
|
||||
#define NRF_DRV_POWER_H__
|
||||
|
||||
#include <nrfx_power.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_drv_power POWER driver - legacy layer
|
||||
* @{
|
||||
* @ingroup nrf_power
|
||||
*
|
||||
* @brief Layer providing compatibility with the former API.
|
||||
*/
|
||||
|
||||
/** @brief Type definition for forwarding the new implementation. */
|
||||
typedef nrfx_power_config_t nrf_drv_power_config_t;
|
||||
/** @brief Type definition for forwarding the new implementation. */
|
||||
typedef nrfx_power_pofwarn_config_t nrf_drv_power_pofwarn_config_t;
|
||||
#if NRF_POWER_HAS_SLEEPEVT || defined(__SDK_DOXYGEN__)
|
||||
/** @brief Type definition for forwarding the new implementation. */
|
||||
typedef nrfx_power_sleepevt_config_t nrf_drv_power_sleepevt_config_t;
|
||||
#endif
|
||||
#if NRF_POWER_HAS_USBREG || defined(__SDK_DOXYGEN__)
|
||||
/** @brief Type definition for forwarding the new implementation. */
|
||||
typedef nrfx_power_usbevt_config_t nrf_drv_power_usbevt_config_t;
|
||||
#endif
|
||||
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_MODE_CONSTLAT NRFX_POWER_MODE_CONSTLAT
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_MODE_LOWPWR NRFX_POWER_MODE_LOWPWR
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_mode_t nrfx_power_mode_t
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_SLEEP_EVT_ENTER NRFX_POWER_SLEEP_EVT_ENTER
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_SLEEP_EVT_EXIT NRFX_POWER_SLEEP_EVT_EXIT
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_sleep_evt_t nrfx_power_sleep_evt_t
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_USB_EVT_DETECTED NRFX_POWER_USB_EVT_DETECTED
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_USB_EVT_REMOVED NRFX_POWER_USB_EVT_REMOVED
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_USB_EVT_READY NRFX_POWER_USB_EVT_READY
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_usb_evt_t nrfx_power_usb_evt_t
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_USB_STATE_DISCONNECTED NRFX_POWER_USB_STATE_DISCONNECTED
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_USB_STATE_CONNECTED NRFX_POWER_USB_STATE_CONNECTED
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define NRF_DRV_POWER_USB_STATE_READY NRFX_POWER_USB_STATE_READY
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_usb_state_t nrfx_power_usb_state_t
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_pofwarn_event_handler_t nrfx_power_pofwarn_event_handler_t
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_sleep_event_handler_t nrfx_power_sleep_event_handler_t
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_usb_event_handler_t nrfx_power_usb_event_handler_t
|
||||
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_power_usbstatus_get nrfx_power_usbstatus_get
|
||||
|
||||
/**
|
||||
* @brief Function for checking if driver is already initialized
|
||||
*
|
||||
* This function is used to check whether common POWER_CLOCK interrupt
|
||||
* should be disabled or not if @ref nrf_drv_clock tries to disable the interrupt.
|
||||
*
|
||||
* @retval true Driver is initialized
|
||||
* @retval false Driver is uninitialized
|
||||
*
|
||||
* @sa nrf_drv_power_uninit
|
||||
*/
|
||||
bool nrf_drv_power_init_check(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize power module driver
|
||||
*
|
||||
* Enabled power module driver would process all the interrupts from power system.
|
||||
*
|
||||
* @param[in] p_config Driver configuration. Can be NULL - the default configuration
|
||||
* from @em sdk_config.h file would be used then.
|
||||
*
|
||||
* @retval NRF_ERROR_INVALID_STATE Power driver has to be enabled
|
||||
* before SoftDevice.
|
||||
* @retval NRF_ERROR_MODULE_ALREADY_INITIALIZED Module is initialized already.
|
||||
* @retval NRF_SUCCESS Successfully initialized.
|
||||
*/
|
||||
ret_code_t nrf_drv_power_init(nrf_drv_power_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Unintialize power module driver
|
||||
*
|
||||
* Disables all the interrupt handling in the module.
|
||||
*
|
||||
* @sa nrf_drv_power_init
|
||||
*/
|
||||
void nrf_drv_power_uninit(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize power failure comparator
|
||||
*
|
||||
* Configures and setups the power failure comparator and enables it.
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
* If event handler is set to NULL, interrupt would be disabled.
|
||||
*
|
||||
* @retval NRF_ERROR_INVALID_STATE POF is initialized when SD is enabled and
|
||||
* the configuration differs from the old one and
|
||||
* is not possible to be set using SD interface.
|
||||
* @retval NRF_SUCCESS Successfully initialized and configured.
|
||||
*/
|
||||
ret_code_t nrf_drv_power_pof_init(nrf_drv_power_pofwarn_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Turn off the power failure comparator
|
||||
*
|
||||
* Disables and clears the settings of the power failure comparator.
|
||||
*/
|
||||
void nrf_drv_power_pof_uninit(void);
|
||||
|
||||
#if NRF_POWER_HAS_SLEEPEVT || defined(__SDK_DOXYGEN__)
|
||||
|
||||
/**
|
||||
* @brief Initialize sleep entering and exiting events processing
|
||||
*
|
||||
* Configures and setups the sleep event processing.
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
*
|
||||
* @sa nrf_drv_power_sleepevt_uninit
|
||||
*
|
||||
* @note Sleep events are not available when SoftDevice is enabled.
|
||||
* @note If sleep event is enabled when SoftDevice is initialized, sleep events
|
||||
* would be automatically disabled - it is the limitation of the
|
||||
* SoftDevice itself.
|
||||
*
|
||||
* @retval NRF_ERROR_INVALID_STATE This event cannot be initialized
|
||||
* when SD is enabled.
|
||||
* @retval NRF_SUCCESS Successfully initialized and configured.
|
||||
*/
|
||||
ret_code_t nrf_drv_power_sleepevt_init(nrf_drv_power_sleepevt_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Uninitialize sleep entering and exiting events processing
|
||||
*
|
||||
* @sa nrf_drv_power_sleepevt_init
|
||||
*/
|
||||
void nrf_drv_power_sleepevt_uninit(void);
|
||||
|
||||
#endif // NRF_POWER_HAS_SLEEPEVT || defined(__SDK_DOXYGEN__)
|
||||
|
||||
#if NRF_POWER_HAS_USBREG || defined(__SDK_DOXYGEN__)
|
||||
|
||||
/**
|
||||
* @brief Initialize USB power event processing
|
||||
*
|
||||
* Configures and setups the USB power event processing.
|
||||
*
|
||||
* @param[in] p_config Configuration with values and event handler.
|
||||
*
|
||||
* @sa nrf_drv_power_usbevt_uninit
|
||||
*
|
||||
* @retval NRF_ERROR_INVALID_STATE This event cannot be initialized
|
||||
* when SD is enabled and SD does not support
|
||||
* USB power events.
|
||||
* @retval NRF_SUCCESS Successfully initialized and configured.
|
||||
*/
|
||||
ret_code_t nrf_drv_power_usbevt_init(nrf_drv_power_usbevt_config_t const * p_config);
|
||||
|
||||
/**
|
||||
* @brief Uninitalize USB power event processing
|
||||
*
|
||||
* @sa nrf_drv_power_usbevt_init
|
||||
*/
|
||||
void nrf_drv_power_usbevt_uninit(void);
|
||||
|
||||
#endif // NRF_POWER_HAS_USBREG || defined(__SDK_DOXYGEN__)
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_DRV_POWER_H__
|
||||
|
||||
+2
-2
@@ -1,3 +1,3 @@
|
||||
# nRF 802.15.4 radio driver.
|
||||
|
||||
# nRF 802.15.4 radio driver.
|
||||
|
||||
Copy of [the nRF52840 IEEE 802.15.4 radio driver](https://github.com/NordicSemiconductor/nRF-IEEE-802.15.4-radio-driver).
|
||||
+1179
-1179
File diff suppressed because it is too large
Load Diff
@@ -1,80 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NRF_DRV_SYSTICK_H__
|
||||
#define NRF_DRV_SYSTICK_H__
|
||||
|
||||
#include <nrfx_systick.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_drv_systick ARM(R) SysTick driver - legacy layer
|
||||
* @{
|
||||
* @ingroup nrf_systick
|
||||
*
|
||||
* @brief Layer providing compatibility with the former API.
|
||||
*/
|
||||
|
||||
/** @brief Type definition for forwarding the new implementation. */
|
||||
typedef nrfx_systick_state_t nrf_drv_systick_state_t;
|
||||
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_systick_init nrfx_systick_init
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_systick_get nrfx_systick_get
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_systick_test nrfx_systick_test
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_systick_delay_ticks nrfx_systick_delay_ticks
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_systick_delay_us nrfx_systick_delay_us
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_systick_delay_ms nrfx_systick_delay_ms
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_DRV_SYSTICK_H__
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NRF_DRV_SYSTICK_H__
|
||||
#define NRF_DRV_SYSTICK_H__
|
||||
|
||||
#include <nrfx_systick.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_drv_systick ARM(R) SysTick driver - legacy layer
|
||||
* @{
|
||||
* @ingroup nrf_systick
|
||||
*
|
||||
* @brief Layer providing compatibility with the former API.
|
||||
*/
|
||||
|
||||
/** @brief Type definition for forwarding the new implementation. */
|
||||
typedef nrfx_systick_state_t nrf_drv_systick_state_t;
|
||||
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_systick_init nrfx_systick_init
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_systick_get nrfx_systick_get
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_systick_test nrfx_systick_test
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_systick_delay_ticks nrfx_systick_delay_ticks
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_systick_delay_us nrfx_systick_delay_us
|
||||
/** @brief Macro for forwarding the new implementation. */
|
||||
#define nrf_drv_systick_delay_ms nrfx_systick_delay_ms
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_DRV_SYSTICK_H__
|
||||
|
||||
+139
-139
@@ -1,139 +1,139 @@
|
||||
/**
|
||||
* Copyright (c) 2014 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @file
|
||||
*
|
||||
* @defgroup app_error Common application error handler
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief Common application error handler.
|
||||
*/
|
||||
|
||||
#include "nrf.h"
|
||||
#include <stdio.h>
|
||||
#include "app_error.h"
|
||||
#include "nordic_common.h"
|
||||
#include "sdk_errors.h"
|
||||
|
||||
/**@brief Function for error handling, which is called when an error has occurred.
|
||||
*
|
||||
* @warning This handler is an example only and does not fit a final product. You need to analyze
|
||||
* how your product is supposed to react in case of error.
|
||||
*
|
||||
* @param[in] error_code Error code supplied to the handler.
|
||||
* @param[in] line_num Line number where the handler is called.
|
||||
* @param[in] p_file_name Pointer to the file name.
|
||||
*/
|
||||
void app_error_handler_bare(ret_code_t error_code)
|
||||
{
|
||||
error_info_t error_info =
|
||||
{
|
||||
.line_num = 0,
|
||||
.p_file_name = NULL,
|
||||
.err_code = error_code,
|
||||
};
|
||||
|
||||
app_error_fault_handler(NRF_FAULT_ID_SDK_ERROR, 0, (uint32_t)(&error_info));
|
||||
|
||||
UNUSED_VARIABLE(error_info);
|
||||
}
|
||||
|
||||
/**@brief Function for error handling, which is called when an error has occurred.
|
||||
*
|
||||
* @param[in] error_code Error code supplied to the handler.
|
||||
* @param[in] line_num Line number where the handler is called.
|
||||
* @param[in] p_file_name Pointer to the file name.
|
||||
*/
|
||||
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
|
||||
{
|
||||
UNUSED_VARIABLE(line_num);
|
||||
UNUSED_VARIABLE(p_file_name);
|
||||
|
||||
app_error_handler_bare(error_code);
|
||||
}
|
||||
|
||||
void app_error_save_and_stop(uint32_t id, uint32_t pc, uint32_t info)
|
||||
{
|
||||
/* static error variables - in order to prevent removal by optimizers */
|
||||
static volatile struct
|
||||
{
|
||||
uint32_t fault_id;
|
||||
uint32_t pc;
|
||||
uint32_t error_info;
|
||||
assert_info_t * p_assert_info;
|
||||
error_info_t * p_error_info;
|
||||
ret_code_t err_code;
|
||||
uint32_t line_num;
|
||||
const uint8_t * p_file_name;
|
||||
} m_error_data = {0};
|
||||
|
||||
// The following variable helps Keil keep the call stack visible, in addition, it can be set to
|
||||
// 0 in the debugger to continue executing code after the error check.
|
||||
volatile bool loop = true;
|
||||
UNUSED_VARIABLE(loop);
|
||||
|
||||
m_error_data.fault_id = id;
|
||||
m_error_data.pc = pc;
|
||||
m_error_data.error_info = info;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case NRF_FAULT_ID_SDK_ASSERT:
|
||||
m_error_data.p_assert_info = (assert_info_t *)info;
|
||||
m_error_data.line_num = m_error_data.p_assert_info->line_num;
|
||||
m_error_data.p_file_name = m_error_data.p_assert_info->p_file_name;
|
||||
break;
|
||||
|
||||
case NRF_FAULT_ID_SDK_ERROR:
|
||||
m_error_data.p_error_info = (error_info_t *)info;
|
||||
m_error_data.err_code = m_error_data.p_error_info->err_code;
|
||||
m_error_data.line_num = m_error_data.p_error_info->line_num;
|
||||
m_error_data.p_file_name = m_error_data.p_error_info->p_file_name;
|
||||
break;
|
||||
}
|
||||
|
||||
UNUSED_VARIABLE(m_error_data);
|
||||
|
||||
// If printing is disrupted, remove the irq calls, or set the loop variable to 0 in the debugger.
|
||||
__disable_irq();
|
||||
while (loop);
|
||||
|
||||
__enable_irq();
|
||||
}
|
||||
/**
|
||||
* Copyright (c) 2014 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @file
|
||||
*
|
||||
* @defgroup app_error Common application error handler
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief Common application error handler.
|
||||
*/
|
||||
|
||||
#include "nrf.h"
|
||||
#include <stdio.h>
|
||||
#include "app_error.h"
|
||||
#include "nordic_common.h"
|
||||
#include "sdk_errors.h"
|
||||
|
||||
/**@brief Function for error handling, which is called when an error has occurred.
|
||||
*
|
||||
* @warning This handler is an example only and does not fit a final product. You need to analyze
|
||||
* how your product is supposed to react in case of error.
|
||||
*
|
||||
* @param[in] error_code Error code supplied to the handler.
|
||||
* @param[in] line_num Line number where the handler is called.
|
||||
* @param[in] p_file_name Pointer to the file name.
|
||||
*/
|
||||
void app_error_handler_bare(ret_code_t error_code)
|
||||
{
|
||||
error_info_t error_info =
|
||||
{
|
||||
.line_num = 0,
|
||||
.p_file_name = NULL,
|
||||
.err_code = error_code,
|
||||
};
|
||||
|
||||
app_error_fault_handler(NRF_FAULT_ID_SDK_ERROR, 0, (uint32_t)(&error_info));
|
||||
|
||||
UNUSED_VARIABLE(error_info);
|
||||
}
|
||||
|
||||
/**@brief Function for error handling, which is called when an error has occurred.
|
||||
*
|
||||
* @param[in] error_code Error code supplied to the handler.
|
||||
* @param[in] line_num Line number where the handler is called.
|
||||
* @param[in] p_file_name Pointer to the file name.
|
||||
*/
|
||||
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
|
||||
{
|
||||
UNUSED_VARIABLE(line_num);
|
||||
UNUSED_VARIABLE(p_file_name);
|
||||
|
||||
app_error_handler_bare(error_code);
|
||||
}
|
||||
|
||||
void app_error_save_and_stop(uint32_t id, uint32_t pc, uint32_t info)
|
||||
{
|
||||
/* static error variables - in order to prevent removal by optimizers */
|
||||
static volatile struct
|
||||
{
|
||||
uint32_t fault_id;
|
||||
uint32_t pc;
|
||||
uint32_t error_info;
|
||||
assert_info_t * p_assert_info;
|
||||
error_info_t * p_error_info;
|
||||
ret_code_t err_code;
|
||||
uint32_t line_num;
|
||||
const uint8_t * p_file_name;
|
||||
} m_error_data = {0};
|
||||
|
||||
// The following variable helps Keil keep the call stack visible, in addition, it can be set to
|
||||
// 0 in the debugger to continue executing code after the error check.
|
||||
volatile bool loop = true;
|
||||
UNUSED_VARIABLE(loop);
|
||||
|
||||
m_error_data.fault_id = id;
|
||||
m_error_data.pc = pc;
|
||||
m_error_data.error_info = info;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case NRF_FAULT_ID_SDK_ASSERT:
|
||||
m_error_data.p_assert_info = (assert_info_t *)info;
|
||||
m_error_data.line_num = m_error_data.p_assert_info->line_num;
|
||||
m_error_data.p_file_name = m_error_data.p_assert_info->p_file_name;
|
||||
break;
|
||||
|
||||
case NRF_FAULT_ID_SDK_ERROR:
|
||||
m_error_data.p_error_info = (error_info_t *)info;
|
||||
m_error_data.err_code = m_error_data.p_error_info->err_code;
|
||||
m_error_data.line_num = m_error_data.p_error_info->line_num;
|
||||
m_error_data.p_file_name = m_error_data.p_error_info->p_file_name;
|
||||
break;
|
||||
}
|
||||
|
||||
UNUSED_VARIABLE(m_error_data);
|
||||
|
||||
// If printing is disrupted, remove the irq calls, or set the loop variable to 0 in the debugger.
|
||||
__disable_irq();
|
||||
while (loop);
|
||||
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
+192
-192
@@ -1,192 +1,192 @@
|
||||
/**
|
||||
* Copyright (c) 2013 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @file
|
||||
*
|
||||
* @defgroup app_error Common application error handler
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief Common application error handler and macros for utilizing a common error handler.
|
||||
*/
|
||||
|
||||
#ifndef APP_ERROR_H__
|
||||
#define APP_ERROR_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "sdk_errors.h"
|
||||
#include "nordic_common.h"
|
||||
#include "app_error_weak.h"
|
||||
#ifdef ANT_STACK_SUPPORT_REQD
|
||||
#include "ant_error.h"
|
||||
#endif // ANT_STACK_SUPPORT_REQD
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NRF_FAULT_ID_SDK_RANGE_START (0x00004000) /**< The start of the range of error IDs defined in the SDK. */
|
||||
|
||||
/**@defgroup APP_ERROR_FAULT_IDS Fault ID types
|
||||
* @{ */
|
||||
#define NRF_FAULT_ID_SDK_ERROR (NRF_FAULT_ID_SDK_RANGE_START + 1) /**< An error stemming from a call to @ref APP_ERROR_CHECK or @ref APP_ERROR_CHECK_BOOL. The info parameter is a pointer to an @ref error_info_t variable. */
|
||||
#define NRF_FAULT_ID_SDK_ASSERT (NRF_FAULT_ID_SDK_RANGE_START + 2) /**< An error stemming from a call to ASSERT (nrf_assert.h). The info parameter is a pointer to an @ref assert_info_t variable. */
|
||||
/**@} */
|
||||
|
||||
/**@brief Structure containing info about an error of the type @ref NRF_FAULT_ID_SDK_ERROR.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t line_num; /**< The line number where the error occurred. */
|
||||
uint8_t const * p_file_name; /**< The file in which the error occurred. */
|
||||
uint32_t err_code; /**< The error code representing the error that occurred. */
|
||||
} error_info_t;
|
||||
|
||||
/**@brief Structure containing info about an error of the type @ref NRF_FAULT_ID_SDK_ASSERT.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t line_num; /**< The line number where the error occurred. */
|
||||
uint8_t const * p_file_name; /**< The file in which the error occurred. */
|
||||
} assert_info_t;
|
||||
|
||||
/**@brief Defines required by app_error_handler assembler intructions.
|
||||
*/
|
||||
#define APP_ERROR_ERROR_INFO_OFFSET_LINE_NUM (offsetof(error_info_t, line_num))
|
||||
#define APP_ERROR_ERROR_INFO_OFFSET_P_FILE_NAME (offsetof(error_info_t, p_file_name))
|
||||
#define APP_ERROR_ERROR_INFO_OFFSET_ERR_CODE (offsetof(error_info_t, err_code))
|
||||
#define APP_ERROR_ERROR_INFO_SIZE (sizeof(error_info_t))
|
||||
#define APP_ERROR_ERROR_INFO_SIZE_ALIGNED_8BYTE \
|
||||
ALIGN_NUM(APP_ERROR_ERROR_INFO_SIZE, sizeof(uint64_t))
|
||||
|
||||
|
||||
/**@brief Function for error handling, which is called when an error has occurred.
|
||||
*
|
||||
* @param[in] error_code Error code supplied to the handler.
|
||||
* @param[in] line_num Line number where the handler is called.
|
||||
* @param[in] p_file_name Pointer to the file name.
|
||||
*/
|
||||
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name);
|
||||
|
||||
/**@brief Function for error handling, which is called when an error has occurred.
|
||||
*
|
||||
* @param[in] error_code Error code supplied to the handler.
|
||||
*/
|
||||
void app_error_handler_bare(ret_code_t error_code);
|
||||
|
||||
/**@brief Function for saving the parameters and entering an eternal loop, for debug purposes.
|
||||
*
|
||||
* @param[in] id Fault identifier. See @ref NRF_FAULT_IDS.
|
||||
* @param[in] pc The program counter of the instruction that triggered the fault, or 0 if
|
||||
* unavailable.
|
||||
* @param[in] info Optional additional information regarding the fault. Refer to each fault
|
||||
* identifier for details.
|
||||
*/
|
||||
void app_error_save_and_stop(uint32_t id, uint32_t pc, uint32_t info);
|
||||
|
||||
/**@brief Function for logging details of error and flushing logs.
|
||||
*
|
||||
* @param[in] id Fault identifier. See @ref NRF_FAULT_IDS.
|
||||
* @param[in] pc The program counter of the instruction that triggered the fault, or 0 if
|
||||
* unavailable.
|
||||
* @param[in] info Optional additional information regarding the fault. Refer to each fault
|
||||
* identifier for details.
|
||||
*/
|
||||
void app_error_log_handle(uint32_t id, uint32_t pc, uint32_t info);
|
||||
|
||||
|
||||
/**@brief Macro for calling error handler function.
|
||||
*
|
||||
* @param[in] ERR_CODE Error code supplied to the error handler.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
#define APP_ERROR_HANDLER(ERR_CODE) \
|
||||
do \
|
||||
{ \
|
||||
app_error_handler((ERR_CODE), __LINE__, (uint8_t*) __FILE__); \
|
||||
} while (0)
|
||||
#else
|
||||
#define APP_ERROR_HANDLER(ERR_CODE) \
|
||||
do \
|
||||
{ \
|
||||
app_error_handler_bare((ERR_CODE)); \
|
||||
} while (0)
|
||||
#endif
|
||||
/**@brief Macro for calling error handler function if supplied error code any other than NRF_SUCCESS.
|
||||
*
|
||||
* @param[in] ERR_CODE Error code supplied to the error handler.
|
||||
*/
|
||||
#define APP_ERROR_CHECK(ERR_CODE) \
|
||||
do \
|
||||
{ \
|
||||
const uint32_t LOCAL_ERR_CODE = (ERR_CODE); \
|
||||
if (LOCAL_ERR_CODE != NRF_SUCCESS) \
|
||||
{ \
|
||||
APP_ERROR_HANDLER(LOCAL_ERR_CODE); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**@brief Macro for calling error handler function if supplied boolean value is false.
|
||||
*
|
||||
* @param[in] BOOLEAN_VALUE Boolean value to be evaluated.
|
||||
*/
|
||||
#define APP_ERROR_CHECK_BOOL(BOOLEAN_VALUE) \
|
||||
do \
|
||||
{ \
|
||||
const uint32_t LOCAL_BOOLEAN_VALUE = (BOOLEAN_VALUE); \
|
||||
if (!LOCAL_BOOLEAN_VALUE) \
|
||||
{ \
|
||||
APP_ERROR_HANDLER(0); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APP_ERROR_H__
|
||||
|
||||
/** @} */
|
||||
/**
|
||||
* Copyright (c) 2013 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/** @file
|
||||
*
|
||||
* @defgroup app_error Common application error handler
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief Common application error handler and macros for utilizing a common error handler.
|
||||
*/
|
||||
|
||||
#ifndef APP_ERROR_H__
|
||||
#define APP_ERROR_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "sdk_errors.h"
|
||||
#include "nordic_common.h"
|
||||
#include "app_error_weak.h"
|
||||
#ifdef ANT_STACK_SUPPORT_REQD
|
||||
#include "ant_error.h"
|
||||
#endif // ANT_STACK_SUPPORT_REQD
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NRF_FAULT_ID_SDK_RANGE_START (0x00004000) /**< The start of the range of error IDs defined in the SDK. */
|
||||
|
||||
/**@defgroup APP_ERROR_FAULT_IDS Fault ID types
|
||||
* @{ */
|
||||
#define NRF_FAULT_ID_SDK_ERROR (NRF_FAULT_ID_SDK_RANGE_START + 1) /**< An error stemming from a call to @ref APP_ERROR_CHECK or @ref APP_ERROR_CHECK_BOOL. The info parameter is a pointer to an @ref error_info_t variable. */
|
||||
#define NRF_FAULT_ID_SDK_ASSERT (NRF_FAULT_ID_SDK_RANGE_START + 2) /**< An error stemming from a call to ASSERT (nrf_assert.h). The info parameter is a pointer to an @ref assert_info_t variable. */
|
||||
/**@} */
|
||||
|
||||
/**@brief Structure containing info about an error of the type @ref NRF_FAULT_ID_SDK_ERROR.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t line_num; /**< The line number where the error occurred. */
|
||||
uint8_t const * p_file_name; /**< The file in which the error occurred. */
|
||||
uint32_t err_code; /**< The error code representing the error that occurred. */
|
||||
} error_info_t;
|
||||
|
||||
/**@brief Structure containing info about an error of the type @ref NRF_FAULT_ID_SDK_ASSERT.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t line_num; /**< The line number where the error occurred. */
|
||||
uint8_t const * p_file_name; /**< The file in which the error occurred. */
|
||||
} assert_info_t;
|
||||
|
||||
/**@brief Defines required by app_error_handler assembler intructions.
|
||||
*/
|
||||
#define APP_ERROR_ERROR_INFO_OFFSET_LINE_NUM (offsetof(error_info_t, line_num))
|
||||
#define APP_ERROR_ERROR_INFO_OFFSET_P_FILE_NAME (offsetof(error_info_t, p_file_name))
|
||||
#define APP_ERROR_ERROR_INFO_OFFSET_ERR_CODE (offsetof(error_info_t, err_code))
|
||||
#define APP_ERROR_ERROR_INFO_SIZE (sizeof(error_info_t))
|
||||
#define APP_ERROR_ERROR_INFO_SIZE_ALIGNED_8BYTE \
|
||||
ALIGN_NUM(APP_ERROR_ERROR_INFO_SIZE, sizeof(uint64_t))
|
||||
|
||||
|
||||
/**@brief Function for error handling, which is called when an error has occurred.
|
||||
*
|
||||
* @param[in] error_code Error code supplied to the handler.
|
||||
* @param[in] line_num Line number where the handler is called.
|
||||
* @param[in] p_file_name Pointer to the file name.
|
||||
*/
|
||||
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name);
|
||||
|
||||
/**@brief Function for error handling, which is called when an error has occurred.
|
||||
*
|
||||
* @param[in] error_code Error code supplied to the handler.
|
||||
*/
|
||||
void app_error_handler_bare(ret_code_t error_code);
|
||||
|
||||
/**@brief Function for saving the parameters and entering an eternal loop, for debug purposes.
|
||||
*
|
||||
* @param[in] id Fault identifier. See @ref NRF_FAULT_IDS.
|
||||
* @param[in] pc The program counter of the instruction that triggered the fault, or 0 if
|
||||
* unavailable.
|
||||
* @param[in] info Optional additional information regarding the fault. Refer to each fault
|
||||
* identifier for details.
|
||||
*/
|
||||
void app_error_save_and_stop(uint32_t id, uint32_t pc, uint32_t info);
|
||||
|
||||
/**@brief Function for logging details of error and flushing logs.
|
||||
*
|
||||
* @param[in] id Fault identifier. See @ref NRF_FAULT_IDS.
|
||||
* @param[in] pc The program counter of the instruction that triggered the fault, or 0 if
|
||||
* unavailable.
|
||||
* @param[in] info Optional additional information regarding the fault. Refer to each fault
|
||||
* identifier for details.
|
||||
*/
|
||||
void app_error_log_handle(uint32_t id, uint32_t pc, uint32_t info);
|
||||
|
||||
|
||||
/**@brief Macro for calling error handler function.
|
||||
*
|
||||
* @param[in] ERR_CODE Error code supplied to the error handler.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
#define APP_ERROR_HANDLER(ERR_CODE) \
|
||||
do \
|
||||
{ \
|
||||
app_error_handler((ERR_CODE), __LINE__, (uint8_t*) __FILE__); \
|
||||
} while (0)
|
||||
#else
|
||||
#define APP_ERROR_HANDLER(ERR_CODE) \
|
||||
do \
|
||||
{ \
|
||||
app_error_handler_bare((ERR_CODE)); \
|
||||
} while (0)
|
||||
#endif
|
||||
/**@brief Macro for calling error handler function if supplied error code any other than NRF_SUCCESS.
|
||||
*
|
||||
* @param[in] ERR_CODE Error code supplied to the error handler.
|
||||
*/
|
||||
#define APP_ERROR_CHECK(ERR_CODE) \
|
||||
do \
|
||||
{ \
|
||||
const uint32_t LOCAL_ERR_CODE = (ERR_CODE); \
|
||||
if (LOCAL_ERR_CODE != NRF_SUCCESS) \
|
||||
{ \
|
||||
APP_ERROR_HANDLER(LOCAL_ERR_CODE); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**@brief Macro for calling error handler function if supplied boolean value is false.
|
||||
*
|
||||
* @param[in] BOOLEAN_VALUE Boolean value to be evaluated.
|
||||
*/
|
||||
#define APP_ERROR_CHECK_BOOL(BOOLEAN_VALUE) \
|
||||
do \
|
||||
{ \
|
||||
const uint32_t LOCAL_BOOLEAN_VALUE = (BOOLEAN_VALUE); \
|
||||
if (!LOCAL_BOOLEAN_VALUE) \
|
||||
{ \
|
||||
APP_ERROR_HANDLER(0); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APP_ERROR_H__
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2019, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "app_error.h"
|
||||
|
||||
/*lint -save -e14 */
|
||||
/**
|
||||
* Function is implemented as weak so that it can be overwritten by custom application error handler
|
||||
* when needed.
|
||||
*/
|
||||
__WEAK void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
|
||||
{
|
||||
(void)id;
|
||||
(void)pc;
|
||||
(void)info;
|
||||
|
||||
#ifndef DEBUG
|
||||
NVIC_SystemReset();
|
||||
#else
|
||||
app_error_save_and_stop(id, pc, info);
|
||||
#endif // DEBUG
|
||||
}
|
||||
/*lint -restore */
|
||||
/**
|
||||
* Copyright (c) 2016 - 2019, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "app_error.h"
|
||||
|
||||
/*lint -save -e14 */
|
||||
/**
|
||||
* Function is implemented as weak so that it can be overwritten by custom application error handler
|
||||
* when needed.
|
||||
*/
|
||||
__WEAK void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
|
||||
{
|
||||
(void)id;
|
||||
(void)pc;
|
||||
(void)info;
|
||||
|
||||
#ifndef DEBUG
|
||||
NVIC_SystemReset();
|
||||
#else
|
||||
app_error_save_and_stop(id, pc, info);
|
||||
#endif // DEBUG
|
||||
}
|
||||
/*lint -restore */
|
||||
|
||||
@@ -1,87 +1,87 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_ERROR_WEAK_H__
|
||||
#define APP_ERROR_WEAK_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup app_error Common application error handler
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief Common application error handler.
|
||||
*/
|
||||
|
||||
/**@brief Callback function for errors, asserts, and faults.
|
||||
*
|
||||
* @details This function is called every time an error is raised in app_error, nrf_assert, or
|
||||
* in the SoftDevice. Information about the error can be found in the @p info
|
||||
* parameter.
|
||||
*
|
||||
* See also @ref nrf_fault_handler_t for more details.
|
||||
*
|
||||
* @note The function is implemented as weak so that it can be redefined by a custom error
|
||||
* handler when needed.
|
||||
*
|
||||
* @param[in] id Fault identifier. See @ref NRF_FAULT_IDS.
|
||||
* @param[in] pc The program counter of the instruction that triggered the fault, or 0 if
|
||||
* unavailable.
|
||||
* @param[in] info Optional additional information regarding the fault. The value of the @p id
|
||||
* parameter dictates how to interpret this parameter. Refer to the documentation
|
||||
* for each fault identifier (@ref NRF_FAULT_IDS and @ref APP_ERROR_FAULT_IDS) for
|
||||
* details about interpreting @p info.
|
||||
*/
|
||||
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APP_ERROR_WEAK_H__
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_ERROR_WEAK_H__
|
||||
#define APP_ERROR_WEAK_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup app_error Common application error handler
|
||||
* @{
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief Common application error handler.
|
||||
*/
|
||||
|
||||
/**@brief Callback function for errors, asserts, and faults.
|
||||
*
|
||||
* @details This function is called every time an error is raised in app_error, nrf_assert, or
|
||||
* in the SoftDevice. Information about the error can be found in the @p info
|
||||
* parameter.
|
||||
*
|
||||
* See also @ref nrf_fault_handler_t for more details.
|
||||
*
|
||||
* @note The function is implemented as weak so that it can be redefined by a custom error
|
||||
* handler when needed.
|
||||
*
|
||||
* @param[in] id Fault identifier. See @ref NRF_FAULT_IDS.
|
||||
* @param[in] pc The program counter of the instruction that triggered the fault, or 0 if
|
||||
* unavailable.
|
||||
* @param[in] info Optional additional information regarding the fault. The value of the @p id
|
||||
* parameter dictates how to interpret this parameter. Refer to the documentation
|
||||
* for each fault identifier (@ref NRF_FAULT_IDS and @ref APP_ERROR_FAULT_IDS) for
|
||||
* details about interpreting @p info.
|
||||
*/
|
||||
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APP_ERROR_WEAK_H__
|
||||
|
||||
+189
-189
@@ -1,189 +1,189 @@
|
||||
/**
|
||||
* Copyright (c) 2011 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "app_util.h"
|
||||
#include "nrf_atfifo.h"
|
||||
#include "nrf_atfifo_internal.h"
|
||||
|
||||
#if NRF_ATFIFO_CONFIG_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL NRF_ATFIFO_CONFIG_LOG_LEVEL
|
||||
#define NRF_LOG_INIT_FILTER_LEVEL NRF_ATFIFO_CONFIG_LOG_INIT_FILTER_LEVEL
|
||||
#define NRF_LOG_INFO_COLOR NRF_ATFIFO_CONFIG_INFO_COLOR
|
||||
#define NRF_LOG_DEBUG_COLOR NRF_ATFIFO_CONFIG_DEBUG_COLOR
|
||||
#else
|
||||
#define NRF_LOG_LEVEL 0
|
||||
#endif // NRF_ATFIFO_CONFIG_LOG_ENABLED
|
||||
#include "nrf_log.h"
|
||||
|
||||
/* Unions testing */
|
||||
STATIC_ASSERT(sizeof(nrf_atfifo_postag_t) == sizeof(uint32_t));
|
||||
|
||||
|
||||
ret_code_t nrf_atfifo_init(nrf_atfifo_t * const p_fifo, void * p_buf, uint16_t buf_size, uint16_t item_size)
|
||||
{
|
||||
if (NULL == p_buf)
|
||||
{
|
||||
NRF_LOG_INST_ERROR(p_fifo->p_log, "Initialization failed. p_buf == NULL");
|
||||
return NRF_ERROR_NULL;
|
||||
}
|
||||
if (0 != (buf_size % item_size))
|
||||
{
|
||||
NRF_LOG_INST_ERROR(p_fifo->p_log, "Initialization failed. Buf_size not multiple of item_size");
|
||||
return NRF_ERROR_INVALID_LENGTH;
|
||||
}
|
||||
|
||||
p_fifo->p_buf = p_buf;
|
||||
p_fifo->tail.tag = 0;
|
||||
p_fifo->head.tag = 0;
|
||||
p_fifo->buf_size = buf_size;
|
||||
p_fifo->item_size = item_size;
|
||||
|
||||
NRF_LOG_INST_INFO(p_fifo->p_log, "Initialized.");
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t nrf_atfifo_clear(nrf_atfifo_t * const p_fifo)
|
||||
{
|
||||
bool released = nrf_atfifo_space_clear(p_fifo);
|
||||
NRF_LOG_INST_INFO(p_fifo->p_log, "Cleared result:%s", released ? "success" : "busy");
|
||||
return released ? NRF_SUCCESS : NRF_ERROR_BUSY;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t nrf_atfifo_alloc_put(nrf_atfifo_t * const p_fifo, void const * p_var, size_t size, bool * const p_visible)
|
||||
{
|
||||
nrf_atfifo_item_put_t context;
|
||||
bool visible;
|
||||
void * p_data = nrf_atfifo_item_alloc(p_fifo, &context);
|
||||
if (NULL == p_data)
|
||||
{
|
||||
NRF_LOG_INST_WARNING(p_fifo->p_log, "Copying in element (0x%08X) failed - no space.", p_var);
|
||||
return NRF_ERROR_NO_MEM;
|
||||
}
|
||||
|
||||
memcpy(p_data, p_var, size);
|
||||
|
||||
visible = nrf_atfifo_item_put(p_fifo, &context);
|
||||
if (NULL != p_visible)
|
||||
{
|
||||
*p_visible = visible;
|
||||
}
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Element (0x%08X) copied in.", p_var);
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void * nrf_atfifo_item_alloc(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_put_t * p_context)
|
||||
{
|
||||
if (nrf_atfifo_wspace_req(p_fifo, &(p_context->last_tail)))
|
||||
{
|
||||
void * p_item = ((uint8_t*)(p_fifo->p_buf)) + p_context->last_tail.pos.wr;
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Allocated element (0x%08X).", p_item);
|
||||
return p_item;
|
||||
}
|
||||
NRF_LOG_INST_WARNING(p_fifo->p_log, "Allocation failed - no space.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool nrf_atfifo_item_put(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_put_t * p_context)
|
||||
{
|
||||
if ((p_context->last_tail.pos.wr) == (p_context->last_tail.pos.rd))
|
||||
{
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Put (uninterrupted)");
|
||||
nrf_atfifo_wspace_close(p_fifo);
|
||||
return true;
|
||||
}
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Put (interrupted!)");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t nrf_atfifo_get_free(nrf_atfifo_t * const p_fifo, void * const p_var, size_t size, bool * p_released)
|
||||
{
|
||||
nrf_atfifo_item_get_t context;
|
||||
bool released;
|
||||
void const * p_s = nrf_atfifo_item_get(p_fifo, &context);
|
||||
if (NULL == p_s)
|
||||
{
|
||||
NRF_LOG_INST_WARNING(p_fifo->p_log, "Copying out failed - no item in the FIFO.");
|
||||
return NRF_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
memcpy(p_var, p_s, size);
|
||||
|
||||
released = nrf_atfifo_item_free(p_fifo, &context);
|
||||
if (NULL != p_released)
|
||||
{
|
||||
*p_released = released;
|
||||
}
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Element (0x%08X) copied out.", p_var);
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void * nrf_atfifo_item_get(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_get_t * p_context)
|
||||
{
|
||||
if (nrf_atfifo_rspace_req(p_fifo, &(p_context->last_head)))
|
||||
{
|
||||
void * p_item = ((uint8_t*)(p_fifo->p_buf)) + p_context->last_head.pos.rd;
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Get element: 0x%08X", p_item);
|
||||
return p_item;
|
||||
}
|
||||
NRF_LOG_INST_WARNING(p_fifo->p_log, "Get failed - no item in the FIFO.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool nrf_atfifo_item_free(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_get_t * p_context)
|
||||
{
|
||||
if ((p_context->last_head.pos.wr) == (p_context->last_head.pos.rd))
|
||||
{
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Free (uninterrupted)");
|
||||
nrf_atfifo_rspace_close(p_fifo);
|
||||
return true;
|
||||
}
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Free (interrupted)");
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Copyright (c) 2011 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "app_util.h"
|
||||
#include "nrf_atfifo.h"
|
||||
#include "nrf_atfifo_internal.h"
|
||||
|
||||
#if NRF_ATFIFO_CONFIG_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL NRF_ATFIFO_CONFIG_LOG_LEVEL
|
||||
#define NRF_LOG_INIT_FILTER_LEVEL NRF_ATFIFO_CONFIG_LOG_INIT_FILTER_LEVEL
|
||||
#define NRF_LOG_INFO_COLOR NRF_ATFIFO_CONFIG_INFO_COLOR
|
||||
#define NRF_LOG_DEBUG_COLOR NRF_ATFIFO_CONFIG_DEBUG_COLOR
|
||||
#else
|
||||
#define NRF_LOG_LEVEL 0
|
||||
#endif // NRF_ATFIFO_CONFIG_LOG_ENABLED
|
||||
#include "nrf_log.h"
|
||||
|
||||
/* Unions testing */
|
||||
STATIC_ASSERT(sizeof(nrf_atfifo_postag_t) == sizeof(uint32_t));
|
||||
|
||||
|
||||
ret_code_t nrf_atfifo_init(nrf_atfifo_t * const p_fifo, void * p_buf, uint16_t buf_size, uint16_t item_size)
|
||||
{
|
||||
if (NULL == p_buf)
|
||||
{
|
||||
NRF_LOG_INST_ERROR(p_fifo->p_log, "Initialization failed. p_buf == NULL");
|
||||
return NRF_ERROR_NULL;
|
||||
}
|
||||
if (0 != (buf_size % item_size))
|
||||
{
|
||||
NRF_LOG_INST_ERROR(p_fifo->p_log, "Initialization failed. Buf_size not multiple of item_size");
|
||||
return NRF_ERROR_INVALID_LENGTH;
|
||||
}
|
||||
|
||||
p_fifo->p_buf = p_buf;
|
||||
p_fifo->tail.tag = 0;
|
||||
p_fifo->head.tag = 0;
|
||||
p_fifo->buf_size = buf_size;
|
||||
p_fifo->item_size = item_size;
|
||||
|
||||
NRF_LOG_INST_INFO(p_fifo->p_log, "Initialized.");
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t nrf_atfifo_clear(nrf_atfifo_t * const p_fifo)
|
||||
{
|
||||
bool released = nrf_atfifo_space_clear(p_fifo);
|
||||
NRF_LOG_INST_INFO(p_fifo->p_log, "Cleared result:%s", released ? "success" : "busy");
|
||||
return released ? NRF_SUCCESS : NRF_ERROR_BUSY;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t nrf_atfifo_alloc_put(nrf_atfifo_t * const p_fifo, void const * p_var, size_t size, bool * const p_visible)
|
||||
{
|
||||
nrf_atfifo_item_put_t context;
|
||||
bool visible;
|
||||
void * p_data = nrf_atfifo_item_alloc(p_fifo, &context);
|
||||
if (NULL == p_data)
|
||||
{
|
||||
NRF_LOG_INST_WARNING(p_fifo->p_log, "Copying in element (0x%08X) failed - no space.", p_var);
|
||||
return NRF_ERROR_NO_MEM;
|
||||
}
|
||||
|
||||
memcpy(p_data, p_var, size);
|
||||
|
||||
visible = nrf_atfifo_item_put(p_fifo, &context);
|
||||
if (NULL != p_visible)
|
||||
{
|
||||
*p_visible = visible;
|
||||
}
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Element (0x%08X) copied in.", p_var);
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void * nrf_atfifo_item_alloc(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_put_t * p_context)
|
||||
{
|
||||
if (nrf_atfifo_wspace_req(p_fifo, &(p_context->last_tail)))
|
||||
{
|
||||
void * p_item = ((uint8_t*)(p_fifo->p_buf)) + p_context->last_tail.pos.wr;
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Allocated element (0x%08X).", p_item);
|
||||
return p_item;
|
||||
}
|
||||
NRF_LOG_INST_WARNING(p_fifo->p_log, "Allocation failed - no space.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool nrf_atfifo_item_put(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_put_t * p_context)
|
||||
{
|
||||
if ((p_context->last_tail.pos.wr) == (p_context->last_tail.pos.rd))
|
||||
{
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Put (uninterrupted)");
|
||||
nrf_atfifo_wspace_close(p_fifo);
|
||||
return true;
|
||||
}
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Put (interrupted!)");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t nrf_atfifo_get_free(nrf_atfifo_t * const p_fifo, void * const p_var, size_t size, bool * p_released)
|
||||
{
|
||||
nrf_atfifo_item_get_t context;
|
||||
bool released;
|
||||
void const * p_s = nrf_atfifo_item_get(p_fifo, &context);
|
||||
if (NULL == p_s)
|
||||
{
|
||||
NRF_LOG_INST_WARNING(p_fifo->p_log, "Copying out failed - no item in the FIFO.");
|
||||
return NRF_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
memcpy(p_var, p_s, size);
|
||||
|
||||
released = nrf_atfifo_item_free(p_fifo, &context);
|
||||
if (NULL != p_released)
|
||||
{
|
||||
*p_released = released;
|
||||
}
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Element (0x%08X) copied out.", p_var);
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void * nrf_atfifo_item_get(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_get_t * p_context)
|
||||
{
|
||||
if (nrf_atfifo_rspace_req(p_fifo, &(p_context->last_head)))
|
||||
{
|
||||
void * p_item = ((uint8_t*)(p_fifo->p_buf)) + p_context->last_head.pos.rd;
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Get element: 0x%08X", p_item);
|
||||
return p_item;
|
||||
}
|
||||
NRF_LOG_INST_WARNING(p_fifo->p_log, "Get failed - no item in the FIFO.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
bool nrf_atfifo_item_free(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_get_t * p_context)
|
||||
{
|
||||
if ((p_context->last_head.pos.wr) == (p_context->last_head.pos.rd))
|
||||
{
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Free (uninterrupted)");
|
||||
nrf_atfifo_rspace_close(p_fifo);
|
||||
return true;
|
||||
}
|
||||
NRF_LOG_INST_DEBUG(p_fifo->p_log, "Free (interrupted)");
|
||||
return false;
|
||||
}
|
||||
|
||||
+424
-424
@@ -1,424 +1,424 @@
|
||||
/**
|
||||
* Copyright (c) 2011 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_ATFIFO_H__
|
||||
#define NRF_ATFIFO_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "sdk_config.h"
|
||||
#include "nordic_common.h"
|
||||
#include "nrf_assert.h"
|
||||
#include "sdk_errors.h"
|
||||
#include "nrf_log_instance.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_atfifo Atomic FIFO
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief @tagAPI52 FIFO implementation that allows for making atomic transactions without
|
||||
* locking interrupts.
|
||||
*
|
||||
* @details There are two types of functions to prepare the FIFO writing:
|
||||
* - Single function for simple access:
|
||||
* @code
|
||||
* if (NRF_SUCCESS != nrf_atfifo_simple_put(my_fifo, &data, NULL))
|
||||
* {
|
||||
* // Error handling
|
||||
* }
|
||||
* @endcode
|
||||
* - Function pair to limit data copying:
|
||||
* @code
|
||||
* struct point3d
|
||||
* {
|
||||
* int x, y, z;
|
||||
* }point3d_t;
|
||||
* nrf_atfifo_context_t context;
|
||||
* point3d_t * point;
|
||||
*
|
||||
* if (NULL != (point = nrf_atfifo_item_alloc(my_fifo, &context)))
|
||||
* {
|
||||
* point->x = a;
|
||||
* point->y = b;
|
||||
* point->z = c;
|
||||
* if (nrf_atfifo_item_put(my_fifo, &context))
|
||||
* {
|
||||
* // Send information to the rest of the system
|
||||
* // that there is new data in the FIFO available for reading.
|
||||
* }
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // Error handling
|
||||
* }
|
||||
*
|
||||
* @endcode
|
||||
* @note
|
||||
* This atomic FIFO implementation requires that the operation that is
|
||||
* opened last is finished (committed/flushed) first.
|
||||
* This is typical for operations performed from the interrupt runtime
|
||||
* when the other operation is performed from the main thread.
|
||||
*
|
||||
* This implementation does not support typical multithreading operating system
|
||||
* access where operations can be started and finished in totally unrelated order.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Read and write position structure.
|
||||
*
|
||||
* A structure that holds the read and write position used by the FIFO head and tail.
|
||||
*/
|
||||
typedef struct nrf_atfifo_postag_pos_s
|
||||
{
|
||||
uint16_t wr; //!< First free space to write the data
|
||||
uint16_t rd; //!< A place after the last data to read
|
||||
}nrf_atfifo_postag_pos_t;
|
||||
|
||||
/**
|
||||
* @brief End data index tag.
|
||||
*
|
||||
* A tag used to mark the end of data.
|
||||
* To properly realize atomic data committing, the whole variable has to be
|
||||
* accessed atomically.
|
||||
*/
|
||||
typedef union nrf_atfifo_postag_u
|
||||
{
|
||||
uint32_t tag; //!< Whole tag, used for atomic, 32-bit access
|
||||
nrf_atfifo_postag_pos_t pos; //!< Structure that holds reading and writing position separately
|
||||
}nrf_atfifo_postag_t;
|
||||
|
||||
/**
|
||||
* @brief The FIFO instance.
|
||||
*
|
||||
* The instance of atomic FIFO.
|
||||
* Used with all FIFO functions.
|
||||
*/
|
||||
typedef struct nrf_atfifo_s
|
||||
{
|
||||
void * p_buf; //!< Pointer to the data buffer
|
||||
nrf_atfifo_postag_t tail; //!< Read and write tail position tag
|
||||
nrf_atfifo_postag_t head; //!< Read and write head position tag
|
||||
uint16_t buf_size; //!< FIFO size in number of bytes (has to be divisible by @c item_size)
|
||||
uint16_t item_size; //!< Size of a single FIFO item
|
||||
NRF_LOG_INSTANCE_PTR_DECLARE(p_log) //!< Pointer to instance of the logger object (Conditionally compiled).
|
||||
}nrf_atfifo_t;
|
||||
|
||||
/**
|
||||
* @brief FIFO write operation item context.
|
||||
*
|
||||
* Context structure used to mark an allocated space in FIFO that is ready for put.
|
||||
* All the data required to properly put allocated and written data.
|
||||
*/
|
||||
typedef struct nrf_atfifo_item_put_s
|
||||
{
|
||||
nrf_atfifo_postag_t last_tail; //!< Tail tag value that was here when opening the FIFO to write
|
||||
}nrf_atfifo_item_put_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief FIFO read operation item context.
|
||||
*
|
||||
* Context structure used to mark an opened get operation to properly free an item after reading.
|
||||
*/
|
||||
typedef struct nrf_atfifo_rcontext_s
|
||||
{
|
||||
nrf_atfifo_postag_t last_head; //!< Head tag value that was here when opening the FIFO to read
|
||||
}nrf_atfifo_item_get_t;
|
||||
|
||||
|
||||
/** @brief Name of the module used for logger messaging.
|
||||
*/
|
||||
#define NRF_ATFIFO_LOG_NAME atfifo
|
||||
|
||||
/**
|
||||
* @defgroup nrf_atfifo_instmacros FIFO instance macros
|
||||
*
|
||||
* A group of macros helpful for FIFO instance creation and initialization.
|
||||
* They may be used to create and initialize instances for most use cases.
|
||||
*
|
||||
* FIFO may also be created and initialized directly using
|
||||
* @ref nrf_atfifo_init function.
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Macro for generating the name for a data buffer.
|
||||
*
|
||||
* The name of the data buffer that would be created by
|
||||
* @ref NRF_ATFIFO_DEF macro.
|
||||
*
|
||||
* @param[in] fifo_id Identifier of the FIFO object.
|
||||
*
|
||||
* @return Name of the buffer variable.
|
||||
*
|
||||
* @note This is auxiliary internal macro and in normal usage
|
||||
* it should not be called.
|
||||
*/
|
||||
#define NRF_ATFIFO_BUF_NAME(fifo_id) CONCAT_2(fifo_id, _data)
|
||||
|
||||
/**
|
||||
* @brief Macro for generating the name for a FIFO instance.
|
||||
*
|
||||
* The name of the instance variable that will be created by the
|
||||
* @ref NRF_ATFIFO_DEF macro.
|
||||
*
|
||||
* @param[in] fifo_id Identifier of the FIFO object.
|
||||
*
|
||||
* @return Name of the instance variable.
|
||||
*
|
||||
* @note This is auxiliary internal macro and in normal usage
|
||||
* it should not be called.
|
||||
*/
|
||||
#define NRF_ATFIFO_INST_NAME(fifo_id) CONCAT_2(fifo_id, _inst)
|
||||
|
||||
/**
|
||||
* @brief Macro for creating an instance.
|
||||
*
|
||||
* Creates the FIFO object variable itself.
|
||||
*
|
||||
* Usage example:
|
||||
* @code
|
||||
* NRF_ATFIFO_DEF(my_fifo, uint16_t, 12);
|
||||
* NRF_ATFIFO_INIT(my_fifo);
|
||||
*
|
||||
* uint16_t some_val = 45;
|
||||
* nrf_atfifo_item_put(my_fifo, &some_val, sizeof(some_val), NULL);
|
||||
* nrf_atfifo_item_get(my_fifo, &some_val, sizeof(some_val), NULL);
|
||||
* @endcode
|
||||
*
|
||||
* @param[in] fifo_id Identifier of a FIFO object.
|
||||
* This identifier will be a pointer to the instance.
|
||||
* It makes it possible to use this directly for the functions
|
||||
* that operate on the FIFO.
|
||||
* Because it is a static const object, it should be optimized by the compiler.
|
||||
* @param[in] storage_type Type of data that will be stored in the FIFO.
|
||||
* @param[in] item_cnt Capacity of the created FIFO in maximum number of items that may be stored.
|
||||
* The phisical size of the buffer will be 1 element bigger.
|
||||
*/
|
||||
#define NRF_ATFIFO_DEF(fifo_id, storage_type, item_cnt) \
|
||||
static storage_type NRF_ATFIFO_BUF_NAME(fifo_id)[(item_cnt)+1]; \
|
||||
NRF_LOG_INSTANCE_REGISTER(NRF_ATFIFO_LOG_NAME, fifo_id, \
|
||||
NRF_ATFIFO_CONFIG_INFO_COLOR, \
|
||||
NRF_ATFIFO_CONFIG_DEBUG_COLOR, \
|
||||
NRF_ATFIFO_CONFIG_LOG_INIT_FILTER_LEVEL, \
|
||||
NRF_ATFIFO_CONFIG_LOG_ENABLED ? \
|
||||
NRF_ATFIFO_CONFIG_LOG_LEVEL : NRF_LOG_SEVERITY_NONE); \
|
||||
static nrf_atfifo_t NRF_ATFIFO_INST_NAME(fifo_id) = { \
|
||||
.p_buf = NULL, \
|
||||
NRF_LOG_INSTANCE_PTR_INIT(p_log, NRF_ATFIFO_LOG_NAME, fifo_id) \
|
||||
}; \
|
||||
static nrf_atfifo_t * const fifo_id = &NRF_ATFIFO_INST_NAME(fifo_id)
|
||||
|
||||
/**
|
||||
* @brief Macro for initializing the FIFO that was previously declared by the macro.
|
||||
*
|
||||
* Use this macro to simplify FIFO initialization.
|
||||
*
|
||||
* @note
|
||||
* This macro can be only used on a FIFO object defined by @ref NRF_ATFIFO_DEF macro.
|
||||
*
|
||||
* @param[in] fifo_id Identifier of the FIFO object.
|
||||
*
|
||||
* @return Value from the @ref nrf_atfifo_init function.
|
||||
*/
|
||||
#define NRF_ATFIFO_INIT(fifo_id) \
|
||||
nrf_atfifo_init( \
|
||||
fifo_id, \
|
||||
NRF_ATFIFO_BUF_NAME(fifo_id), \
|
||||
sizeof(NRF_ATFIFO_BUF_NAME(fifo_id)), \
|
||||
sizeof(NRF_ATFIFO_BUF_NAME(fifo_id)[0]) \
|
||||
)
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the FIFO.
|
||||
*
|
||||
* Preparing the FIFO instance to work.
|
||||
*
|
||||
* @param[out] p_fifo FIFO object to initialize.
|
||||
* @param[in,out] p_buf FIFO buffer for storing data.
|
||||
* @param[in] buf_size Total buffer size (has to be divisible by @c item_size).
|
||||
* @param[in] item_size Size of a single item held inside the FIFO.
|
||||
*
|
||||
* @retval NRF_SUCCESS If initialization was successful.
|
||||
* @retval NRF_ERROR_NULL If a NULL pointer is provided as the buffer.
|
||||
* @retval NRF_ERROR_INVALID_LENGTH If size of the buffer provided is not divisible by @c item_size.
|
||||
*
|
||||
* @note
|
||||
* Buffer size must be able to hold one element more than the designed FIFO capacity.
|
||||
* This one, empty element is used for overflow checking.
|
||||
*/
|
||||
ret_code_t nrf_atfifo_init(nrf_atfifo_t * const p_fifo, void * p_buf, uint16_t buf_size, uint16_t item_size);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing the FIFO.
|
||||
*
|
||||
* Function for clearing the FIFO.
|
||||
*
|
||||
* If this function is called during an opened and uncommitted write operation,
|
||||
* the FIFO is cleared up to the currently ongoing commit.
|
||||
* There is no possibility to cancel an ongoing commit.
|
||||
*
|
||||
* If this function is called during an opened and unflushed read operation,
|
||||
* the read position in the head is set, but copying it into the write head position
|
||||
* is left to read closing operation.
|
||||
*
|
||||
* This way, there is no more data to read, but the memory is released
|
||||
* in the moment when it is safe.
|
||||
*
|
||||
* @param[in,out] p_fifo FIFO object.
|
||||
*
|
||||
* @retval NRF_SUCCESS FIFO totally cleared.
|
||||
* @retval NRF_ERROR_BUSY Function called in the middle of writing or reading operation.
|
||||
* If it is called in the middle of writing operation,
|
||||
* FIFO was cleared up to the already started and uncommitted write.
|
||||
* If it is called in the middle of reading operation,
|
||||
* write head was only moved. It will be copied into read tail when the reading operation
|
||||
* is flushed.
|
||||
*/
|
||||
ret_code_t nrf_atfifo_clear(nrf_atfifo_t * const p_fifo);
|
||||
|
||||
/**
|
||||
* @brief Function for atomically putting data into the FIFO.
|
||||
*
|
||||
* It uses memcpy function inside and in most situations, it is more suitable to
|
||||
* use @ref nrf_atfifo_item_alloc, write the data, and @ref nrf_atfifo_item_put to store a new value
|
||||
* in a FIFO.
|
||||
*
|
||||
* @param[in,out] p_fifo FIFO object.
|
||||
* @param[in] p_var Variable to copy.
|
||||
* @param[in] size Size of the variable to copy.
|
||||
* Can be smaller or equal to the FIFO item size.
|
||||
* @param[out] p_visible See value returned by @ref nrf_atfifo_item_put.
|
||||
* It may be NULL if the caller does not require the current operation status.
|
||||
*
|
||||
* @retval NRF_SUCCESS If an element has been successfully added to the FIFO.
|
||||
* @retval NRF_ERROR_NO_MEM If the FIFO is full.
|
||||
*
|
||||
* @note
|
||||
* To avoid data copying, you can use the @ref nrf_atfifo_item_alloc and @ref nrf_atfifo_item_put
|
||||
* functions pair.
|
||||
*/
|
||||
ret_code_t nrf_atfifo_alloc_put(nrf_atfifo_t * const p_fifo, void const * const p_var, size_t size, bool * const p_visible);
|
||||
|
||||
/**
|
||||
* @brief Function for opening the FIFO for writing.
|
||||
*
|
||||
* Function called to start the FIFO write operation and access the given FIFO buffer directly.
|
||||
*
|
||||
* @param[in,out] p_fifo FIFO object.
|
||||
* @param[out] p_context Operation context, required by @ref nrf_atfifo_item_put.
|
||||
*
|
||||
* @return Pointer to the space where variable data can be stored.
|
||||
* NULL if there is no space in the buffer.
|
||||
*/
|
||||
void * nrf_atfifo_item_alloc(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_put_t * p_context);
|
||||
|
||||
/**
|
||||
* @brief Function for closing the writing operation.
|
||||
*
|
||||
* Puts a previously allocated context into FIFO.
|
||||
* This function must be called to commit an opened write operation.
|
||||
* It sets all the buffers and marks the data, so that it is visible to read.
|
||||
*
|
||||
* @param[in,out] p_fifo FIFO object.
|
||||
* @param[in] p_context Operation context, filled by the @ref nrf_atfifo_item_alloc function.
|
||||
*
|
||||
* @retval true Data is currently ready and will be visible to read.
|
||||
* @retval false The internal commit was marked, but the writing operation interrupted another writing operation.
|
||||
* The data will be available to read when the interrupted operation is committed.
|
||||
*/
|
||||
bool nrf_atfifo_item_put(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_put_t * p_context);
|
||||
|
||||
/**
|
||||
* @brief Function for getting a single value from the FIFO.
|
||||
*
|
||||
* This function gets the value from the top of the FIFO.
|
||||
* The value is removed from the FIFO memory.
|
||||
*
|
||||
* @param[in,out] p_fifo FIFO object.
|
||||
* @param[out] p_var Pointer to the variable to store the data.
|
||||
* @param[in] size Size of the data to be loaded.
|
||||
* @param[out] p_released See the values returned by @ref nrf_atfifo_item_free.
|
||||
*
|
||||
* @retval NRF_SUCCESS Element was successfully copied from the FIFO memory.
|
||||
* @retval NRF_ERROR_NOT_FOUND No data in the FIFO.
|
||||
*/
|
||||
ret_code_t nrf_atfifo_get_free(nrf_atfifo_t * const p_fifo, void * const p_var, size_t size, bool * p_released);
|
||||
|
||||
/**
|
||||
* @brief Function for opening the FIFO for reading.
|
||||
*
|
||||
* Function called to start the FIFO read operation and access the given FIFO buffer directly.
|
||||
*
|
||||
* @param[in,out] p_fifo FIFO object.
|
||||
* @param[out] p_context The operation context, required by @ref nrf_atfifo_item_free
|
||||
*
|
||||
* @return Pointer to data buffer or NULL if there is no data in the FIFO.
|
||||
*/
|
||||
void * nrf_atfifo_item_get(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_get_t * p_context);
|
||||
|
||||
/**
|
||||
* @brief Function for closing the reading operation.
|
||||
*
|
||||
* Function used to finish the reading operation.
|
||||
* If this reading operation does not interrupt another reading operation, the head write buffer is moved.
|
||||
* If this reading operation is placed in the middle of another reading, only the new read pointer is written.
|
||||
*
|
||||
* @param[in,out] p_fifo FIFO object.
|
||||
* @param[in] p_context Context of the reading operation to be closed.
|
||||
*
|
||||
* @retval true This operation is not generated in the middle of another read operation and the write head will be updated to the read head (space is released).
|
||||
* @retval false This operation was performed in the middle of another read operation and the write buffer head was not moved (no space is released).
|
||||
*/
|
||||
bool nrf_atfifo_item_free(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_get_t * p_context);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_ATFIFO_H__ */
|
||||
/**
|
||||
* Copyright (c) 2011 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_ATFIFO_H__
|
||||
#define NRF_ATFIFO_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "sdk_config.h"
|
||||
#include "nordic_common.h"
|
||||
#include "nrf_assert.h"
|
||||
#include "sdk_errors.h"
|
||||
#include "nrf_log_instance.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup nrf_atfifo Atomic FIFO
|
||||
* @ingroup app_common
|
||||
*
|
||||
* @brief @tagAPI52 FIFO implementation that allows for making atomic transactions without
|
||||
* locking interrupts.
|
||||
*
|
||||
* @details There are two types of functions to prepare the FIFO writing:
|
||||
* - Single function for simple access:
|
||||
* @code
|
||||
* if (NRF_SUCCESS != nrf_atfifo_simple_put(my_fifo, &data, NULL))
|
||||
* {
|
||||
* // Error handling
|
||||
* }
|
||||
* @endcode
|
||||
* - Function pair to limit data copying:
|
||||
* @code
|
||||
* struct point3d
|
||||
* {
|
||||
* int x, y, z;
|
||||
* }point3d_t;
|
||||
* nrf_atfifo_context_t context;
|
||||
* point3d_t * point;
|
||||
*
|
||||
* if (NULL != (point = nrf_atfifo_item_alloc(my_fifo, &context)))
|
||||
* {
|
||||
* point->x = a;
|
||||
* point->y = b;
|
||||
* point->z = c;
|
||||
* if (nrf_atfifo_item_put(my_fifo, &context))
|
||||
* {
|
||||
* // Send information to the rest of the system
|
||||
* // that there is new data in the FIFO available for reading.
|
||||
* }
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* // Error handling
|
||||
* }
|
||||
*
|
||||
* @endcode
|
||||
* @note
|
||||
* This atomic FIFO implementation requires that the operation that is
|
||||
* opened last is finished (committed/flushed) first.
|
||||
* This is typical for operations performed from the interrupt runtime
|
||||
* when the other operation is performed from the main thread.
|
||||
*
|
||||
* This implementation does not support typical multithreading operating system
|
||||
* access where operations can be started and finished in totally unrelated order.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Read and write position structure.
|
||||
*
|
||||
* A structure that holds the read and write position used by the FIFO head and tail.
|
||||
*/
|
||||
typedef struct nrf_atfifo_postag_pos_s
|
||||
{
|
||||
uint16_t wr; //!< First free space to write the data
|
||||
uint16_t rd; //!< A place after the last data to read
|
||||
}nrf_atfifo_postag_pos_t;
|
||||
|
||||
/**
|
||||
* @brief End data index tag.
|
||||
*
|
||||
* A tag used to mark the end of data.
|
||||
* To properly realize atomic data committing, the whole variable has to be
|
||||
* accessed atomically.
|
||||
*/
|
||||
typedef union nrf_atfifo_postag_u
|
||||
{
|
||||
uint32_t tag; //!< Whole tag, used for atomic, 32-bit access
|
||||
nrf_atfifo_postag_pos_t pos; //!< Structure that holds reading and writing position separately
|
||||
}nrf_atfifo_postag_t;
|
||||
|
||||
/**
|
||||
* @brief The FIFO instance.
|
||||
*
|
||||
* The instance of atomic FIFO.
|
||||
* Used with all FIFO functions.
|
||||
*/
|
||||
typedef struct nrf_atfifo_s
|
||||
{
|
||||
void * p_buf; //!< Pointer to the data buffer
|
||||
nrf_atfifo_postag_t tail; //!< Read and write tail position tag
|
||||
nrf_atfifo_postag_t head; //!< Read and write head position tag
|
||||
uint16_t buf_size; //!< FIFO size in number of bytes (has to be divisible by @c item_size)
|
||||
uint16_t item_size; //!< Size of a single FIFO item
|
||||
NRF_LOG_INSTANCE_PTR_DECLARE(p_log) //!< Pointer to instance of the logger object (Conditionally compiled).
|
||||
}nrf_atfifo_t;
|
||||
|
||||
/**
|
||||
* @brief FIFO write operation item context.
|
||||
*
|
||||
* Context structure used to mark an allocated space in FIFO that is ready for put.
|
||||
* All the data required to properly put allocated and written data.
|
||||
*/
|
||||
typedef struct nrf_atfifo_item_put_s
|
||||
{
|
||||
nrf_atfifo_postag_t last_tail; //!< Tail tag value that was here when opening the FIFO to write
|
||||
}nrf_atfifo_item_put_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief FIFO read operation item context.
|
||||
*
|
||||
* Context structure used to mark an opened get operation to properly free an item after reading.
|
||||
*/
|
||||
typedef struct nrf_atfifo_rcontext_s
|
||||
{
|
||||
nrf_atfifo_postag_t last_head; //!< Head tag value that was here when opening the FIFO to read
|
||||
}nrf_atfifo_item_get_t;
|
||||
|
||||
|
||||
/** @brief Name of the module used for logger messaging.
|
||||
*/
|
||||
#define NRF_ATFIFO_LOG_NAME atfifo
|
||||
|
||||
/**
|
||||
* @defgroup nrf_atfifo_instmacros FIFO instance macros
|
||||
*
|
||||
* A group of macros helpful for FIFO instance creation and initialization.
|
||||
* They may be used to create and initialize instances for most use cases.
|
||||
*
|
||||
* FIFO may also be created and initialized directly using
|
||||
* @ref nrf_atfifo_init function.
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief Macro for generating the name for a data buffer.
|
||||
*
|
||||
* The name of the data buffer that would be created by
|
||||
* @ref NRF_ATFIFO_DEF macro.
|
||||
*
|
||||
* @param[in] fifo_id Identifier of the FIFO object.
|
||||
*
|
||||
* @return Name of the buffer variable.
|
||||
*
|
||||
* @note This is auxiliary internal macro and in normal usage
|
||||
* it should not be called.
|
||||
*/
|
||||
#define NRF_ATFIFO_BUF_NAME(fifo_id) CONCAT_2(fifo_id, _data)
|
||||
|
||||
/**
|
||||
* @brief Macro for generating the name for a FIFO instance.
|
||||
*
|
||||
* The name of the instance variable that will be created by the
|
||||
* @ref NRF_ATFIFO_DEF macro.
|
||||
*
|
||||
* @param[in] fifo_id Identifier of the FIFO object.
|
||||
*
|
||||
* @return Name of the instance variable.
|
||||
*
|
||||
* @note This is auxiliary internal macro and in normal usage
|
||||
* it should not be called.
|
||||
*/
|
||||
#define NRF_ATFIFO_INST_NAME(fifo_id) CONCAT_2(fifo_id, _inst)
|
||||
|
||||
/**
|
||||
* @brief Macro for creating an instance.
|
||||
*
|
||||
* Creates the FIFO object variable itself.
|
||||
*
|
||||
* Usage example:
|
||||
* @code
|
||||
* NRF_ATFIFO_DEF(my_fifo, uint16_t, 12);
|
||||
* NRF_ATFIFO_INIT(my_fifo);
|
||||
*
|
||||
* uint16_t some_val = 45;
|
||||
* nrf_atfifo_item_put(my_fifo, &some_val, sizeof(some_val), NULL);
|
||||
* nrf_atfifo_item_get(my_fifo, &some_val, sizeof(some_val), NULL);
|
||||
* @endcode
|
||||
*
|
||||
* @param[in] fifo_id Identifier of a FIFO object.
|
||||
* This identifier will be a pointer to the instance.
|
||||
* It makes it possible to use this directly for the functions
|
||||
* that operate on the FIFO.
|
||||
* Because it is a static const object, it should be optimized by the compiler.
|
||||
* @param[in] storage_type Type of data that will be stored in the FIFO.
|
||||
* @param[in] item_cnt Capacity of the created FIFO in maximum number of items that may be stored.
|
||||
* The phisical size of the buffer will be 1 element bigger.
|
||||
*/
|
||||
#define NRF_ATFIFO_DEF(fifo_id, storage_type, item_cnt) \
|
||||
static storage_type NRF_ATFIFO_BUF_NAME(fifo_id)[(item_cnt)+1]; \
|
||||
NRF_LOG_INSTANCE_REGISTER(NRF_ATFIFO_LOG_NAME, fifo_id, \
|
||||
NRF_ATFIFO_CONFIG_INFO_COLOR, \
|
||||
NRF_ATFIFO_CONFIG_DEBUG_COLOR, \
|
||||
NRF_ATFIFO_CONFIG_LOG_INIT_FILTER_LEVEL, \
|
||||
NRF_ATFIFO_CONFIG_LOG_ENABLED ? \
|
||||
NRF_ATFIFO_CONFIG_LOG_LEVEL : NRF_LOG_SEVERITY_NONE); \
|
||||
static nrf_atfifo_t NRF_ATFIFO_INST_NAME(fifo_id) = { \
|
||||
.p_buf = NULL, \
|
||||
NRF_LOG_INSTANCE_PTR_INIT(p_log, NRF_ATFIFO_LOG_NAME, fifo_id) \
|
||||
}; \
|
||||
static nrf_atfifo_t * const fifo_id = &NRF_ATFIFO_INST_NAME(fifo_id)
|
||||
|
||||
/**
|
||||
* @brief Macro for initializing the FIFO that was previously declared by the macro.
|
||||
*
|
||||
* Use this macro to simplify FIFO initialization.
|
||||
*
|
||||
* @note
|
||||
* This macro can be only used on a FIFO object defined by @ref NRF_ATFIFO_DEF macro.
|
||||
*
|
||||
* @param[in] fifo_id Identifier of the FIFO object.
|
||||
*
|
||||
* @return Value from the @ref nrf_atfifo_init function.
|
||||
*/
|
||||
#define NRF_ATFIFO_INIT(fifo_id) \
|
||||
nrf_atfifo_init( \
|
||||
fifo_id, \
|
||||
NRF_ATFIFO_BUF_NAME(fifo_id), \
|
||||
sizeof(NRF_ATFIFO_BUF_NAME(fifo_id)), \
|
||||
sizeof(NRF_ATFIFO_BUF_NAME(fifo_id)[0]) \
|
||||
)
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the FIFO.
|
||||
*
|
||||
* Preparing the FIFO instance to work.
|
||||
*
|
||||
* @param[out] p_fifo FIFO object to initialize.
|
||||
* @param[in,out] p_buf FIFO buffer for storing data.
|
||||
* @param[in] buf_size Total buffer size (has to be divisible by @c item_size).
|
||||
* @param[in] item_size Size of a single item held inside the FIFO.
|
||||
*
|
||||
* @retval NRF_SUCCESS If initialization was successful.
|
||||
* @retval NRF_ERROR_NULL If a NULL pointer is provided as the buffer.
|
||||
* @retval NRF_ERROR_INVALID_LENGTH If size of the buffer provided is not divisible by @c item_size.
|
||||
*
|
||||
* @note
|
||||
* Buffer size must be able to hold one element more than the designed FIFO capacity.
|
||||
* This one, empty element is used for overflow checking.
|
||||
*/
|
||||
ret_code_t nrf_atfifo_init(nrf_atfifo_t * const p_fifo, void * p_buf, uint16_t buf_size, uint16_t item_size);
|
||||
|
||||
/**
|
||||
* @brief Function for clearing the FIFO.
|
||||
*
|
||||
* Function for clearing the FIFO.
|
||||
*
|
||||
* If this function is called during an opened and uncommitted write operation,
|
||||
* the FIFO is cleared up to the currently ongoing commit.
|
||||
* There is no possibility to cancel an ongoing commit.
|
||||
*
|
||||
* If this function is called during an opened and unflushed read operation,
|
||||
* the read position in the head is set, but copying it into the write head position
|
||||
* is left to read closing operation.
|
||||
*
|
||||
* This way, there is no more data to read, but the memory is released
|
||||
* in the moment when it is safe.
|
||||
*
|
||||
* @param[in,out] p_fifo FIFO object.
|
||||
*
|
||||
* @retval NRF_SUCCESS FIFO totally cleared.
|
||||
* @retval NRF_ERROR_BUSY Function called in the middle of writing or reading operation.
|
||||
* If it is called in the middle of writing operation,
|
||||
* FIFO was cleared up to the already started and uncommitted write.
|
||||
* If it is called in the middle of reading operation,
|
||||
* write head was only moved. It will be copied into read tail when the reading operation
|
||||
* is flushed.
|
||||
*/
|
||||
ret_code_t nrf_atfifo_clear(nrf_atfifo_t * const p_fifo);
|
||||
|
||||
/**
|
||||
* @brief Function for atomically putting data into the FIFO.
|
||||
*
|
||||
* It uses memcpy function inside and in most situations, it is more suitable to
|
||||
* use @ref nrf_atfifo_item_alloc, write the data, and @ref nrf_atfifo_item_put to store a new value
|
||||
* in a FIFO.
|
||||
*
|
||||
* @param[in,out] p_fifo FIFO object.
|
||||
* @param[in] p_var Variable to copy.
|
||||
* @param[in] size Size of the variable to copy.
|
||||
* Can be smaller or equal to the FIFO item size.
|
||||
* @param[out] p_visible See value returned by @ref nrf_atfifo_item_put.
|
||||
* It may be NULL if the caller does not require the current operation status.
|
||||
*
|
||||
* @retval NRF_SUCCESS If an element has been successfully added to the FIFO.
|
||||
* @retval NRF_ERROR_NO_MEM If the FIFO is full.
|
||||
*
|
||||
* @note
|
||||
* To avoid data copying, you can use the @ref nrf_atfifo_item_alloc and @ref nrf_atfifo_item_put
|
||||
* functions pair.
|
||||
*/
|
||||
ret_code_t nrf_atfifo_alloc_put(nrf_atfifo_t * const p_fifo, void const * const p_var, size_t size, bool * const p_visible);
|
||||
|
||||
/**
|
||||
* @brief Function for opening the FIFO for writing.
|
||||
*
|
||||
* Function called to start the FIFO write operation and access the given FIFO buffer directly.
|
||||
*
|
||||
* @param[in,out] p_fifo FIFO object.
|
||||
* @param[out] p_context Operation context, required by @ref nrf_atfifo_item_put.
|
||||
*
|
||||
* @return Pointer to the space where variable data can be stored.
|
||||
* NULL if there is no space in the buffer.
|
||||
*/
|
||||
void * nrf_atfifo_item_alloc(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_put_t * p_context);
|
||||
|
||||
/**
|
||||
* @brief Function for closing the writing operation.
|
||||
*
|
||||
* Puts a previously allocated context into FIFO.
|
||||
* This function must be called to commit an opened write operation.
|
||||
* It sets all the buffers and marks the data, so that it is visible to read.
|
||||
*
|
||||
* @param[in,out] p_fifo FIFO object.
|
||||
* @param[in] p_context Operation context, filled by the @ref nrf_atfifo_item_alloc function.
|
||||
*
|
||||
* @retval true Data is currently ready and will be visible to read.
|
||||
* @retval false The internal commit was marked, but the writing operation interrupted another writing operation.
|
||||
* The data will be available to read when the interrupted operation is committed.
|
||||
*/
|
||||
bool nrf_atfifo_item_put(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_put_t * p_context);
|
||||
|
||||
/**
|
||||
* @brief Function for getting a single value from the FIFO.
|
||||
*
|
||||
* This function gets the value from the top of the FIFO.
|
||||
* The value is removed from the FIFO memory.
|
||||
*
|
||||
* @param[in,out] p_fifo FIFO object.
|
||||
* @param[out] p_var Pointer to the variable to store the data.
|
||||
* @param[in] size Size of the data to be loaded.
|
||||
* @param[out] p_released See the values returned by @ref nrf_atfifo_item_free.
|
||||
*
|
||||
* @retval NRF_SUCCESS Element was successfully copied from the FIFO memory.
|
||||
* @retval NRF_ERROR_NOT_FOUND No data in the FIFO.
|
||||
*/
|
||||
ret_code_t nrf_atfifo_get_free(nrf_atfifo_t * const p_fifo, void * const p_var, size_t size, bool * p_released);
|
||||
|
||||
/**
|
||||
* @brief Function for opening the FIFO for reading.
|
||||
*
|
||||
* Function called to start the FIFO read operation and access the given FIFO buffer directly.
|
||||
*
|
||||
* @param[in,out] p_fifo FIFO object.
|
||||
* @param[out] p_context The operation context, required by @ref nrf_atfifo_item_free
|
||||
*
|
||||
* @return Pointer to data buffer or NULL if there is no data in the FIFO.
|
||||
*/
|
||||
void * nrf_atfifo_item_get(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_get_t * p_context);
|
||||
|
||||
/**
|
||||
* @brief Function for closing the reading operation.
|
||||
*
|
||||
* Function used to finish the reading operation.
|
||||
* If this reading operation does not interrupt another reading operation, the head write buffer is moved.
|
||||
* If this reading operation is placed in the middle of another reading, only the new read pointer is written.
|
||||
*
|
||||
* @param[in,out] p_fifo FIFO object.
|
||||
* @param[in] p_context Context of the reading operation to be closed.
|
||||
*
|
||||
* @retval true This operation is not generated in the middle of another read operation and the write head will be updated to the read head (space is released).
|
||||
* @retval false This operation was performed in the middle of another read operation and the write buffer head was not moved (no space is released).
|
||||
*/
|
||||
bool nrf_atfifo_item_free(nrf_atfifo_t * const p_fifo, nrf_atfifo_item_get_t * p_context);
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_ATFIFO_H__ */
|
||||
|
||||
+577
-577
File diff suppressed because it is too large
Load Diff
+449
-449
@@ -1,449 +1,449 @@
|
||||
/**
|
||||
* Copyright (c) 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "nrf_atomic.h"
|
||||
|
||||
#ifndef NRF_ATOMIC_USE_BUILD_IN
|
||||
#if (defined(__GNUC__) && defined(WIN32))
|
||||
#define NRF_ATOMIC_USE_BUILD_IN 1
|
||||
#else
|
||||
#define NRF_ATOMIC_USE_BUILD_IN 0
|
||||
#endif
|
||||
#endif // NRF_ATOMIC_USE_BUILD_IN
|
||||
|
||||
#if ((__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U))
|
||||
#define STREX_LDREX_PRESENT
|
||||
#else
|
||||
#include "app_util_platform.h"
|
||||
#endif
|
||||
|
||||
|
||||
#if (NRF_ATOMIC_USE_BUILD_IN == 0) && defined(STREX_LDREX_PRESENT)
|
||||
#include "nrf_atomic_internal.h"
|
||||
#endif
|
||||
|
||||
uint32_t nrf_atomic_u32_fetch_store(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_exchange_n(p_data, value, __ATOMIC_SEQ_CST);
|
||||
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
NRF_ATOMIC_OP(mov, old_val, new_val, p_data, value);
|
||||
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data = value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_store(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
__atomic_store_n(p_data, value, __ATOMIC_SEQ_CST);
|
||||
return value;
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(mov, old_val, new_val, p_data, value);
|
||||
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data = value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_fetch_or(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_or(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(orr, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data |= value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_or(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_or_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(orr, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data |= value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_fetch_and(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_and(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(and, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data &= value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_and(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_and_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(and, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data &= value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_fetch_xor(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_xor(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(eor, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data ^= value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_xor(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_xor_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(eor, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data ^= value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_fetch_add(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_add(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(add, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data += value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_add(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_add_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(add, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data += value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_fetch_sub(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_sub(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(sub, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data -= value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_sub(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_sub_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(sub, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data -= value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
bool nrf_atomic_u32_cmp_exch(nrf_atomic_u32_t * p_data,
|
||||
uint32_t * p_expected,
|
||||
uint32_t desired)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_compare_exchange(p_data,
|
||||
p_expected,
|
||||
&desired,
|
||||
1,
|
||||
__ATOMIC_SEQ_CST,
|
||||
__ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
return nrf_atomic_internal_cmp_exch(p_data, p_expected, desired);
|
||||
#else
|
||||
bool ret;
|
||||
CRITICAL_REGION_ENTER();
|
||||
if (*p_data == *p_expected)
|
||||
{
|
||||
*p_data = desired;
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*p_expected = *p_data;
|
||||
ret = false;
|
||||
}
|
||||
CRITICAL_REGION_EXIT();
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_fetch_sub_hs(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
uint32_t expected = *p_data;
|
||||
uint32_t new_val;
|
||||
bool success;
|
||||
|
||||
do
|
||||
{
|
||||
if (expected >= value)
|
||||
{
|
||||
new_val = expected - value;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_val = expected;
|
||||
}
|
||||
success = __atomic_compare_exchange(p_data,
|
||||
&expected,
|
||||
&new_val,
|
||||
1,
|
||||
__ATOMIC_SEQ_CST,
|
||||
__ATOMIC_SEQ_CST);
|
||||
} while(!success);
|
||||
return expected;
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(sub_hs, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data -= value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_sub_hs(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
uint32_t expected = *p_data;
|
||||
uint32_t new_val;
|
||||
bool success;
|
||||
|
||||
do
|
||||
{
|
||||
if (expected >= value)
|
||||
{
|
||||
new_val = expected - value;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_val = expected;
|
||||
}
|
||||
success = __atomic_compare_exchange(p_data,
|
||||
&expected,
|
||||
&new_val,
|
||||
1,
|
||||
__ATOMIC_SEQ_CST,
|
||||
__ATOMIC_SEQ_CST);
|
||||
} while(!success);
|
||||
return new_val;
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(sub_hs, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data -= value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_flag_set_fetch(nrf_atomic_flag_t * p_data)
|
||||
{
|
||||
return nrf_atomic_u32_fetch_or(p_data, 1);
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_flag_set(nrf_atomic_flag_t * p_data)
|
||||
{
|
||||
return nrf_atomic_u32_or(p_data, 1);
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_flag_clear_fetch(nrf_atomic_flag_t * p_data)
|
||||
{
|
||||
return nrf_atomic_u32_fetch_and(p_data, 0);
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_flag_clear(nrf_atomic_flag_t * p_data)
|
||||
{
|
||||
return nrf_atomic_u32_and(p_data, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copyright (c) 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "nrf_atomic.h"
|
||||
|
||||
#ifndef NRF_ATOMIC_USE_BUILD_IN
|
||||
#if (defined(__GNUC__) && defined(WIN32))
|
||||
#define NRF_ATOMIC_USE_BUILD_IN 1
|
||||
#else
|
||||
#define NRF_ATOMIC_USE_BUILD_IN 0
|
||||
#endif
|
||||
#endif // NRF_ATOMIC_USE_BUILD_IN
|
||||
|
||||
#if ((__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U))
|
||||
#define STREX_LDREX_PRESENT
|
||||
#else
|
||||
#include "app_util_platform.h"
|
||||
#endif
|
||||
|
||||
|
||||
#if (NRF_ATOMIC_USE_BUILD_IN == 0) && defined(STREX_LDREX_PRESENT)
|
||||
#include "nrf_atomic_internal.h"
|
||||
#endif
|
||||
|
||||
uint32_t nrf_atomic_u32_fetch_store(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_exchange_n(p_data, value, __ATOMIC_SEQ_CST);
|
||||
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
NRF_ATOMIC_OP(mov, old_val, new_val, p_data, value);
|
||||
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data = value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_store(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
__atomic_store_n(p_data, value, __ATOMIC_SEQ_CST);
|
||||
return value;
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(mov, old_val, new_val, p_data, value);
|
||||
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data = value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_fetch_or(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_or(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(orr, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data |= value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_or(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_or_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(orr, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data |= value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_fetch_and(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_and(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(and, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data &= value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_and(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_and_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(and, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data &= value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_fetch_xor(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_xor(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(eor, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data ^= value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_xor(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_xor_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(eor, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data ^= value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_fetch_add(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_add(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(add, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data += value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_add(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_add_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(add, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data += value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_fetch_sub(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_fetch_sub(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(sub, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data -= value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_sub(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_sub_fetch(p_data, value, __ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(sub, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data -= value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
bool nrf_atomic_u32_cmp_exch(nrf_atomic_u32_t * p_data,
|
||||
uint32_t * p_expected,
|
||||
uint32_t desired)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
return __atomic_compare_exchange(p_data,
|
||||
p_expected,
|
||||
&desired,
|
||||
1,
|
||||
__ATOMIC_SEQ_CST,
|
||||
__ATOMIC_SEQ_CST);
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
return nrf_atomic_internal_cmp_exch(p_data, p_expected, desired);
|
||||
#else
|
||||
bool ret;
|
||||
CRITICAL_REGION_ENTER();
|
||||
if (*p_data == *p_expected)
|
||||
{
|
||||
*p_data = desired;
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
*p_expected = *p_data;
|
||||
ret = false;
|
||||
}
|
||||
CRITICAL_REGION_EXIT();
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_fetch_sub_hs(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
uint32_t expected = *p_data;
|
||||
uint32_t new_val;
|
||||
bool success;
|
||||
|
||||
do
|
||||
{
|
||||
if (expected >= value)
|
||||
{
|
||||
new_val = expected - value;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_val = expected;
|
||||
}
|
||||
success = __atomic_compare_exchange(p_data,
|
||||
&expected,
|
||||
&new_val,
|
||||
1,
|
||||
__ATOMIC_SEQ_CST,
|
||||
__ATOMIC_SEQ_CST);
|
||||
} while(!success);
|
||||
return expected;
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(sub_hs, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return old_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
uint32_t old_val = *p_data;
|
||||
*p_data -= value;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return old_val;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_u32_sub_hs(nrf_atomic_u32_t * p_data, uint32_t value)
|
||||
{
|
||||
#if NRF_ATOMIC_USE_BUILD_IN
|
||||
uint32_t expected = *p_data;
|
||||
uint32_t new_val;
|
||||
bool success;
|
||||
|
||||
do
|
||||
{
|
||||
if (expected >= value)
|
||||
{
|
||||
new_val = expected - value;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_val = expected;
|
||||
}
|
||||
success = __atomic_compare_exchange(p_data,
|
||||
&expected,
|
||||
&new_val,
|
||||
1,
|
||||
__ATOMIC_SEQ_CST,
|
||||
__ATOMIC_SEQ_CST);
|
||||
} while(!success);
|
||||
return new_val;
|
||||
#elif defined(STREX_LDREX_PRESENT)
|
||||
uint32_t old_val;
|
||||
uint32_t new_val;
|
||||
|
||||
NRF_ATOMIC_OP(sub_hs, old_val, new_val, p_data, value);
|
||||
UNUSED_PARAMETER(old_val);
|
||||
UNUSED_PARAMETER(new_val);
|
||||
return new_val;
|
||||
#else
|
||||
CRITICAL_REGION_ENTER();
|
||||
*p_data -= value;
|
||||
uint32_t new_value = *p_data;
|
||||
CRITICAL_REGION_EXIT();
|
||||
return new_value;
|
||||
#endif //NRF_ATOMIC_USE_BUILD_IN
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_flag_set_fetch(nrf_atomic_flag_t * p_data)
|
||||
{
|
||||
return nrf_atomic_u32_fetch_or(p_data, 1);
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_flag_set(nrf_atomic_flag_t * p_data)
|
||||
{
|
||||
return nrf_atomic_u32_or(p_data, 1);
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_flag_clear_fetch(nrf_atomic_flag_t * p_data)
|
||||
{
|
||||
return nrf_atomic_u32_fetch_and(p_data, 0);
|
||||
}
|
||||
|
||||
uint32_t nrf_atomic_flag_clear(nrf_atomic_flag_t * p_data)
|
||||
{
|
||||
return nrf_atomic_u32_and(p_data, 0);
|
||||
}
|
||||
|
||||
|
||||
+274
-274
@@ -1,274 +1,274 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@file
|
||||
*
|
||||
* @defgroup nrf_atomic Atomic operations API
|
||||
* @ingroup app_common
|
||||
* @{
|
||||
*
|
||||
* @brief @tagAPI52 This module implements C11 stdatomic.h simplified API.
|
||||
At this point only Cortex-M3/M4 cores are supported (LDREX/STREX instructions).
|
||||
* Atomic types are limited to @ref nrf_atomic_u32_t and @ref nrf_atomic_flag_t.
|
||||
*/
|
||||
|
||||
#ifndef NRF_ATOMIC_H__
|
||||
#define NRF_ATOMIC_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
/**
|
||||
* @brief Atomic 32 bit unsigned type
|
||||
* */
|
||||
typedef volatile uint32_t nrf_atomic_u32_t;
|
||||
|
||||
/**
|
||||
* @brief Atomic 1 bit flag type (technically 32 bit)
|
||||
* */
|
||||
typedef volatile uint32_t nrf_atomic_flag_t;
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Stores value to an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value to store
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_fetch_store(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Stores value to an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value to store
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_store(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Logical OR operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand OR operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_fetch_or(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Logical OR operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand OR operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_or(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Logical AND operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand AND operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_fetch_and(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Logical AND operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand AND operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_and(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Logical XOR operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand XOR operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_fetch_xor(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Logical XOR operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand XOR operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_xor(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Arithmetic ADD operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand ADD operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_fetch_add(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Arithmetic ADD operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand ADD operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_add(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Arithmetic SUB operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand SUB operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_fetch_sub(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Arithmetic SUB operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand SUB operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_sub(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief If value at pointer is equal to expected value, changes value at pointer to desired
|
||||
*
|
||||
* Atomically compares the value pointed to by p_data with the value pointed to by p_expected,
|
||||
* and if those are equal, replaces the former with desired. Otherwise, loads the actual value
|
||||
* pointed to by p_data into *p_expected.
|
||||
*
|
||||
* @param p_data Atomic memory pointer to test and modify.
|
||||
* @param p_expected Pointer to test value.
|
||||
* @param desired Value to be stored to atomic memory.
|
||||
*
|
||||
* @retval true *p_data was equal to *p_expected
|
||||
* @retval false *p_data was not equal to *p_expected
|
||||
*/
|
||||
bool nrf_atomic_u32_cmp_exch(nrf_atomic_u32_t * p_data,
|
||||
uint32_t * p_expected,
|
||||
uint32_t desired);
|
||||
|
||||
/**
|
||||
* @brief Arithmetic SUB operation on an atomic object performed if object >= value.
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand SUB operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_fetch_sub_hs(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Arithmetic SUB operation on an atomic object performed if object >= value.
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand SUB operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_sub_hs(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**************************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief Logic one bit flag set operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic flag memory pointer
|
||||
*
|
||||
* @return Old flag value
|
||||
* */
|
||||
uint32_t nrf_atomic_flag_set_fetch(nrf_atomic_flag_t * p_data);
|
||||
|
||||
/**
|
||||
* @brief Logic one bit flag set operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic flag memory pointer
|
||||
*
|
||||
* @return New flag value
|
||||
* */
|
||||
uint32_t nrf_atomic_flag_set(nrf_atomic_flag_t * p_data);
|
||||
|
||||
/**
|
||||
* @brief Logic one bit flag clear operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic flag memory pointer
|
||||
*
|
||||
* @return Old flag value
|
||||
* */
|
||||
uint32_t nrf_atomic_flag_clear_fetch(nrf_atomic_flag_t * p_data);
|
||||
|
||||
/**
|
||||
* @brief Logic one bit flag clear operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic flag memory pointer
|
||||
*
|
||||
* @return New flag value
|
||||
* */
|
||||
uint32_t nrf_atomic_flag_clear(nrf_atomic_flag_t * p_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_ATOMIC_H__ */
|
||||
|
||||
/** @} */
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/**@file
|
||||
*
|
||||
* @defgroup nrf_atomic Atomic operations API
|
||||
* @ingroup app_common
|
||||
* @{
|
||||
*
|
||||
* @brief @tagAPI52 This module implements C11 stdatomic.h simplified API.
|
||||
At this point only Cortex-M3/M4 cores are supported (LDREX/STREX instructions).
|
||||
* Atomic types are limited to @ref nrf_atomic_u32_t and @ref nrf_atomic_flag_t.
|
||||
*/
|
||||
|
||||
#ifndef NRF_ATOMIC_H__
|
||||
#define NRF_ATOMIC_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
/**
|
||||
* @brief Atomic 32 bit unsigned type
|
||||
* */
|
||||
typedef volatile uint32_t nrf_atomic_u32_t;
|
||||
|
||||
/**
|
||||
* @brief Atomic 1 bit flag type (technically 32 bit)
|
||||
* */
|
||||
typedef volatile uint32_t nrf_atomic_flag_t;
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Stores value to an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value to store
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_fetch_store(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Stores value to an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value to store
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_store(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Logical OR operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand OR operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_fetch_or(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Logical OR operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand OR operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_or(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Logical AND operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand AND operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_fetch_and(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Logical AND operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand AND operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_and(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Logical XOR operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand XOR operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_fetch_xor(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Logical XOR operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand XOR operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_xor(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Arithmetic ADD operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand ADD operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_fetch_add(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Arithmetic ADD operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand ADD operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_add(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Arithmetic SUB operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand SUB operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_fetch_sub(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Arithmetic SUB operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand SUB operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_sub(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief If value at pointer is equal to expected value, changes value at pointer to desired
|
||||
*
|
||||
* Atomically compares the value pointed to by p_data with the value pointed to by p_expected,
|
||||
* and if those are equal, replaces the former with desired. Otherwise, loads the actual value
|
||||
* pointed to by p_data into *p_expected.
|
||||
*
|
||||
* @param p_data Atomic memory pointer to test and modify.
|
||||
* @param p_expected Pointer to test value.
|
||||
* @param desired Value to be stored to atomic memory.
|
||||
*
|
||||
* @retval true *p_data was equal to *p_expected
|
||||
* @retval false *p_data was not equal to *p_expected
|
||||
*/
|
||||
bool nrf_atomic_u32_cmp_exch(nrf_atomic_u32_t * p_data,
|
||||
uint32_t * p_expected,
|
||||
uint32_t desired);
|
||||
|
||||
/**
|
||||
* @brief Arithmetic SUB operation on an atomic object performed if object >= value.
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand SUB operation
|
||||
*
|
||||
* @return Old value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_fetch_sub_hs(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Arithmetic SUB operation on an atomic object performed if object >= value.
|
||||
*
|
||||
* @param[in] p_data Atomic memory pointer
|
||||
* @param[in] value Value of second operand SUB operation
|
||||
*
|
||||
* @return New value stored into atomic object
|
||||
* */
|
||||
uint32_t nrf_atomic_u32_sub_hs(nrf_atomic_u32_t * p_data, uint32_t value);
|
||||
|
||||
/**************************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief Logic one bit flag set operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic flag memory pointer
|
||||
*
|
||||
* @return Old flag value
|
||||
* */
|
||||
uint32_t nrf_atomic_flag_set_fetch(nrf_atomic_flag_t * p_data);
|
||||
|
||||
/**
|
||||
* @brief Logic one bit flag set operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic flag memory pointer
|
||||
*
|
||||
* @return New flag value
|
||||
* */
|
||||
uint32_t nrf_atomic_flag_set(nrf_atomic_flag_t * p_data);
|
||||
|
||||
/**
|
||||
* @brief Logic one bit flag clear operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic flag memory pointer
|
||||
*
|
||||
* @return Old flag value
|
||||
* */
|
||||
uint32_t nrf_atomic_flag_clear_fetch(nrf_atomic_flag_t * p_data);
|
||||
|
||||
/**
|
||||
* @brief Logic one bit flag clear operation on an atomic object
|
||||
*
|
||||
* @param[in] p_data Atomic flag memory pointer
|
||||
*
|
||||
* @return New flag value
|
||||
* */
|
||||
uint32_t nrf_atomic_flag_clear(nrf_atomic_flag_t * p_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_ATOMIC_H__ */
|
||||
|
||||
/** @} */
|
||||
|
||||
+343
-343
@@ -1,343 +1,343 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_ATOMIC_INTERNAL_H__
|
||||
#define NRF_ATOMIC_INTERNAL_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
* @defgroup nrf_atomic_internal Atomic operations internals
|
||||
* @ingroup nrf_atomic
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
/* Only Cortex M cores > 3 support LDREX/STREX instructions*/
|
||||
#if ((__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)) == 0
|
||||
#error "Unsupported core version"
|
||||
#endif
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
static __asm uint32_t nrf_atomic_internal_mov(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
/* The base standard provides for passing arguments in core registers (r0-r3) and on the stack.
|
||||
* Registers r4 and r5 have to be saved on stack. Note that only even number of register push are
|
||||
* allowed. This is a requirement of the Procedure Call Standard for the ARM Architecture [AAPCS].
|
||||
* */
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_mov
|
||||
ldrex r0, [r4]
|
||||
mov r5, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_mov
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_orr(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_orr
|
||||
ldrex r0, [r4]
|
||||
orr r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_orr
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_and(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_and
|
||||
ldrex r0, [r4]
|
||||
and r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_and
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_eor(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_eor
|
||||
ldrex r0, [r4]
|
||||
eor r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_eor
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_add(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_add
|
||||
ldrex r0, [r4]
|
||||
add r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_add
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_sub(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_sub
|
||||
ldrex r0, [r4]
|
||||
sub r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_sub
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
static __asm bool nrf_atomic_internal_cmp_exch(nrf_atomic_u32_t * p_data,
|
||||
uint32_t * p_expected,
|
||||
uint32_t value)
|
||||
{
|
||||
#define RET_REG r0
|
||||
#define P_EXPC r1
|
||||
#define VALUE r2
|
||||
#define STR_RES r3
|
||||
#define P_DATA r4
|
||||
#define EXPC_VAL r5
|
||||
#define ACT_VAL r6
|
||||
|
||||
push {r4-r6}
|
||||
mov P_DATA, r0
|
||||
mov RET_REG, #0
|
||||
|
||||
loop_cmp_exch
|
||||
ldrex ACT_VAL, [P_DATA]
|
||||
ldr EXPC_VAL, [P_EXPC]
|
||||
cmp ACT_VAL, EXPC_VAL
|
||||
ittee eq
|
||||
strexeq STR_RES, VALUE, [P_DATA]
|
||||
moveq RET_REG, #1
|
||||
strexne STR_RES, ACT_VAL, [P_DATA]
|
||||
strne ACT_VAL, [P_EXPC]
|
||||
cmp STR_RES, #0
|
||||
itt ne
|
||||
movne RET_REG, #0
|
||||
bne loop_cmp_exch
|
||||
|
||||
pop {r4-r6}
|
||||
bx lr
|
||||
|
||||
#undef RET_REG
|
||||
#undef P_EXPC
|
||||
#undef VALUE
|
||||
#undef STR_RES
|
||||
#undef P_DATA
|
||||
#undef EXPC_VAL
|
||||
#undef ACT_VAL
|
||||
}
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_sub_hs(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_sub_ge
|
||||
ldrex r0, [r4]
|
||||
cmp r0, r1
|
||||
ite hs
|
||||
subhs r5, r0, r1
|
||||
movlo r5, r0
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_sub_ge
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
|
||||
#define NRF_ATOMIC_OP(asm_op, old_val, new_val, ptr, value) \
|
||||
old_val = nrf_atomic_internal_##asm_op(ptr, value, &new_val)
|
||||
|
||||
#elif defined ( __ICCARM__ ) || defined ( __GNUC__ )
|
||||
|
||||
/**
|
||||
* @brief Atomic operation generic macro
|
||||
* @param[in] asm_op operation: mov, orr, and, eor, add, sub
|
||||
* @param[out] old_val atomic object output (uint32_t), value before operation
|
||||
* @param[out] new_val atomic object output (uint32_t), value after operation
|
||||
* @param[in] value atomic operation operand
|
||||
* */
|
||||
#define NRF_ATOMIC_OP(asm_op, old_val, new_val, ptr, value) \
|
||||
{ \
|
||||
uint32_t str_res; \
|
||||
__ASM volatile( \
|
||||
"1: ldrex %["#old_val"], [%["#ptr"]]\n" \
|
||||
NRF_ATOMIC_OP_##asm_op(new_val, old_val, value) \
|
||||
" strex %[str_res], %["#new_val"], [%["#ptr"]]\n" \
|
||||
" teq %[str_res], #0\n" \
|
||||
" bne.n 1b" \
|
||||
: \
|
||||
[old_val]"=&r" (old_val), \
|
||||
[new_val]"=&r" (new_val), \
|
||||
[str_res]"=&r" (str_res) \
|
||||
: \
|
||||
[ptr]"r" (ptr), \
|
||||
[value]"r" (value) \
|
||||
: "cc"); \
|
||||
UNUSED_PARAMETER(str_res); \
|
||||
}
|
||||
|
||||
#define NRF_ATOMIC_OP_mov(new_val, old_val, value) "mov %["#new_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_orr(new_val, old_val, value) "orr %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_and(new_val, old_val, value) "and %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_eor(new_val, old_val, value) "eor %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_add(new_val, old_val, value) "add %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_sub(new_val, old_val, value) "sub %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_sub_hs(new_val, old_val, value) \
|
||||
"cmp %["#old_val"], %["#value"]\n " \
|
||||
"ite hs\n" \
|
||||
"subhs %["#new_val"], %["#old_val"], %["#value"]\n" \
|
||||
"movlo %["#new_val"], %["#old_val"]\n"
|
||||
|
||||
static inline bool nrf_atomic_internal_cmp_exch(nrf_atomic_u32_t * p_data,
|
||||
uint32_t * p_expected,
|
||||
uint32_t value)
|
||||
{
|
||||
bool res = false;
|
||||
uint32_t str_res = 0;
|
||||
uint32_t act_val = 0;
|
||||
uint32_t exp_val = 0;
|
||||
UNUSED_VARIABLE(str_res);
|
||||
UNUSED_VARIABLE(act_val);
|
||||
UNUSED_VARIABLE(exp_val);
|
||||
__ASM volatile(
|
||||
"1: ldrex %[act_val], [%[ptr]]\n"
|
||||
" ldr %[exp_val], [%[expc]]\n"
|
||||
" cmp %[act_val], %[exp_val]\n"
|
||||
" ittee eq\n"
|
||||
" strexeq %[str_res], %[value], [%[ptr]]\n"
|
||||
" moveq %[res], #1\n"
|
||||
" strexne %[str_res], %[act_val], [%[ptr]]\n"
|
||||
" strne %[act_val], [%[expc]]\n"
|
||||
" cmp %[str_res], #0\n"
|
||||
" itt ne\n"
|
||||
" movne %[res], #0\n"
|
||||
" bne.n 1b"
|
||||
:
|
||||
[res] "=&r" (res),
|
||||
[exp_val] "=&r" (exp_val),
|
||||
[act_val] "=&r" (act_val),
|
||||
[str_res] "=&r" (str_res)
|
||||
:
|
||||
"0" (res),
|
||||
"1" (exp_val),
|
||||
"2" (act_val),
|
||||
[expc] "r" (p_expected),
|
||||
[ptr] "r" (p_data),
|
||||
[value] "r" (value)
|
||||
: "cc");
|
||||
return res;
|
||||
}
|
||||
|
||||
#else
|
||||
#error "Unsupported compiler"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_ATOMIC_INTERNAL_H__ */
|
||||
|
||||
/** @} */
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef NRF_ATOMIC_INTERNAL_H__
|
||||
#define NRF_ATOMIC_INTERNAL_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
* @defgroup nrf_atomic_internal Atomic operations internals
|
||||
* @ingroup nrf_atomic
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
/* Only Cortex M cores > 3 support LDREX/STREX instructions*/
|
||||
#if ((__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)) == 0
|
||||
#error "Unsupported core version"
|
||||
#endif
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
static __asm uint32_t nrf_atomic_internal_mov(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
/* The base standard provides for passing arguments in core registers (r0-r3) and on the stack.
|
||||
* Registers r4 and r5 have to be saved on stack. Note that only even number of register push are
|
||||
* allowed. This is a requirement of the Procedure Call Standard for the ARM Architecture [AAPCS].
|
||||
* */
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_mov
|
||||
ldrex r0, [r4]
|
||||
mov r5, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_mov
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_orr(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_orr
|
||||
ldrex r0, [r4]
|
||||
orr r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_orr
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_and(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_and
|
||||
ldrex r0, [r4]
|
||||
and r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_and
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_eor(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_eor
|
||||
ldrex r0, [r4]
|
||||
eor r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_eor
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_add(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_add
|
||||
ldrex r0, [r4]
|
||||
add r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_add
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_sub(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_sub
|
||||
ldrex r0, [r4]
|
||||
sub r5, r0, r1
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_sub
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
static __asm bool nrf_atomic_internal_cmp_exch(nrf_atomic_u32_t * p_data,
|
||||
uint32_t * p_expected,
|
||||
uint32_t value)
|
||||
{
|
||||
#define RET_REG r0
|
||||
#define P_EXPC r1
|
||||
#define VALUE r2
|
||||
#define STR_RES r3
|
||||
#define P_DATA r4
|
||||
#define EXPC_VAL r5
|
||||
#define ACT_VAL r6
|
||||
|
||||
push {r4-r6}
|
||||
mov P_DATA, r0
|
||||
mov RET_REG, #0
|
||||
|
||||
loop_cmp_exch
|
||||
ldrex ACT_VAL, [P_DATA]
|
||||
ldr EXPC_VAL, [P_EXPC]
|
||||
cmp ACT_VAL, EXPC_VAL
|
||||
ittee eq
|
||||
strexeq STR_RES, VALUE, [P_DATA]
|
||||
moveq RET_REG, #1
|
||||
strexne STR_RES, ACT_VAL, [P_DATA]
|
||||
strne ACT_VAL, [P_EXPC]
|
||||
cmp STR_RES, #0
|
||||
itt ne
|
||||
movne RET_REG, #0
|
||||
bne loop_cmp_exch
|
||||
|
||||
pop {r4-r6}
|
||||
bx lr
|
||||
|
||||
#undef RET_REG
|
||||
#undef P_EXPC
|
||||
#undef VALUE
|
||||
#undef STR_RES
|
||||
#undef P_DATA
|
||||
#undef EXPC_VAL
|
||||
#undef ACT_VAL
|
||||
}
|
||||
|
||||
static __asm uint32_t nrf_atomic_internal_sub_hs(nrf_atomic_u32_t * p_ptr,
|
||||
uint32_t value,
|
||||
uint32_t * p_new)
|
||||
{
|
||||
push {r4, r5}
|
||||
mov r4, r0
|
||||
|
||||
loop_sub_ge
|
||||
ldrex r0, [r4]
|
||||
cmp r0, r1
|
||||
ite hs
|
||||
subhs r5, r0, r1
|
||||
movlo r5, r0
|
||||
strex r3, r5, [r4]
|
||||
cmp r3, #0
|
||||
bne loop_sub_ge
|
||||
|
||||
str r5, [r2]
|
||||
pop {r4, r5}
|
||||
bx lr
|
||||
}
|
||||
|
||||
|
||||
#define NRF_ATOMIC_OP(asm_op, old_val, new_val, ptr, value) \
|
||||
old_val = nrf_atomic_internal_##asm_op(ptr, value, &new_val)
|
||||
|
||||
#elif defined ( __ICCARM__ ) || defined ( __GNUC__ )
|
||||
|
||||
/**
|
||||
* @brief Atomic operation generic macro
|
||||
* @param[in] asm_op operation: mov, orr, and, eor, add, sub
|
||||
* @param[out] old_val atomic object output (uint32_t), value before operation
|
||||
* @param[out] new_val atomic object output (uint32_t), value after operation
|
||||
* @param[in] value atomic operation operand
|
||||
* */
|
||||
#define NRF_ATOMIC_OP(asm_op, old_val, new_val, ptr, value) \
|
||||
{ \
|
||||
uint32_t str_res; \
|
||||
__ASM volatile( \
|
||||
"1: ldrex %["#old_val"], [%["#ptr"]]\n" \
|
||||
NRF_ATOMIC_OP_##asm_op(new_val, old_val, value) \
|
||||
" strex %[str_res], %["#new_val"], [%["#ptr"]]\n" \
|
||||
" teq %[str_res], #0\n" \
|
||||
" bne.n 1b" \
|
||||
: \
|
||||
[old_val]"=&r" (old_val), \
|
||||
[new_val]"=&r" (new_val), \
|
||||
[str_res]"=&r" (str_res) \
|
||||
: \
|
||||
[ptr]"r" (ptr), \
|
||||
[value]"r" (value) \
|
||||
: "cc"); \
|
||||
UNUSED_PARAMETER(str_res); \
|
||||
}
|
||||
|
||||
#define NRF_ATOMIC_OP_mov(new_val, old_val, value) "mov %["#new_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_orr(new_val, old_val, value) "orr %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_and(new_val, old_val, value) "and %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_eor(new_val, old_val, value) "eor %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_add(new_val, old_val, value) "add %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_sub(new_val, old_val, value) "sub %["#new_val"], %["#old_val"], %["#value"]\n"
|
||||
#define NRF_ATOMIC_OP_sub_hs(new_val, old_val, value) \
|
||||
"cmp %["#old_val"], %["#value"]\n " \
|
||||
"ite hs\n" \
|
||||
"subhs %["#new_val"], %["#old_val"], %["#value"]\n" \
|
||||
"movlo %["#new_val"], %["#old_val"]\n"
|
||||
|
||||
static inline bool nrf_atomic_internal_cmp_exch(nrf_atomic_u32_t * p_data,
|
||||
uint32_t * p_expected,
|
||||
uint32_t value)
|
||||
{
|
||||
bool res = false;
|
||||
uint32_t str_res = 0;
|
||||
uint32_t act_val = 0;
|
||||
uint32_t exp_val = 0;
|
||||
UNUSED_VARIABLE(str_res);
|
||||
UNUSED_VARIABLE(act_val);
|
||||
UNUSED_VARIABLE(exp_val);
|
||||
__ASM volatile(
|
||||
"1: ldrex %[act_val], [%[ptr]]\n"
|
||||
" ldr %[exp_val], [%[expc]]\n"
|
||||
" cmp %[act_val], %[exp_val]\n"
|
||||
" ittee eq\n"
|
||||
" strexeq %[str_res], %[value], [%[ptr]]\n"
|
||||
" moveq %[res], #1\n"
|
||||
" strexne %[str_res], %[act_val], [%[ptr]]\n"
|
||||
" strne %[act_val], [%[expc]]\n"
|
||||
" cmp %[str_res], #0\n"
|
||||
" itt ne\n"
|
||||
" movne %[res], #0\n"
|
||||
" bne.n 1b"
|
||||
:
|
||||
[res] "=&r" (res),
|
||||
[exp_val] "=&r" (exp_val),
|
||||
[act_val] "=&r" (act_val),
|
||||
[str_res] "=&r" (str_res)
|
||||
:
|
||||
"0" (res),
|
||||
"1" (exp_val),
|
||||
"2" (act_val),
|
||||
[expc] "r" (p_expected),
|
||||
[ptr] "r" (p_data),
|
||||
[value] "r" (value)
|
||||
: "cc");
|
||||
return res;
|
||||
}
|
||||
|
||||
#else
|
||||
#error "Unsupported compiler"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NRF_ATOMIC_INTERNAL_H__ */
|
||||
|
||||
/** @} */
|
||||
|
||||
+80
-80
@@ -1,80 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2011 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _NRF_DELAY_H
|
||||
#define _NRF_DELAY_H
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Function for delaying execution for a number of microseconds.
|
||||
*
|
||||
* @param us_time Number of microseconds to wait.
|
||||
*/
|
||||
#define nrf_delay_us(us_time) NRFX_DELAY_US(us_time)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for delaying execution for a number of milliseconds.
|
||||
*
|
||||
* @param ms_time Number of milliseconds to wait.
|
||||
*/
|
||||
|
||||
__STATIC_INLINE void nrf_delay_ms(uint32_t ms_time)
|
||||
{
|
||||
if (ms_time == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
nrf_delay_us(1000);
|
||||
} while (--ms_time);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/**
|
||||
* Copyright (c) 2011 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _NRF_DELAY_H
|
||||
#define _NRF_DELAY_H
|
||||
|
||||
#include <nrfx.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Function for delaying execution for a number of microseconds.
|
||||
*
|
||||
* @param us_time Number of microseconds to wait.
|
||||
*/
|
||||
#define nrf_delay_us(us_time) NRFX_DELAY_US(us_time)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for delaying execution for a number of milliseconds.
|
||||
*
|
||||
* @param ms_time Number of milliseconds to wait.
|
||||
*/
|
||||
|
||||
__STATIC_INLINE void nrf_delay_ms(uint32_t ms_time)
|
||||
{
|
||||
if (ms_time == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
nrf_delay_us(1000);
|
||||
} while (--ms_time);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+1919
-1919
File diff suppressed because it is too large
Load Diff
+816
-816
File diff suppressed because it is too large
Load Diff
+1103
-1103
File diff suppressed because it is too large
Load Diff
+1235
-1235
File diff suppressed because it is too large
Load Diff
+222
-222
@@ -1,222 +1,222 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_CORE_H__
|
||||
#define APP_USBD_CORE_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include "nrf_drv_usbd.h"
|
||||
#include "app_usbd_types.h"
|
||||
#include "app_usbd_class_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_core USB Device high level library core module
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 Core module that manages current USB state and process device requests.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Core interface configuration.
|
||||
*
|
||||
* Core instance would have 2 endpoints (IN0 and OUT0).
|
||||
* The interface number does not matter because it is not used.
|
||||
*/
|
||||
#define APP_USBD_CORE_CLASS_CONFIGURATION ((0, NRF_DRV_USBD_EPOUT0, NRF_DRV_USBD_EPIN0))
|
||||
|
||||
/**
|
||||
* @brief USB Device state.
|
||||
*
|
||||
* Possible USB Device states according to specification.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
APP_USBD_STATE_Disabled , /**< The whole USBD library is disabled */
|
||||
APP_USBD_STATE_Unattached, /**< Device is currently not connected to the host */
|
||||
APP_USBD_STATE_Powered , /**< Device is connected to the host but has not been enumerated */
|
||||
APP_USBD_STATE_Default , /**< USB Reset condition detected, waiting for the address */
|
||||
APP_USBD_STATE_Addressed , /**< Device has been addressed but has not been configured */
|
||||
APP_USBD_STATE_Configured, /**< Device is addressed and configured */
|
||||
}app_usbd_state_t;
|
||||
|
||||
/**
|
||||
* @brief EP0 handler function pointer.
|
||||
*
|
||||
* Type of the variable that would hold the pointer to the handler for
|
||||
* endpoint 0 messages processing.
|
||||
*
|
||||
* @param p_contex Context variable configured with the transmission request.
|
||||
*/
|
||||
typedef ret_code_t (*app_usbd_core_setup_data_handler_t)(nrf_drv_usbd_ep_status_t status,
|
||||
void * p_context);
|
||||
|
||||
/**
|
||||
* @brief Variable type used to register EP0 transfer handler.
|
||||
*
|
||||
* EP0 messages are processed by core instance.
|
||||
* Another class can register itself to receive messages from EP0 when requesting
|
||||
* for Setup data transfer.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
app_usbd_core_setup_data_handler_t handler; //!< Event handler to be called when transmission is ready
|
||||
void * p_context; //!< Context pointer to be send to every called event.
|
||||
} app_usbd_core_setup_data_handler_desc_t;
|
||||
|
||||
/*lint -save -e10 -e26 -e93 -e123 -e505 */
|
||||
/**
|
||||
* @brief Declare Core instance type.
|
||||
*
|
||||
* USBD core instance type definition.
|
||||
*/
|
||||
APP_USBD_CLASS_TYPEDEF(app_usbd_core,
|
||||
APP_USBD_CORE_CLASS_CONFIGURATION,
|
||||
APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE,
|
||||
APP_USBD_CLASS_DATA_SPECIFIC_DEC_NONE);
|
||||
/*lint -restore*/
|
||||
|
||||
/**
|
||||
* @brief Access to core instance.
|
||||
*
|
||||
* Function that returns pointer to the USBD core instance.
|
||||
*
|
||||
* @return pointer to the core instance.
|
||||
*/
|
||||
static inline app_usbd_class_inst_t const * app_usbd_core_instance_access(void)
|
||||
{
|
||||
extern const APP_USBD_CLASS_INSTANCE_TYPE(app_usbd_core) app_usbd_core_inst;
|
||||
return (app_usbd_class_inst_t const *)&app_usbd_core_inst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable endpoint 0
|
||||
*
|
||||
* Function enables endpoint OUT0 and IN0.
|
||||
* This makes the USB respond to SETUP transfers.
|
||||
*/
|
||||
void app_usbd_core_ep0_enable(void);
|
||||
|
||||
/**
|
||||
* @brief Disable endpoint 0
|
||||
*
|
||||
* Function disables endpoint OUT0 and IN0.
|
||||
* This makes the USB ignore SETUP transfers.
|
||||
*/
|
||||
void app_usbd_core_ep0_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Default simple response to setup command.
|
||||
*
|
||||
* This function generates default simple response.
|
||||
* It sends ZLP when required and on takes care on allowing status stage when
|
||||
* transfer is finished.
|
||||
*
|
||||
* @param p_setup Pointer to original setup message.
|
||||
* @param p_data Pointer to the response. This has to be globaly aviable data.
|
||||
* @param size Total size of the answer - The function takes care about
|
||||
* limiting the size of transfered data to the size required
|
||||
* by setup command.
|
||||
*/
|
||||
ret_code_t app_usbd_core_setup_rsp(app_usbd_setup_t const * p_setup,
|
||||
void const * p_data,
|
||||
size_t size);
|
||||
|
||||
/**
|
||||
* @brief Configure the handler for the nearest setup data endpoint transfer.
|
||||
*
|
||||
* This function would be called on incomming setup data.
|
||||
* The correct place to set the handler for a data is when SETUP command
|
||||
* was received.
|
||||
*
|
||||
* @param ep Endpoint number (only IN0 and OUT0 are supported).
|
||||
* @param p_handler_desc Descriptor of the handler to be called.
|
||||
*
|
||||
* @retval NRF_SUCCESS Successfully configured.
|
||||
* @retval NRF_ERROR_INVALID_ADDR Last received setup direction does not match
|
||||
* configured endpoint.
|
||||
*/
|
||||
ret_code_t app_usbd_core_setup_data_handler_set(
|
||||
nrf_drv_usbd_ep_t ep,
|
||||
app_usbd_core_setup_data_handler_desc_t const * const p_handler_desc);
|
||||
|
||||
/**
|
||||
* @brief Set up a data transfer buffer.
|
||||
*
|
||||
* Returns special internal buffer that can be used in setup transfer.
|
||||
* @return Internal buffer pointer.
|
||||
*/
|
||||
void * app_usbd_core_setup_transfer_buff_get(size_t * p_size);
|
||||
|
||||
|
||||
/**@brief Return internal USBD core state.
|
||||
*
|
||||
* @return Check @ref app_usbd_state_t to find possible USBD core states.
|
||||
*/
|
||||
app_usbd_state_t app_usbd_core_state_get(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Check current feature state.
|
||||
*
|
||||
* Function checks the state of the selected feature that was configured by the host.
|
||||
*
|
||||
* @param feature Feature to check. @ref app_usbd_setup_stdfeature_t
|
||||
* Only features related to the device should be checked by this function.
|
||||
*
|
||||
* @retval true Selected feature is set.
|
||||
* @retval false Selected feature is cleared.
|
||||
*/
|
||||
bool app_usbd_core_feature_state_get(app_usbd_setup_stdfeature_t feature);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_CORE_H__ */
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_CORE_H__
|
||||
#define APP_USBD_CORE_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include "nrf_drv_usbd.h"
|
||||
#include "app_usbd_types.h"
|
||||
#include "app_usbd_class_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_core USB Device high level library core module
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 Core module that manages current USB state and process device requests.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Core interface configuration.
|
||||
*
|
||||
* Core instance would have 2 endpoints (IN0 and OUT0).
|
||||
* The interface number does not matter because it is not used.
|
||||
*/
|
||||
#define APP_USBD_CORE_CLASS_CONFIGURATION ((0, NRF_DRV_USBD_EPOUT0, NRF_DRV_USBD_EPIN0))
|
||||
|
||||
/**
|
||||
* @brief USB Device state.
|
||||
*
|
||||
* Possible USB Device states according to specification.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
APP_USBD_STATE_Disabled , /**< The whole USBD library is disabled */
|
||||
APP_USBD_STATE_Unattached, /**< Device is currently not connected to the host */
|
||||
APP_USBD_STATE_Powered , /**< Device is connected to the host but has not been enumerated */
|
||||
APP_USBD_STATE_Default , /**< USB Reset condition detected, waiting for the address */
|
||||
APP_USBD_STATE_Addressed , /**< Device has been addressed but has not been configured */
|
||||
APP_USBD_STATE_Configured, /**< Device is addressed and configured */
|
||||
}app_usbd_state_t;
|
||||
|
||||
/**
|
||||
* @brief EP0 handler function pointer.
|
||||
*
|
||||
* Type of the variable that would hold the pointer to the handler for
|
||||
* endpoint 0 messages processing.
|
||||
*
|
||||
* @param p_contex Context variable configured with the transmission request.
|
||||
*/
|
||||
typedef ret_code_t (*app_usbd_core_setup_data_handler_t)(nrf_drv_usbd_ep_status_t status,
|
||||
void * p_context);
|
||||
|
||||
/**
|
||||
* @brief Variable type used to register EP0 transfer handler.
|
||||
*
|
||||
* EP0 messages are processed by core instance.
|
||||
* Another class can register itself to receive messages from EP0 when requesting
|
||||
* for Setup data transfer.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
app_usbd_core_setup_data_handler_t handler; //!< Event handler to be called when transmission is ready
|
||||
void * p_context; //!< Context pointer to be send to every called event.
|
||||
} app_usbd_core_setup_data_handler_desc_t;
|
||||
|
||||
/*lint -save -e10 -e26 -e93 -e123 -e505 */
|
||||
/**
|
||||
* @brief Declare Core instance type.
|
||||
*
|
||||
* USBD core instance type definition.
|
||||
*/
|
||||
APP_USBD_CLASS_TYPEDEF(app_usbd_core,
|
||||
APP_USBD_CORE_CLASS_CONFIGURATION,
|
||||
APP_USBD_CLASS_INSTANCE_SPECIFIC_DEC_NONE,
|
||||
APP_USBD_CLASS_DATA_SPECIFIC_DEC_NONE);
|
||||
/*lint -restore*/
|
||||
|
||||
/**
|
||||
* @brief Access to core instance.
|
||||
*
|
||||
* Function that returns pointer to the USBD core instance.
|
||||
*
|
||||
* @return pointer to the core instance.
|
||||
*/
|
||||
static inline app_usbd_class_inst_t const * app_usbd_core_instance_access(void)
|
||||
{
|
||||
extern const APP_USBD_CLASS_INSTANCE_TYPE(app_usbd_core) app_usbd_core_inst;
|
||||
return (app_usbd_class_inst_t const *)&app_usbd_core_inst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable endpoint 0
|
||||
*
|
||||
* Function enables endpoint OUT0 and IN0.
|
||||
* This makes the USB respond to SETUP transfers.
|
||||
*/
|
||||
void app_usbd_core_ep0_enable(void);
|
||||
|
||||
/**
|
||||
* @brief Disable endpoint 0
|
||||
*
|
||||
* Function disables endpoint OUT0 and IN0.
|
||||
* This makes the USB ignore SETUP transfers.
|
||||
*/
|
||||
void app_usbd_core_ep0_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Default simple response to setup command.
|
||||
*
|
||||
* This function generates default simple response.
|
||||
* It sends ZLP when required and on takes care on allowing status stage when
|
||||
* transfer is finished.
|
||||
*
|
||||
* @param p_setup Pointer to original setup message.
|
||||
* @param p_data Pointer to the response. This has to be globaly aviable data.
|
||||
* @param size Total size of the answer - The function takes care about
|
||||
* limiting the size of transfered data to the size required
|
||||
* by setup command.
|
||||
*/
|
||||
ret_code_t app_usbd_core_setup_rsp(app_usbd_setup_t const * p_setup,
|
||||
void const * p_data,
|
||||
size_t size);
|
||||
|
||||
/**
|
||||
* @brief Configure the handler for the nearest setup data endpoint transfer.
|
||||
*
|
||||
* This function would be called on incomming setup data.
|
||||
* The correct place to set the handler for a data is when SETUP command
|
||||
* was received.
|
||||
*
|
||||
* @param ep Endpoint number (only IN0 and OUT0 are supported).
|
||||
* @param p_handler_desc Descriptor of the handler to be called.
|
||||
*
|
||||
* @retval NRF_SUCCESS Successfully configured.
|
||||
* @retval NRF_ERROR_INVALID_ADDR Last received setup direction does not match
|
||||
* configured endpoint.
|
||||
*/
|
||||
ret_code_t app_usbd_core_setup_data_handler_set(
|
||||
nrf_drv_usbd_ep_t ep,
|
||||
app_usbd_core_setup_data_handler_desc_t const * const p_handler_desc);
|
||||
|
||||
/**
|
||||
* @brief Set up a data transfer buffer.
|
||||
*
|
||||
* Returns special internal buffer that can be used in setup transfer.
|
||||
* @return Internal buffer pointer.
|
||||
*/
|
||||
void * app_usbd_core_setup_transfer_buff_get(size_t * p_size);
|
||||
|
||||
|
||||
/**@brief Return internal USBD core state.
|
||||
*
|
||||
* @return Check @ref app_usbd_state_t to find possible USBD core states.
|
||||
*/
|
||||
app_usbd_state_t app_usbd_core_state_get(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Check current feature state.
|
||||
*
|
||||
* Function checks the state of the selected feature that was configured by the host.
|
||||
*
|
||||
* @param feature Feature to check. @ref app_usbd_setup_stdfeature_t
|
||||
* Only features related to the device should be checked by this function.
|
||||
*
|
||||
* @retval true Selected feature is set.
|
||||
* @retval false Selected feature is cleared.
|
||||
*/
|
||||
bool app_usbd_core_feature_state_get(app_usbd_setup_stdfeature_t feature);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_CORE_H__ */
|
||||
|
||||
+337
-337
@@ -1,337 +1,337 @@
|
||||
/**
|
||||
* Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_DESCRIPTOR_H__
|
||||
#define APP_USBD_DESCRIPTOR_H__
|
||||
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_usbd.h"
|
||||
#include "app_usbd_langid.h"
|
||||
#include "app_util_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Compiler support for anonymous unions */
|
||||
ANON_UNIONS_ENABLE;
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_descriptor USB standard descriptors
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 Module with types definitions used for standard descriptors.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Helper macro for translating unsigned 24 bit value to 2 byte raw descriptor.
|
||||
* */
|
||||
#define APP_USBD_U16_TO_RAW_DSC(val) (uint8_t)(val), \
|
||||
(uint8_t)(((val) / (256)))
|
||||
|
||||
/**
|
||||
* @brief Helper macro for translating unsigned 24 bit value to 3 byte raw descriptor.
|
||||
* */
|
||||
#define APP_USBD_U24_TO_RAW_DSC(val) (uint8_t)(val), \
|
||||
(uint8_t)(((val) / (256))), \
|
||||
(uint8_t)(((val) / (256 * 256)))
|
||||
|
||||
/**
|
||||
* @brief Helper macro for translating unsigned 32 bit value to 4 byte raw descriptor.
|
||||
* */
|
||||
#define APP_USBD_U32_TO_RAW_DSC(val) (uint8_t)(val), \
|
||||
(uint8_t)(((val) / (256))), \
|
||||
(uint8_t)(((val) / (256 * 256))) \
|
||||
(uint8_t)(((val) / (256 * 256 * 256)))
|
||||
/**
|
||||
* @brief Descriptor types.
|
||||
*
|
||||
* Descriptor types used in two situations:
|
||||
* - when processing @ref APP_USBD_SETUP_STDREQ_GET_DESCRIPTOR SETUP request,
|
||||
* the required descriptor type may be placed in wValue in HighByte.
|
||||
* - As a descriptor identifier itself inside descriptor stream.
|
||||
*
|
||||
* According to chapter 9.6 of USB 2.0 specification, following descriptors may
|
||||
* be requested directly by GetDescriptor method:
|
||||
* - @ref APP_USBD_DESCRIPTOR_DEVICE
|
||||
* - @ref APP_USBD_DESCRIPTOR_DEVICE_QUALIFIER (not used for FullSpeed only device)
|
||||
* - @ref APP_USBD_DESCRIPTOR_CONFIGURATION
|
||||
* - @ref APP_USBD_DESCRIPTOR_STRING
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
APP_USBD_DESCRIPTOR_DEVICE = 1, /**< Device descriptor. */
|
||||
APP_USBD_DESCRIPTOR_CONFIGURATION = 2, /**<
|
||||
* Specific configuration descriptor.
|
||||
* Configuration descriptor is always followed by all the related interface
|
||||
* and endpoints descriptors.
|
||||
*/
|
||||
APP_USBD_DESCRIPTOR_STRING = 3, /**< String descriptor. */
|
||||
APP_USBD_DESCRIPTOR_INTERFACE = 4, /**<
|
||||
* Interface descriptor followed by all the related endpoints descriptors.
|
||||
*
|
||||
* @note It is returned together with @ref APP_USBD_DESCRIPTOR_CONFIGURATION.
|
||||
* Cannot be accessed by GetDescriptor or SetDescriptor
|
||||
*/
|
||||
APP_USBD_DESCRIPTOR_ENDPOINT = 5, /**<
|
||||
* Endpoint descriptor.
|
||||
*
|
||||
* @note It is returned together with @ref APP_USBD_DESCRIPTOR_CONFIGURATION.
|
||||
* Cannot be accessed by GetDescriptor or SetDescriptor
|
||||
*/
|
||||
APP_USBD_DESCRIPTOR_DEVICE_QUALIFIER = 6, /**< @note Not supported - used only in HighSpeed capable devices. */
|
||||
APP_USBD_DESCRIPTOR_OTHER_SPEED_CONFIGURATION = 7, /**< @note Not supported - our USB implementation supports only one speed. */
|
||||
APP_USBD_DESCRIPTOR_INTERFACE_POWER = 8, /**< @note Not supported */
|
||||
APP_USBD_DESCRIPTOR_OTG = 9, /**< @note Not supported - Our USB have not OTG functionality */
|
||||
APP_USBD_DESCRIPTOR_DEBUG = 10, /**< Debug channel descriptor if available, can be only reached by GetDescriptor */
|
||||
APP_USBD_DESCRIPTOR_INTERFACE_ASSOCIATION = 11, /**<
|
||||
* Descriptor used to describe that two or more interfaces are associated to the same function.
|
||||
*
|
||||
* @note It is returned together with @ref APP_USBD_DESCRIPTOR_CONFIGURATION.
|
||||
* Cannot be accessed by GetDescriptor or SetDescriptor
|
||||
*/
|
||||
APP_USBD_DESCRIPTOR_REPORT = 34, /**< HID Report descriptor. */
|
||||
APP_USBD_DESCRIPTOR_PHYSICAL = 35 /**< HID Physical descriptor. */
|
||||
|
||||
} app_usbd_descriptor_t;
|
||||
|
||||
/* Make all descriptors packed */
|
||||
#pragma pack(push, 1)
|
||||
|
||||
/**
|
||||
* @brief Common descriptor header.
|
||||
*
|
||||
* The header that we can find on the beginning of all descriptors that contains
|
||||
* the descriptor length and type.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< Size of the descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< Should equal one of @ref app_usbd_descriptor_t.
|
||||
/** Class specific descriptors values are defined inside classes. */
|
||||
} app_usbd_descriptor_header_t;
|
||||
|
||||
/**
|
||||
* @brief Device descriptor.
|
||||
*
|
||||
* Descriptor used for the whole device.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< Size of the descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< Should equal to @ref APP_USBD_DESCRIPTOR_DEVICE.
|
||||
uint16_t bcdUSB; //!< USB Specification Release Number in Binary-Coded Decimal
|
||||
uint8_t bDeviceClass; //!< Device class code.
|
||||
/**< If 0, each interface specifies its own class information.
|
||||
* 0xFF for vendor-specific.
|
||||
*/
|
||||
uint8_t bDeviceSubClass; //!< Subclass code.
|
||||
/**< If bDevice Class is set to value other than 0xFF,
|
||||
* all values here are reserved for assignment by USB-IF.
|
||||
*/
|
||||
uint8_t bDeviceProtocol; //!< Subclass code.
|
||||
/**< If 0, no specific protocol is defined on device basis.
|
||||
* Each interface may define its own protocol then.
|
||||
* If set to 0xFF, vendor-specific protocol is used.
|
||||
*/
|
||||
uint8_t bMaxPacketSize0; //!< Maximum packet size for endpoint zero.
|
||||
uint16_t idVendor; //!< Vendor ID (Assigned by the USB-IF).
|
||||
uint16_t idProduct; //!< Product ID (assigned by manufacturer).
|
||||
uint16_t bcdDevice; //!< Device release number in binary-coded decimal.
|
||||
uint8_t iManufacturer; //!< Index of string descriptor in describing manufacturer.
|
||||
uint8_t iProduct; //!< Index of string descriptor in describing product.
|
||||
uint8_t iSerialNumber; //!< Index of string descriptor in describing the device's serial number.
|
||||
uint8_t bNumConfigurations; //!< Number of possible configurations.
|
||||
} app_usbd_descriptor_device_t;
|
||||
|
||||
/**
|
||||
* @brief Attributes masks.
|
||||
*
|
||||
* Masks used for attributes in configuration.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** This is reserved descriptor that has always to be set */
|
||||
APP_USBD_DESCRIPTOR_CONFIGURATION_ATTRIBUTE_ALWAYS_SET_MASK = 1U << 7,
|
||||
/** Attribute that informs that device is self powered */
|
||||
APP_USBD_DESCRIPTOR_CONFIGURATION_ATTRIBUTE_SELF_POWERED_MASK = 1U << 6,
|
||||
/** Attribute that informs that device has Remove Wakeup functionality */
|
||||
APP_USBD_DESCRIPTOR_CONFIGURATION_ATTRIBUTE_REMOTE_WAKEUP_MASK = 1U << 5
|
||||
} app_usbd_descriptor_configuration_attributes_t;
|
||||
|
||||
/**
|
||||
* @brief Configuration descriptor.
|
||||
*
|
||||
* Descriptor used at the beginning of configuration response.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< Size of the descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< Should equal to @ref APP_USBD_DESCRIPTOR_DEVICE.
|
||||
uint16_t wTotalLength; //!< Total length of configuration data, including all descriptors returned after configuration itself.
|
||||
uint8_t bNumInterfaces; //!< Number of interfaces supportedf by this configuration
|
||||
uint8_t bConfigurationValue; //!< Value to use as an argument to the SetConfiguration request.
|
||||
uint8_t iConfiguration; //!< Index of string descriptor describing this configuration.
|
||||
uint8_t bmAttributes; //!< Configuration characteristics.
|
||||
uint8_t bMaxPower; //!< Maximum power consumption. Expressed in 2 mA units.
|
||||
} app_usbd_descriptor_configuration_t;
|
||||
|
||||
/**
|
||||
* @brief Raw descriptor - String descriptor zero.
|
||||
*
|
||||
* String descriptor sent only as a response for GetDescriptor.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< Size of the descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< Should equal to @ref APP_USBD_DESCRIPTOR_STRING.
|
||||
uint16_t wLANGID[]; //!< The array of LANGID codes supported by the device.
|
||||
} app_usbd_descriptor_string0_t;
|
||||
|
||||
/**
|
||||
* @brief Raw descriptor - Any normal string.
|
||||
*
|
||||
* String descriptor sent only as a response for GetDescriptor.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< Size of the descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< Should equal to @ref APP_USBD_DESCRIPTOR_STRING.
|
||||
uint16_t bString[]; //!< UNICODE encoded string.
|
||||
} app_usbd_descriptor_string_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Interface descriptor.
|
||||
*
|
||||
* Interface descriptor, returned as a part of configuration descriptor.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< Size of the descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< Should equal to @ref APP_USBD_DESCRIPTOR_INTERFACE.
|
||||
uint8_t bInterfaceNumber; //!< Number of this interface.
|
||||
uint8_t bAlternateSetting; //!< Value used to select this alternate setting.
|
||||
uint8_t bNumEndpoints; //!< Number of endpoints used by this interface.
|
||||
uint8_t bInterfaceClass; //!< Class code (assigned by the USB-IF). 0xff for vendor specific.
|
||||
uint8_t bInterfaceSubClass; //!< Subclass code (assigned by the USB-IF).
|
||||
uint8_t bInterfaceProtocol; //!< Protocol code (assigned by the USB-IF). 0xff for vendor specific.
|
||||
uint8_t iInterface; //!< Index of string descriptor describing this interface.
|
||||
} app_usbd_descriptor_iface_t;
|
||||
|
||||
/** Offset of endpoint type attribute bits */
|
||||
#define APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_OFFSET 0
|
||||
/** Mask of endpoint type attribute bits */
|
||||
#define APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_MASK BF_MASK(2, APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_OFFSET)
|
||||
|
||||
/** Offset of endpoint synchronization type attribute bits */
|
||||
#define APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_OFFSET 2
|
||||
/** Mask of endpoint synchronization type attribute bits */
|
||||
#define APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_MASK BF_MASK(2, APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_OFFSET)
|
||||
|
||||
/** Offset of endpoint usage type attribute bits */
|
||||
#define APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_OFFSET 4
|
||||
/** Mask of endpoint usage type attribute bits */
|
||||
#define APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_MASK BF_MASK(2, APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_OFFSET)
|
||||
|
||||
/**
|
||||
* @brief Endpoint attributes mnemonics.
|
||||
*
|
||||
* @sa APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_OFFSET APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_MASK
|
||||
* @sa APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_OFFSET APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_MASK
|
||||
* @sa APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_OFFSET APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_MASK
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_CONTROL = 0 << APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_ISOCHRONOUS = 1 << APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_BULK = 2 << APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_INTERRUPT = 3 << APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_OFFSET,
|
||||
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_NONE = 0 << APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_ASYNCHRONOUS = 1 << APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_ADAPTIVE = 2 << APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_SYNCHRONOUS = 3 << APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_OFFSET,
|
||||
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_DATA = 0 << APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_FEEDBACK = 1 << APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_IMPLICIT = 2 << APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_OFFSET
|
||||
} app_usbd_descriptor_ep_attr_bitmap_t;
|
||||
|
||||
/**
|
||||
* @brief Endpoint descriptor.
|
||||
*
|
||||
* Endpoint descriptor, returned as a part of configuration descriptor.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< Size of the descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< Should equal to @ref APP_USBD_DESCRIPTOR_ENDPOINT.
|
||||
uint8_t bEndpointAddress; //!< Endpoint address
|
||||
uint8_t bmAttributes; //!< Endpoint attributes
|
||||
uint16_t wMaxPacketSize; //!< Maximum packet size this endpoint is capable of handling.
|
||||
uint8_t bInterval; //!< Interval for pooling endpoint for data transfers.
|
||||
} app_usbd_descriptor_ep_t;
|
||||
|
||||
/**
|
||||
* @brief Interface association descriptor.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< size of this descriptor in bytes
|
||||
uint8_t bDescriptorType; //!< INTERFACE descriptor type
|
||||
uint8_t bFirstInterface; //!< Number of interface
|
||||
uint8_t bInterfaceCount; //!< value to select alternate setting
|
||||
uint8_t bFunctionClass; //!< Class code assigned by the USB
|
||||
uint8_t bFunctionSubClass;//!< Sub-class code assigned by the USB
|
||||
uint8_t bFunctionProtocol;//!< Protocol code assigned by the USB
|
||||
uint8_t iFunction; //!< Index of string descriptor
|
||||
} app_usbd_descriptor_iad_t;
|
||||
|
||||
#pragma pack(pop)
|
||||
ANON_UNIONS_DISABLE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif /* APP_USBD_DESCRIPTOR_H__ */
|
||||
/**
|
||||
* Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_DESCRIPTOR_H__
|
||||
#define APP_USBD_DESCRIPTOR_H__
|
||||
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_usbd.h"
|
||||
#include "app_usbd_langid.h"
|
||||
#include "app_util_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Compiler support for anonymous unions */
|
||||
ANON_UNIONS_ENABLE;
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_descriptor USB standard descriptors
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 Module with types definitions used for standard descriptors.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Helper macro for translating unsigned 24 bit value to 2 byte raw descriptor.
|
||||
* */
|
||||
#define APP_USBD_U16_TO_RAW_DSC(val) (uint8_t)(val), \
|
||||
(uint8_t)(((val) / (256)))
|
||||
|
||||
/**
|
||||
* @brief Helper macro for translating unsigned 24 bit value to 3 byte raw descriptor.
|
||||
* */
|
||||
#define APP_USBD_U24_TO_RAW_DSC(val) (uint8_t)(val), \
|
||||
(uint8_t)(((val) / (256))), \
|
||||
(uint8_t)(((val) / (256 * 256)))
|
||||
|
||||
/**
|
||||
* @brief Helper macro for translating unsigned 32 bit value to 4 byte raw descriptor.
|
||||
* */
|
||||
#define APP_USBD_U32_TO_RAW_DSC(val) (uint8_t)(val), \
|
||||
(uint8_t)(((val) / (256))), \
|
||||
(uint8_t)(((val) / (256 * 256))) \
|
||||
(uint8_t)(((val) / (256 * 256 * 256)))
|
||||
/**
|
||||
* @brief Descriptor types.
|
||||
*
|
||||
* Descriptor types used in two situations:
|
||||
* - when processing @ref APP_USBD_SETUP_STDREQ_GET_DESCRIPTOR SETUP request,
|
||||
* the required descriptor type may be placed in wValue in HighByte.
|
||||
* - As a descriptor identifier itself inside descriptor stream.
|
||||
*
|
||||
* According to chapter 9.6 of USB 2.0 specification, following descriptors may
|
||||
* be requested directly by GetDescriptor method:
|
||||
* - @ref APP_USBD_DESCRIPTOR_DEVICE
|
||||
* - @ref APP_USBD_DESCRIPTOR_DEVICE_QUALIFIER (not used for FullSpeed only device)
|
||||
* - @ref APP_USBD_DESCRIPTOR_CONFIGURATION
|
||||
* - @ref APP_USBD_DESCRIPTOR_STRING
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
APP_USBD_DESCRIPTOR_DEVICE = 1, /**< Device descriptor. */
|
||||
APP_USBD_DESCRIPTOR_CONFIGURATION = 2, /**<
|
||||
* Specific configuration descriptor.
|
||||
* Configuration descriptor is always followed by all the related interface
|
||||
* and endpoints descriptors.
|
||||
*/
|
||||
APP_USBD_DESCRIPTOR_STRING = 3, /**< String descriptor. */
|
||||
APP_USBD_DESCRIPTOR_INTERFACE = 4, /**<
|
||||
* Interface descriptor followed by all the related endpoints descriptors.
|
||||
*
|
||||
* @note It is returned together with @ref APP_USBD_DESCRIPTOR_CONFIGURATION.
|
||||
* Cannot be accessed by GetDescriptor or SetDescriptor
|
||||
*/
|
||||
APP_USBD_DESCRIPTOR_ENDPOINT = 5, /**<
|
||||
* Endpoint descriptor.
|
||||
*
|
||||
* @note It is returned together with @ref APP_USBD_DESCRIPTOR_CONFIGURATION.
|
||||
* Cannot be accessed by GetDescriptor or SetDescriptor
|
||||
*/
|
||||
APP_USBD_DESCRIPTOR_DEVICE_QUALIFIER = 6, /**< @note Not supported - used only in HighSpeed capable devices. */
|
||||
APP_USBD_DESCRIPTOR_OTHER_SPEED_CONFIGURATION = 7, /**< @note Not supported - our USB implementation supports only one speed. */
|
||||
APP_USBD_DESCRIPTOR_INTERFACE_POWER = 8, /**< @note Not supported */
|
||||
APP_USBD_DESCRIPTOR_OTG = 9, /**< @note Not supported - Our USB have not OTG functionality */
|
||||
APP_USBD_DESCRIPTOR_DEBUG = 10, /**< Debug channel descriptor if available, can be only reached by GetDescriptor */
|
||||
APP_USBD_DESCRIPTOR_INTERFACE_ASSOCIATION = 11, /**<
|
||||
* Descriptor used to describe that two or more interfaces are associated to the same function.
|
||||
*
|
||||
* @note It is returned together with @ref APP_USBD_DESCRIPTOR_CONFIGURATION.
|
||||
* Cannot be accessed by GetDescriptor or SetDescriptor
|
||||
*/
|
||||
APP_USBD_DESCRIPTOR_REPORT = 34, /**< HID Report descriptor. */
|
||||
APP_USBD_DESCRIPTOR_PHYSICAL = 35 /**< HID Physical descriptor. */
|
||||
|
||||
} app_usbd_descriptor_t;
|
||||
|
||||
/* Make all descriptors packed */
|
||||
#pragma pack(push, 1)
|
||||
|
||||
/**
|
||||
* @brief Common descriptor header.
|
||||
*
|
||||
* The header that we can find on the beginning of all descriptors that contains
|
||||
* the descriptor length and type.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< Size of the descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< Should equal one of @ref app_usbd_descriptor_t.
|
||||
/** Class specific descriptors values are defined inside classes. */
|
||||
} app_usbd_descriptor_header_t;
|
||||
|
||||
/**
|
||||
* @brief Device descriptor.
|
||||
*
|
||||
* Descriptor used for the whole device.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< Size of the descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< Should equal to @ref APP_USBD_DESCRIPTOR_DEVICE.
|
||||
uint16_t bcdUSB; //!< USB Specification Release Number in Binary-Coded Decimal
|
||||
uint8_t bDeviceClass; //!< Device class code.
|
||||
/**< If 0, each interface specifies its own class information.
|
||||
* 0xFF for vendor-specific.
|
||||
*/
|
||||
uint8_t bDeviceSubClass; //!< Subclass code.
|
||||
/**< If bDevice Class is set to value other than 0xFF,
|
||||
* all values here are reserved for assignment by USB-IF.
|
||||
*/
|
||||
uint8_t bDeviceProtocol; //!< Subclass code.
|
||||
/**< If 0, no specific protocol is defined on device basis.
|
||||
* Each interface may define its own protocol then.
|
||||
* If set to 0xFF, vendor-specific protocol is used.
|
||||
*/
|
||||
uint8_t bMaxPacketSize0; //!< Maximum packet size for endpoint zero.
|
||||
uint16_t idVendor; //!< Vendor ID (Assigned by the USB-IF).
|
||||
uint16_t idProduct; //!< Product ID (assigned by manufacturer).
|
||||
uint16_t bcdDevice; //!< Device release number in binary-coded decimal.
|
||||
uint8_t iManufacturer; //!< Index of string descriptor in describing manufacturer.
|
||||
uint8_t iProduct; //!< Index of string descriptor in describing product.
|
||||
uint8_t iSerialNumber; //!< Index of string descriptor in describing the device's serial number.
|
||||
uint8_t bNumConfigurations; //!< Number of possible configurations.
|
||||
} app_usbd_descriptor_device_t;
|
||||
|
||||
/**
|
||||
* @brief Attributes masks.
|
||||
*
|
||||
* Masks used for attributes in configuration.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
/** This is reserved descriptor that has always to be set */
|
||||
APP_USBD_DESCRIPTOR_CONFIGURATION_ATTRIBUTE_ALWAYS_SET_MASK = 1U << 7,
|
||||
/** Attribute that informs that device is self powered */
|
||||
APP_USBD_DESCRIPTOR_CONFIGURATION_ATTRIBUTE_SELF_POWERED_MASK = 1U << 6,
|
||||
/** Attribute that informs that device has Remove Wakeup functionality */
|
||||
APP_USBD_DESCRIPTOR_CONFIGURATION_ATTRIBUTE_REMOTE_WAKEUP_MASK = 1U << 5
|
||||
} app_usbd_descriptor_configuration_attributes_t;
|
||||
|
||||
/**
|
||||
* @brief Configuration descriptor.
|
||||
*
|
||||
* Descriptor used at the beginning of configuration response.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< Size of the descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< Should equal to @ref APP_USBD_DESCRIPTOR_DEVICE.
|
||||
uint16_t wTotalLength; //!< Total length of configuration data, including all descriptors returned after configuration itself.
|
||||
uint8_t bNumInterfaces; //!< Number of interfaces supportedf by this configuration
|
||||
uint8_t bConfigurationValue; //!< Value to use as an argument to the SetConfiguration request.
|
||||
uint8_t iConfiguration; //!< Index of string descriptor describing this configuration.
|
||||
uint8_t bmAttributes; //!< Configuration characteristics.
|
||||
uint8_t bMaxPower; //!< Maximum power consumption. Expressed in 2 mA units.
|
||||
} app_usbd_descriptor_configuration_t;
|
||||
|
||||
/**
|
||||
* @brief Raw descriptor - String descriptor zero.
|
||||
*
|
||||
* String descriptor sent only as a response for GetDescriptor.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< Size of the descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< Should equal to @ref APP_USBD_DESCRIPTOR_STRING.
|
||||
uint16_t wLANGID[]; //!< The array of LANGID codes supported by the device.
|
||||
} app_usbd_descriptor_string0_t;
|
||||
|
||||
/**
|
||||
* @brief Raw descriptor - Any normal string.
|
||||
*
|
||||
* String descriptor sent only as a response for GetDescriptor.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< Size of the descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< Should equal to @ref APP_USBD_DESCRIPTOR_STRING.
|
||||
uint16_t bString[]; //!< UNICODE encoded string.
|
||||
} app_usbd_descriptor_string_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Interface descriptor.
|
||||
*
|
||||
* Interface descriptor, returned as a part of configuration descriptor.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< Size of the descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< Should equal to @ref APP_USBD_DESCRIPTOR_INTERFACE.
|
||||
uint8_t bInterfaceNumber; //!< Number of this interface.
|
||||
uint8_t bAlternateSetting; //!< Value used to select this alternate setting.
|
||||
uint8_t bNumEndpoints; //!< Number of endpoints used by this interface.
|
||||
uint8_t bInterfaceClass; //!< Class code (assigned by the USB-IF). 0xff for vendor specific.
|
||||
uint8_t bInterfaceSubClass; //!< Subclass code (assigned by the USB-IF).
|
||||
uint8_t bInterfaceProtocol; //!< Protocol code (assigned by the USB-IF). 0xff for vendor specific.
|
||||
uint8_t iInterface; //!< Index of string descriptor describing this interface.
|
||||
} app_usbd_descriptor_iface_t;
|
||||
|
||||
/** Offset of endpoint type attribute bits */
|
||||
#define APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_OFFSET 0
|
||||
/** Mask of endpoint type attribute bits */
|
||||
#define APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_MASK BF_MASK(2, APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_OFFSET)
|
||||
|
||||
/** Offset of endpoint synchronization type attribute bits */
|
||||
#define APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_OFFSET 2
|
||||
/** Mask of endpoint synchronization type attribute bits */
|
||||
#define APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_MASK BF_MASK(2, APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_OFFSET)
|
||||
|
||||
/** Offset of endpoint usage type attribute bits */
|
||||
#define APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_OFFSET 4
|
||||
/** Mask of endpoint usage type attribute bits */
|
||||
#define APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_MASK BF_MASK(2, APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_OFFSET)
|
||||
|
||||
/**
|
||||
* @brief Endpoint attributes mnemonics.
|
||||
*
|
||||
* @sa APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_OFFSET APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_MASK
|
||||
* @sa APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_OFFSET APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_MASK
|
||||
* @sa APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_OFFSET APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_MASK
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_CONTROL = 0 << APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_ISOCHRONOUS = 1 << APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_BULK = 2 << APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_INTERRUPT = 3 << APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_OFFSET,
|
||||
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_NONE = 0 << APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_ASYNCHRONOUS = 1 << APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_ADAPTIVE = 2 << APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_SYNCHRONOUS = 3 << APP_USBD_DESCRIPTOR_EP_ATTR_SYNC_OFFSET,
|
||||
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_DATA = 0 << APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_FEEDBACK = 1 << APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_OFFSET,
|
||||
APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_IMPLICIT = 2 << APP_USBD_DESCRIPTOR_EP_ATTR_USAGE_OFFSET
|
||||
} app_usbd_descriptor_ep_attr_bitmap_t;
|
||||
|
||||
/**
|
||||
* @brief Endpoint descriptor.
|
||||
*
|
||||
* Endpoint descriptor, returned as a part of configuration descriptor.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< Size of the descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< Should equal to @ref APP_USBD_DESCRIPTOR_ENDPOINT.
|
||||
uint8_t bEndpointAddress; //!< Endpoint address
|
||||
uint8_t bmAttributes; //!< Endpoint attributes
|
||||
uint16_t wMaxPacketSize; //!< Maximum packet size this endpoint is capable of handling.
|
||||
uint8_t bInterval; //!< Interval for pooling endpoint for data transfers.
|
||||
} app_usbd_descriptor_ep_t;
|
||||
|
||||
/**
|
||||
* @brief Interface association descriptor.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength; //!< size of this descriptor in bytes
|
||||
uint8_t bDescriptorType; //!< INTERFACE descriptor type
|
||||
uint8_t bFirstInterface; //!< Number of interface
|
||||
uint8_t bInterfaceCount; //!< value to select alternate setting
|
||||
uint8_t bFunctionClass; //!< Class code assigned by the USB
|
||||
uint8_t bFunctionSubClass;//!< Sub-class code assigned by the USB
|
||||
uint8_t bFunctionProtocol;//!< Protocol code assigned by the USB
|
||||
uint8_t iFunction; //!< Index of string descriptor
|
||||
} app_usbd_descriptor_iad_t;
|
||||
|
||||
#pragma pack(pop)
|
||||
ANON_UNIONS_DISABLE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif /* APP_USBD_DESCRIPTOR_H__ */
|
||||
|
||||
+300
-300
@@ -1,300 +1,300 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_LANGID_H__
|
||||
#define APP_USBD_LANGID_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief This file contains LANGID variable type with all defined values.
|
||||
*
|
||||
* This file was created using Language Identifiers (LANGIDs) 3/29/00 Version 1.0,
|
||||
* available on USB web page:
|
||||
* http://www.usb.org/developers/docs/USB_LANGIDs.pdf
|
||||
*
|
||||
* @note
|
||||
* Do not include this file directly to the project.
|
||||
* It is included by @file app_usbd_request.h.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Offset of the lowest bit of primary language identifier.
|
||||
* @sa app_usbd_langid_t
|
||||
*/
|
||||
#define APP_USB_LANG_OFFSET 0
|
||||
|
||||
/**
|
||||
* Bitmask for a primary language identifier.
|
||||
* @sa app_usbd_langid_t
|
||||
*/
|
||||
#define APP_USB_LANG_MASK BF_MASK(10, APP_USB_LANG_OFFSET)
|
||||
|
||||
/**
|
||||
* Macro for defining language identifier.
|
||||
*
|
||||
* @param x Language identifier value.
|
||||
*/
|
||||
#define APP_USB_LANG_DEF(x) ((x) << (APP_USB_LANG_OFFSET))
|
||||
|
||||
/**
|
||||
* Offset of the lowest bit of sublanguage identifier.
|
||||
* @sa app_usbd_langid_t
|
||||
*/
|
||||
#define APP_USB_SUBLANG_OFFSET 10
|
||||
|
||||
/**
|
||||
* Bitmask for a sublanguage identifier.
|
||||
* @sa app_usbd_langid_t
|
||||
*/
|
||||
#define APP_USB_SUBLANG_MASK BF_MASK(6, APP_USB_SUBLANG_OFFSET)
|
||||
|
||||
/**
|
||||
* Macro for defining language identifier.
|
||||
*
|
||||
* @param x Language identifier value.
|
||||
*/
|
||||
#define APP_USB_SUBLANG_DEF(x) ((x) << (APP_USB_SUBLANG_OFFSET))
|
||||
|
||||
/**
|
||||
* @brief Primary language identifiers.
|
||||
*
|
||||
* Mnemonics for primary language identifiers.
|
||||
* This mnemonics can be combined using the logical OR operator with @ref app_usbd_langid_sub_t.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
APP_USBD_LANG_ARABIC = APP_USB_LANG_DEF(0x01U), /**< Arabic */
|
||||
APP_USBD_LANG_BULGARIAN = APP_USB_LANG_DEF(0x02U), /**< Bulgarian */
|
||||
APP_USBD_LANG_CATALAN = APP_USB_LANG_DEF(0x03U), /**< Catalan */
|
||||
APP_USBD_LANG_CHINESE = APP_USB_LANG_DEF(0x04U), /**< Chinese */
|
||||
APP_USBD_LANG_CZECH = APP_USB_LANG_DEF(0x05U), /**< Czech */
|
||||
APP_USBD_LANG_DANISH = APP_USB_LANG_DEF(0x06U), /**< Danish */
|
||||
APP_USBD_LANG_GERMAN = APP_USB_LANG_DEF(0x07U), /**< German */
|
||||
APP_USBD_LANG_GREEK = APP_USB_LANG_DEF(0x08U), /**< Greek */
|
||||
APP_USBD_LANG_ENGLISH = APP_USB_LANG_DEF(0x09U), /**< English */
|
||||
APP_USBD_LANG_SPANISH = APP_USB_LANG_DEF(0x0aU), /**< Spanish */
|
||||
APP_USBD_LANG_FINNISH = APP_USB_LANG_DEF(0x0bU), /**< Finnish */
|
||||
APP_USBD_LANG_FRENCH = APP_USB_LANG_DEF(0x0cU), /**< French */
|
||||
APP_USBD_LANG_HEBREW = APP_USB_LANG_DEF(0x0dU), /**< Hebrew */
|
||||
APP_USBD_LANG_HUNGARIAN = APP_USB_LANG_DEF(0x0eU), /**< Hungarian */
|
||||
APP_USBD_LANG_ICELANDIC = APP_USB_LANG_DEF(0x0fU), /**< Icelandic */
|
||||
APP_USBD_LANG_ITALIAN = APP_USB_LANG_DEF(0x10U), /**< Italian */
|
||||
APP_USBD_LANG_JAPANESE = APP_USB_LANG_DEF(0x11U), /**< Japanese */
|
||||
APP_USBD_LANG_KOREAN = APP_USB_LANG_DEF(0x12U), /**< Korean */
|
||||
APP_USBD_LANG_DUTCH = APP_USB_LANG_DEF(0x13U), /**< Dutch */
|
||||
APP_USBD_LANG_NORWEGIAN = APP_USB_LANG_DEF(0x14U), /**< Norwegian */
|
||||
APP_USBD_LANG_POLISH = APP_USB_LANG_DEF(0x15U), /**< Polish */
|
||||
APP_USBD_LANG_PORTUGUESE = APP_USB_LANG_DEF(0x16U), /**< Portuguese */
|
||||
APP_USBD_LANG_ROMANIAN = APP_USB_LANG_DEF(0x18U), /**< Romanian */
|
||||
APP_USBD_LANG_RUSSIAN = APP_USB_LANG_DEF(0x19U), /**< Russian */
|
||||
APP_USBD_LANG_CROATIAN = APP_USB_LANG_DEF(0x1aU), /**< Croatian */
|
||||
APP_USBD_LANG_SERBIAN = APP_USB_LANG_DEF(0x1aU), /**< Serbian */
|
||||
APP_USBD_LANG_SLOVAK = APP_USB_LANG_DEF(0x1bU), /**< Slovak */
|
||||
APP_USBD_LANG_ALBANIAN = APP_USB_LANG_DEF(0x1cU), /**< Albanian */
|
||||
APP_USBD_LANG_SWEDISH = APP_USB_LANG_DEF(0x1dU), /**< Swedish */
|
||||
APP_USBD_LANG_THAI = APP_USB_LANG_DEF(0x1eU), /**< Thai */
|
||||
APP_USBD_LANG_TURKISH = APP_USB_LANG_DEF(0x1fU), /**< Turkish */
|
||||
APP_USBD_LANG_URDU = APP_USB_LANG_DEF(0x20U), /**< Urdu */
|
||||
APP_USBD_LANG_INDONESIAN = APP_USB_LANG_DEF(0x21U), /**< Indonesian */
|
||||
APP_USBD_LANG_UKRANIAN = APP_USB_LANG_DEF(0x22U), /**< Ukrainian */
|
||||
APP_USBD_LANG_BELARUSIAN = APP_USB_LANG_DEF(0x23U), /**< Belarusian */
|
||||
APP_USBD_LANG_SLOVENIAN = APP_USB_LANG_DEF(0x24U), /**< Slovenian */
|
||||
APP_USBD_LANG_ESTONIAN = APP_USB_LANG_DEF(0x25U), /**< Estonian */
|
||||
APP_USBD_LANG_LATVIAN = APP_USB_LANG_DEF(0x26U), /**< Latvian */
|
||||
APP_USBD_LANG_LITHUANIAN = APP_USB_LANG_DEF(0x27U), /**< Lithuanian */
|
||||
APP_USBD_LANG_FARSI = APP_USB_LANG_DEF(0x29U), /**< Farsi */
|
||||
APP_USBD_LANG_VIETNAMESE = APP_USB_LANG_DEF(0x2aU), /**< Vietnamese */
|
||||
APP_USBD_LANG_ARMENIAN = APP_USB_LANG_DEF(0x2bU), /**< Armenian */
|
||||
APP_USBD_LANG_AZERI = APP_USB_LANG_DEF(0x2cU), /**< Azeri */
|
||||
APP_USBD_LANG_BASQUE = APP_USB_LANG_DEF(0x2dU), /**< Basque */
|
||||
APP_USBD_LANG_MACEDONIAN = APP_USB_LANG_DEF(0x2fU), /**< Macedonian */
|
||||
APP_USBD_LANG_AFRIKAANS = APP_USB_LANG_DEF(0x36U), /**< Afrikaans */
|
||||
APP_USBD_LANG_GEORGIAN = APP_USB_LANG_DEF(0x37U), /**< Georgian */
|
||||
APP_USBD_LANG_FAEROESE = APP_USB_LANG_DEF(0x38U), /**< Faeroese */
|
||||
APP_USBD_LANG_HINDI = APP_USB_LANG_DEF(0x39U), /**< Hindi */
|
||||
APP_USBD_LANG_MALAY = APP_USB_LANG_DEF(0x3eU), /**< Malay */
|
||||
APP_USBD_LANG_KAZAK = APP_USB_LANG_DEF(0x3fU), /**< Kazak */
|
||||
APP_USBD_LANG_SWAHILI = APP_USB_LANG_DEF(0x41U), /**< Swahili */
|
||||
APP_USBD_LANG_UZBEK = APP_USB_LANG_DEF(0x43U), /**< Uzbek */
|
||||
APP_USBD_LANG_TATAR = APP_USB_LANG_DEF(0x44U), /**< Tatar */
|
||||
APP_USBD_LANG_BENGALI = APP_USB_LANG_DEF(0x45U), /**< Bengali */
|
||||
APP_USBD_LANG_PUNJABI = APP_USB_LANG_DEF(0x46U), /**< Punjabi */
|
||||
APP_USBD_LANG_GUJARATI = APP_USB_LANG_DEF(0x47U), /**< Gujarati */
|
||||
APP_USBD_LANG_ORIYA = APP_USB_LANG_DEF(0x48U), /**< Oriya */
|
||||
APP_USBD_LANG_TAMIL = APP_USB_LANG_DEF(0x49U), /**< Tamil */
|
||||
APP_USBD_LANG_TELUGU = APP_USB_LANG_DEF(0x4aU), /**< Telugu */
|
||||
APP_USBD_LANG_KANNADA = APP_USB_LANG_DEF(0x4bU), /**< Kannada */
|
||||
APP_USBD_LANG_MALAYALAM = APP_USB_LANG_DEF(0x4cU), /**< Malayalam */
|
||||
APP_USBD_LANG_ASSAMESE = APP_USB_LANG_DEF(0x4dU), /**< Assamese */
|
||||
APP_USBD_LANG_MARATHI = APP_USB_LANG_DEF(0x4eU), /**< Marathi */
|
||||
APP_USBD_LANG_SANSKRIT = APP_USB_LANG_DEF(0x4fU), /**< Sanskrit */
|
||||
APP_USBD_LANG_KONKANI = APP_USB_LANG_DEF(0x57U), /**< Konkani */
|
||||
APP_USBD_LANG_MANIPURI = APP_USB_LANG_DEF(0x58U), /**< Manipuri */
|
||||
APP_USBD_LANG_SINDHI = APP_USB_LANG_DEF(0x59U), /**< Sindhi */
|
||||
APP_USBD_LANG_KASHMIRI = APP_USB_LANG_DEF(0x60U), /**< Kashmiri */
|
||||
APP_USBD_LANG_NEPALI = APP_USB_LANG_DEF(0x61U), /**< Nepali */
|
||||
APP_USBD_LANG_HID = APP_USB_LANG_DEF(0xffU), /**< Reserved for USB HID Class use. */
|
||||
} app_usbd_langid_primary_t;
|
||||
|
||||
/**
|
||||
* @brief Sublanguage identifiers.
|
||||
*
|
||||
* Mnemonics with sublanguage values.
|
||||
* Use them in combination with @ref app_usbd_langid_primary_t.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
APP_USBD_SUBLANG_ARABIC_SAUDI_ARABIA = APP_USB_SUBLANG_DEF(0x01U), /**< Arabic (Saudi Arabia) */
|
||||
APP_USBD_SUBLANG_ARABIC_IRAQ = APP_USB_SUBLANG_DEF(0x02U), /**< Arabic (Iraq) */
|
||||
APP_USBD_SUBLANG_ARABIC_EGYPT = APP_USB_SUBLANG_DEF(0x03U), /**< Arabic (Egypt) */
|
||||
APP_USBD_SUBLANG_ARABIC_LIBYA = APP_USB_SUBLANG_DEF(0x04U), /**< Arabic (Libya) */
|
||||
APP_USBD_SUBLANG_ARABIC_ALGERIA = APP_USB_SUBLANG_DEF(0x05U), /**< Arabic (Algeria) */
|
||||
APP_USBD_SUBLANG_ARABIC_MOROCCO = APP_USB_SUBLANG_DEF(0x06U), /**< Arabic (Morocco) */
|
||||
APP_USBD_SUBLANG_ARABIC_TUNISIA = APP_USB_SUBLANG_DEF(0x07U), /**< Arabic (Tunisia) */
|
||||
APP_USBD_SUBLANG_ARABIC_OMAN = APP_USB_SUBLANG_DEF(0x08U), /**< Arabic (Oman) */
|
||||
APP_USBD_SUBLANG_ARABIC_YEMEN = APP_USB_SUBLANG_DEF(0x09U), /**< Arabic (Yemen) */
|
||||
APP_USBD_SUBLANG_ARABIC_SYRIA = APP_USB_SUBLANG_DEF(0x10U), /**< Arabic (Syria) */
|
||||
APP_USBD_SUBLANG_ARABIC_JORDAN = APP_USB_SUBLANG_DEF(0x11U), /**< Arabic (Jordan) */
|
||||
APP_USBD_SUBLANG_ARABIC_LEBANON = APP_USB_SUBLANG_DEF(0x12U), /**< Arabic (Lebanon) */
|
||||
APP_USBD_SUBLANG_ARABIC_KUWAIT = APP_USB_SUBLANG_DEF(0x13U), /**< Arabic (Kuwait) */
|
||||
APP_USBD_SUBLANG_ARABIC_UAE = APP_USB_SUBLANG_DEF(0x14U), /**< Arabic (U.A.E.) */
|
||||
APP_USBD_SUBLANG_ARABIC_BAHRAIN = APP_USB_SUBLANG_DEF(0x15U), /**< Arabic (Bahrain) */
|
||||
APP_USBD_SUBLANG_ARABIC_QATAR = APP_USB_SUBLANG_DEF(0x16U), /**< Arabic (Qatar) */
|
||||
APP_USBD_SUBLANG_AZERI_CYRILLIC = APP_USB_SUBLANG_DEF(0x01U), /**< Azeri (Cyrillic) */
|
||||
APP_USBD_SUBLANG_AZERI_LATIN = APP_USB_SUBLANG_DEF(0x02U), /**< Azeri (Latin) */
|
||||
APP_USBD_SUBLANG_CHINESE_TRADITIONAL = APP_USB_SUBLANG_DEF(0x01U), /**< Chinese (Traditional) */
|
||||
APP_USBD_SUBLANG_CHINESE_SIMPLIFIED = APP_USB_SUBLANG_DEF(0x02U), /**< Chinese (Simplified) */
|
||||
APP_USBD_SUBLANG_CHINESE_HONGKONG = APP_USB_SUBLANG_DEF(0x03U), /**< Chinese (Hong Kong SAR, PRC) */
|
||||
APP_USBD_SUBLANG_CHINESE_SINGAPORE = APP_USB_SUBLANG_DEF(0x04U), /**< Chinese (Singapore) */
|
||||
APP_USBD_SUBLANG_CHINESE_MACAU = APP_USB_SUBLANG_DEF(0x05U), /**< Chinese (Macau SAR) */
|
||||
APP_USBD_SUBLANG_DUTCH = APP_USB_SUBLANG_DEF(0x01U), /**< Dutch */
|
||||
APP_USBD_SUBLANG_DUTCH_BELGIAN = APP_USB_SUBLANG_DEF(0x02U), /**< Dutch (Belgian) */
|
||||
APP_USBD_SUBLANG_ENGLISH_US = APP_USB_SUBLANG_DEF(0x01U), /**< English (US) */
|
||||
APP_USBD_SUBLANG_ENGLISH_UK = APP_USB_SUBLANG_DEF(0x02U), /**< English (UK) */
|
||||
APP_USBD_SUBLANG_ENGLISH_AUS = APP_USB_SUBLANG_DEF(0x03U), /**< English (Australian) */
|
||||
APP_USBD_SUBLANG_ENGLISH_CAN = APP_USB_SUBLANG_DEF(0x04U), /**< English (Canadian) */
|
||||
APP_USBD_SUBLANG_ENGLISH_NZ = APP_USB_SUBLANG_DEF(0x05U), /**< English (New Zealand) */
|
||||
APP_USBD_SUBLANG_ENGLISH_EIRE = APP_USB_SUBLANG_DEF(0x06U), /**< English (Ireland) */
|
||||
APP_USBD_SUBLANG_ENGLISH_SOUTH_AFRICA = APP_USB_SUBLANG_DEF(0x07U), /**< English (South Africa) */
|
||||
APP_USBD_SUBLANG_ENGLISH_JAMAICA = APP_USB_SUBLANG_DEF(0x08U), /**< English (Jamaica) */
|
||||
APP_USBD_SUBLANG_ENGLISH_CARIBBEAN = APP_USB_SUBLANG_DEF(0x09U), /**< English (Caribbean) */
|
||||
APP_USBD_SUBLANG_ENGLISH_BELIZE = APP_USB_SUBLANG_DEF(0x0aU), /**< English (Belize) */
|
||||
APP_USBD_SUBLANG_ENGLISH_TRINIDAD = APP_USB_SUBLANG_DEF(0x0bU), /**< English (Trinidad) */
|
||||
APP_USBD_SUBLANG_ENGLISH_PHILIPPINES = APP_USB_SUBLANG_DEF(0x0cU), /**< English (Zimbabwe) */
|
||||
APP_USBD_SUBLANG_ENGLISH_ZIMBABWE = APP_USB_SUBLANG_DEF(0x0dU), /**< English (Philippines) */
|
||||
APP_USBD_SUBLANG_FRENCH = APP_USB_SUBLANG_DEF(0x01U), /**< French */
|
||||
APP_USBD_SUBLANG_FRENCH_BELGIAN = APP_USB_SUBLANG_DEF(0x02U), /**< French (Belgian) */
|
||||
APP_USBD_SUBLANG_FRENCH_CANADIAN = APP_USB_SUBLANG_DEF(0x03U), /**< French (Canadian) */
|
||||
APP_USBD_SUBLANG_FRENCH_SWISS = APP_USB_SUBLANG_DEF(0x04U), /**< French (Switzerland) */
|
||||
APP_USBD_SUBLANG_FRENCH_LUXEMBOURG = APP_USB_SUBLANG_DEF(0x05U), /**< French (Luxembourg) */
|
||||
APP_USBD_SUBLANG_FRENCH_MONACO = APP_USB_SUBLANG_DEF(0x06U), /**< French (Monaco) */
|
||||
APP_USBD_SUBLANG_GERMAN = APP_USB_SUBLANG_DEF(0x01U), /**< German */
|
||||
APP_USBD_SUBLANG_GERMAN_SWISS = APP_USB_SUBLANG_DEF(0x02U), /**< German (Switzerland) */
|
||||
APP_USBD_SUBLANG_GERMAN_AUSTRIAN = APP_USB_SUBLANG_DEF(0x03U), /**< German (Austria) */
|
||||
APP_USBD_SUBLANG_GERMAN_LUXEMBOURG = APP_USB_SUBLANG_DEF(0x04U), /**< German (Luxembourg) */
|
||||
APP_USBD_SUBLANG_GERMAN_LIECHTENSTEIN = APP_USB_SUBLANG_DEF(0x05U), /**< German (Liechtenstein) */
|
||||
APP_USBD_SUBLANG_ITALIAN = APP_USB_SUBLANG_DEF(0x01U), /**< Italian */
|
||||
APP_USBD_SUBLANG_ITALIAN_SWISS = APP_USB_SUBLANG_DEF(0x02U), /**< Italian (Switzerland) */
|
||||
APP_USBD_SUBLANG_KASHMIRI_INDIA = APP_USB_SUBLANG_DEF(0x02U), /**< Kashmiri (India) */
|
||||
APP_USBD_SUBLANG_KOREAN = APP_USB_SUBLANG_DEF(0x01U), /**< Korean */
|
||||
APP_USBD_SUBLANG_LITHUANIAN = APP_USB_SUBLANG_DEF(0x01U), /**< Lithuanian */
|
||||
APP_USBD_SUBLANG_MALAY_MALAYSIA = APP_USB_SUBLANG_DEF(0x01U), /**< Malay (Malaysia) */
|
||||
APP_USBD_SUBLANG_MALAY_BRUNEI_DARUSSALAM = APP_USB_SUBLANG_DEF(0x02U), /**< Malay (Brunei Darassalam) */
|
||||
APP_USBD_SUBLANG_NEPALI_INDIA = APP_USB_SUBLANG_DEF(0x02U), /**< Nepali (India) */
|
||||
APP_USBD_SUBLANG_NORWEGIAN_BOKMAL = APP_USB_SUBLANG_DEF(0x01U), /**< Norwegian (Bokmal) */
|
||||
APP_USBD_SUBLANG_NORWEGIAN_NYNORSK = APP_USB_SUBLANG_DEF(0x02U), /**< Norwegian (Nynorsk) */
|
||||
APP_USBD_SUBLANG_PORTUGUESE = APP_USB_SUBLANG_DEF(0x01U), /**< Portuguese */
|
||||
APP_USBD_SUBLANG_PORTUGUESE_BRAZILIAN = APP_USB_SUBLANG_DEF(0x02U), /**< Portuguese (Brazil) */
|
||||
APP_USBD_SUBLANG_SERBIAN_LATIN = APP_USB_SUBLANG_DEF(0x02U), /**< Serbian (Latin) */
|
||||
APP_USBD_SUBLANG_SERBIAN_CYRILLIC = APP_USB_SUBLANG_DEF(0x03U), /**< Serbian (Cyrillic) */
|
||||
APP_USBD_SUBLANG_SPANISH = APP_USB_SUBLANG_DEF(0x01U), /**< Spanish (Traditional) */
|
||||
APP_USBD_SUBLANG_SPANISH_MEXICAN = APP_USB_SUBLANG_DEF(0x02U), /**< Spanish (Mexican) */
|
||||
APP_USBD_SUBLANG_SPANISH_MODERN = APP_USB_SUBLANG_DEF(0x03U), /**< Spanish (Modern) */
|
||||
APP_USBD_SUBLANG_SPANISH_GUATEMALA = APP_USB_SUBLANG_DEF(0x04U), /**< Spanish (Guatemala) */
|
||||
APP_USBD_SUBLANG_SPANISH_COSTA_RICA = APP_USB_SUBLANG_DEF(0x05U), /**< Spanish (Costa Rica) */
|
||||
APP_USBD_SUBLANG_SPANISH_PANAMA = APP_USB_SUBLANG_DEF(0x06U), /**< Spanish (Panama) */
|
||||
APP_USBD_SUBLANG_SPANISH_DOMINICAN_REPUBLIC = APP_USB_SUBLANG_DEF(0x07U), /**< Spanish (Dominican Republic) */
|
||||
APP_USBD_SUBLANG_SPANISH_VENEZUELA = APP_USB_SUBLANG_DEF(0x08U), /**< Spanish (Venezuela) */
|
||||
APP_USBD_SUBLANG_SPANISH_COLOMBIA = APP_USB_SUBLANG_DEF(0x09U), /**< Spanish (Colombia) */
|
||||
APP_USBD_SUBLANG_SPANISH_PERU = APP_USB_SUBLANG_DEF(0x0aU), /**< Spanish (Peru) */
|
||||
APP_USBD_SUBLANG_SPANISH_ARGENTINA = APP_USB_SUBLANG_DEF(0x0bU), /**< Spanish (Argentina) */
|
||||
APP_USBD_SUBLANG_SPANISH_ECUADOR = APP_USB_SUBLANG_DEF(0x0cU), /**< Spanish (Ecuador) */
|
||||
APP_USBD_SUBLANG_SPANISH_CHILE = APP_USB_SUBLANG_DEF(0x0dU), /**< Spanish (Chile) */
|
||||
APP_USBD_SUBLANG_SPANISH_URUGUAY = APP_USB_SUBLANG_DEF(0x0eU), /**< Spanish (Uruguay) */
|
||||
APP_USBD_SUBLANG_SPANISH_PARAGUAY = APP_USB_SUBLANG_DEF(0x0fU), /**< Spanish (Paraguay) */
|
||||
APP_USBD_SUBLANG_SPANISH_BOLIVIA = APP_USB_SUBLANG_DEF(0x10U), /**< Spanish (Bolivia) */
|
||||
APP_USBD_SUBLANG_SPANISH_EL_SALVADOR = APP_USB_SUBLANG_DEF(0x11U), /**< Spanish (El Salvador) */
|
||||
APP_USBD_SUBLANG_SPANISH_HONDURAS = APP_USB_SUBLANG_DEF(0x12U), /**< Spanish (Honduras) */
|
||||
APP_USBD_SUBLANG_SPANISH_NICARAGUA = APP_USB_SUBLANG_DEF(0x13U), /**< Spanish (Nicaragua) */
|
||||
APP_USBD_SUBLANG_SPANISH_PUERTO_RICO = APP_USB_SUBLANG_DEF(0x14U), /**< Spanish (Puerto Rico) */
|
||||
APP_USBD_SUBLANG_SWEDISH = APP_USB_SUBLANG_DEF(0x01U), /**< Swedish */
|
||||
APP_USBD_SUBLANG_SWEDISH_FINLAND = APP_USB_SUBLANG_DEF(0x02U), /**< Swedish (Finland) */
|
||||
APP_USBD_SUBLANG_URDU_PAKISTAN = APP_USB_SUBLANG_DEF(0x01U), /**< Urdu (Pakistan) */
|
||||
APP_USBD_SUBLANG_URDU_INDIA = APP_USB_SUBLANG_DEF(0x02U), /**< Urdu (India) */
|
||||
APP_USBD_SUBLANG_UZBEK_LATIN = APP_USB_SUBLANG_DEF(0x01U), /**< Uzbek (Latin) */
|
||||
APP_USBD_SUBLANG_UZBEK_CYRILLIC = APP_USB_SUBLANG_DEF(0x02U), /**< Uzbek (Cyrillic) */
|
||||
APP_USBD_SUBLANG_HID_USAGE_DATA_DESCRIPTOR = APP_USB_SUBLANG_DEF(0x01U), /**< HID (Usage Data Descriptor) */
|
||||
APP_USBD_SUBLANG_HID_VENDOR_DEFINED_1 = APP_USB_SUBLANG_DEF(0x3cU), /**< HID (Vendor Defined 1) */
|
||||
APP_USBD_SUBLANG_HID_VENDOR_DEFINED_2 = APP_USB_SUBLANG_DEF(0x3dU), /**< HID (Vendor Defined 2) */
|
||||
APP_USBD_SUBLANG_HID_VENDOR_DEFINED_3 = APP_USB_SUBLANG_DEF(0x3eU), /**< HID (Vendor Defined 3) */
|
||||
APP_USBD_SUBLANG_HID_VENDOR_DEFINED_4 = APP_USB_SUBLANG_DEF(0x3fU), /**< HID (Vendor Defined 4) */
|
||||
} app_usbd_langid_sub_t;
|
||||
|
||||
/**
|
||||
* @brief LANGID variable.
|
||||
*
|
||||
* The LANGID value is composed of:
|
||||
* - 10 bits (9-0) of Primary Language Identifier,
|
||||
* - 6 bits (15-10) of Sublanguage Identifier.
|
||||
*
|
||||
* @sa app_usbd_langid_primary_t
|
||||
* @sa app_usbd_langid_sub_t
|
||||
*/
|
||||
typedef uint16_t app_usbd_langid_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_LANGID_H__ */
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_LANGID_H__
|
||||
#define APP_USBD_LANGID_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief This file contains LANGID variable type with all defined values.
|
||||
*
|
||||
* This file was created using Language Identifiers (LANGIDs) 3/29/00 Version 1.0,
|
||||
* available on USB web page:
|
||||
* http://www.usb.org/developers/docs/USB_LANGIDs.pdf
|
||||
*
|
||||
* @note
|
||||
* Do not include this file directly to the project.
|
||||
* It is included by @file app_usbd_request.h.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Offset of the lowest bit of primary language identifier.
|
||||
* @sa app_usbd_langid_t
|
||||
*/
|
||||
#define APP_USB_LANG_OFFSET 0
|
||||
|
||||
/**
|
||||
* Bitmask for a primary language identifier.
|
||||
* @sa app_usbd_langid_t
|
||||
*/
|
||||
#define APP_USB_LANG_MASK BF_MASK(10, APP_USB_LANG_OFFSET)
|
||||
|
||||
/**
|
||||
* Macro for defining language identifier.
|
||||
*
|
||||
* @param x Language identifier value.
|
||||
*/
|
||||
#define APP_USB_LANG_DEF(x) ((x) << (APP_USB_LANG_OFFSET))
|
||||
|
||||
/**
|
||||
* Offset of the lowest bit of sublanguage identifier.
|
||||
* @sa app_usbd_langid_t
|
||||
*/
|
||||
#define APP_USB_SUBLANG_OFFSET 10
|
||||
|
||||
/**
|
||||
* Bitmask for a sublanguage identifier.
|
||||
* @sa app_usbd_langid_t
|
||||
*/
|
||||
#define APP_USB_SUBLANG_MASK BF_MASK(6, APP_USB_SUBLANG_OFFSET)
|
||||
|
||||
/**
|
||||
* Macro for defining language identifier.
|
||||
*
|
||||
* @param x Language identifier value.
|
||||
*/
|
||||
#define APP_USB_SUBLANG_DEF(x) ((x) << (APP_USB_SUBLANG_OFFSET))
|
||||
|
||||
/**
|
||||
* @brief Primary language identifiers.
|
||||
*
|
||||
* Mnemonics for primary language identifiers.
|
||||
* This mnemonics can be combined using the logical OR operator with @ref app_usbd_langid_sub_t.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
APP_USBD_LANG_ARABIC = APP_USB_LANG_DEF(0x01U), /**< Arabic */
|
||||
APP_USBD_LANG_BULGARIAN = APP_USB_LANG_DEF(0x02U), /**< Bulgarian */
|
||||
APP_USBD_LANG_CATALAN = APP_USB_LANG_DEF(0x03U), /**< Catalan */
|
||||
APP_USBD_LANG_CHINESE = APP_USB_LANG_DEF(0x04U), /**< Chinese */
|
||||
APP_USBD_LANG_CZECH = APP_USB_LANG_DEF(0x05U), /**< Czech */
|
||||
APP_USBD_LANG_DANISH = APP_USB_LANG_DEF(0x06U), /**< Danish */
|
||||
APP_USBD_LANG_GERMAN = APP_USB_LANG_DEF(0x07U), /**< German */
|
||||
APP_USBD_LANG_GREEK = APP_USB_LANG_DEF(0x08U), /**< Greek */
|
||||
APP_USBD_LANG_ENGLISH = APP_USB_LANG_DEF(0x09U), /**< English */
|
||||
APP_USBD_LANG_SPANISH = APP_USB_LANG_DEF(0x0aU), /**< Spanish */
|
||||
APP_USBD_LANG_FINNISH = APP_USB_LANG_DEF(0x0bU), /**< Finnish */
|
||||
APP_USBD_LANG_FRENCH = APP_USB_LANG_DEF(0x0cU), /**< French */
|
||||
APP_USBD_LANG_HEBREW = APP_USB_LANG_DEF(0x0dU), /**< Hebrew */
|
||||
APP_USBD_LANG_HUNGARIAN = APP_USB_LANG_DEF(0x0eU), /**< Hungarian */
|
||||
APP_USBD_LANG_ICELANDIC = APP_USB_LANG_DEF(0x0fU), /**< Icelandic */
|
||||
APP_USBD_LANG_ITALIAN = APP_USB_LANG_DEF(0x10U), /**< Italian */
|
||||
APP_USBD_LANG_JAPANESE = APP_USB_LANG_DEF(0x11U), /**< Japanese */
|
||||
APP_USBD_LANG_KOREAN = APP_USB_LANG_DEF(0x12U), /**< Korean */
|
||||
APP_USBD_LANG_DUTCH = APP_USB_LANG_DEF(0x13U), /**< Dutch */
|
||||
APP_USBD_LANG_NORWEGIAN = APP_USB_LANG_DEF(0x14U), /**< Norwegian */
|
||||
APP_USBD_LANG_POLISH = APP_USB_LANG_DEF(0x15U), /**< Polish */
|
||||
APP_USBD_LANG_PORTUGUESE = APP_USB_LANG_DEF(0x16U), /**< Portuguese */
|
||||
APP_USBD_LANG_ROMANIAN = APP_USB_LANG_DEF(0x18U), /**< Romanian */
|
||||
APP_USBD_LANG_RUSSIAN = APP_USB_LANG_DEF(0x19U), /**< Russian */
|
||||
APP_USBD_LANG_CROATIAN = APP_USB_LANG_DEF(0x1aU), /**< Croatian */
|
||||
APP_USBD_LANG_SERBIAN = APP_USB_LANG_DEF(0x1aU), /**< Serbian */
|
||||
APP_USBD_LANG_SLOVAK = APP_USB_LANG_DEF(0x1bU), /**< Slovak */
|
||||
APP_USBD_LANG_ALBANIAN = APP_USB_LANG_DEF(0x1cU), /**< Albanian */
|
||||
APP_USBD_LANG_SWEDISH = APP_USB_LANG_DEF(0x1dU), /**< Swedish */
|
||||
APP_USBD_LANG_THAI = APP_USB_LANG_DEF(0x1eU), /**< Thai */
|
||||
APP_USBD_LANG_TURKISH = APP_USB_LANG_DEF(0x1fU), /**< Turkish */
|
||||
APP_USBD_LANG_URDU = APP_USB_LANG_DEF(0x20U), /**< Urdu */
|
||||
APP_USBD_LANG_INDONESIAN = APP_USB_LANG_DEF(0x21U), /**< Indonesian */
|
||||
APP_USBD_LANG_UKRANIAN = APP_USB_LANG_DEF(0x22U), /**< Ukrainian */
|
||||
APP_USBD_LANG_BELARUSIAN = APP_USB_LANG_DEF(0x23U), /**< Belarusian */
|
||||
APP_USBD_LANG_SLOVENIAN = APP_USB_LANG_DEF(0x24U), /**< Slovenian */
|
||||
APP_USBD_LANG_ESTONIAN = APP_USB_LANG_DEF(0x25U), /**< Estonian */
|
||||
APP_USBD_LANG_LATVIAN = APP_USB_LANG_DEF(0x26U), /**< Latvian */
|
||||
APP_USBD_LANG_LITHUANIAN = APP_USB_LANG_DEF(0x27U), /**< Lithuanian */
|
||||
APP_USBD_LANG_FARSI = APP_USB_LANG_DEF(0x29U), /**< Farsi */
|
||||
APP_USBD_LANG_VIETNAMESE = APP_USB_LANG_DEF(0x2aU), /**< Vietnamese */
|
||||
APP_USBD_LANG_ARMENIAN = APP_USB_LANG_DEF(0x2bU), /**< Armenian */
|
||||
APP_USBD_LANG_AZERI = APP_USB_LANG_DEF(0x2cU), /**< Azeri */
|
||||
APP_USBD_LANG_BASQUE = APP_USB_LANG_DEF(0x2dU), /**< Basque */
|
||||
APP_USBD_LANG_MACEDONIAN = APP_USB_LANG_DEF(0x2fU), /**< Macedonian */
|
||||
APP_USBD_LANG_AFRIKAANS = APP_USB_LANG_DEF(0x36U), /**< Afrikaans */
|
||||
APP_USBD_LANG_GEORGIAN = APP_USB_LANG_DEF(0x37U), /**< Georgian */
|
||||
APP_USBD_LANG_FAEROESE = APP_USB_LANG_DEF(0x38U), /**< Faeroese */
|
||||
APP_USBD_LANG_HINDI = APP_USB_LANG_DEF(0x39U), /**< Hindi */
|
||||
APP_USBD_LANG_MALAY = APP_USB_LANG_DEF(0x3eU), /**< Malay */
|
||||
APP_USBD_LANG_KAZAK = APP_USB_LANG_DEF(0x3fU), /**< Kazak */
|
||||
APP_USBD_LANG_SWAHILI = APP_USB_LANG_DEF(0x41U), /**< Swahili */
|
||||
APP_USBD_LANG_UZBEK = APP_USB_LANG_DEF(0x43U), /**< Uzbek */
|
||||
APP_USBD_LANG_TATAR = APP_USB_LANG_DEF(0x44U), /**< Tatar */
|
||||
APP_USBD_LANG_BENGALI = APP_USB_LANG_DEF(0x45U), /**< Bengali */
|
||||
APP_USBD_LANG_PUNJABI = APP_USB_LANG_DEF(0x46U), /**< Punjabi */
|
||||
APP_USBD_LANG_GUJARATI = APP_USB_LANG_DEF(0x47U), /**< Gujarati */
|
||||
APP_USBD_LANG_ORIYA = APP_USB_LANG_DEF(0x48U), /**< Oriya */
|
||||
APP_USBD_LANG_TAMIL = APP_USB_LANG_DEF(0x49U), /**< Tamil */
|
||||
APP_USBD_LANG_TELUGU = APP_USB_LANG_DEF(0x4aU), /**< Telugu */
|
||||
APP_USBD_LANG_KANNADA = APP_USB_LANG_DEF(0x4bU), /**< Kannada */
|
||||
APP_USBD_LANG_MALAYALAM = APP_USB_LANG_DEF(0x4cU), /**< Malayalam */
|
||||
APP_USBD_LANG_ASSAMESE = APP_USB_LANG_DEF(0x4dU), /**< Assamese */
|
||||
APP_USBD_LANG_MARATHI = APP_USB_LANG_DEF(0x4eU), /**< Marathi */
|
||||
APP_USBD_LANG_SANSKRIT = APP_USB_LANG_DEF(0x4fU), /**< Sanskrit */
|
||||
APP_USBD_LANG_KONKANI = APP_USB_LANG_DEF(0x57U), /**< Konkani */
|
||||
APP_USBD_LANG_MANIPURI = APP_USB_LANG_DEF(0x58U), /**< Manipuri */
|
||||
APP_USBD_LANG_SINDHI = APP_USB_LANG_DEF(0x59U), /**< Sindhi */
|
||||
APP_USBD_LANG_KASHMIRI = APP_USB_LANG_DEF(0x60U), /**< Kashmiri */
|
||||
APP_USBD_LANG_NEPALI = APP_USB_LANG_DEF(0x61U), /**< Nepali */
|
||||
APP_USBD_LANG_HID = APP_USB_LANG_DEF(0xffU), /**< Reserved for USB HID Class use. */
|
||||
} app_usbd_langid_primary_t;
|
||||
|
||||
/**
|
||||
* @brief Sublanguage identifiers.
|
||||
*
|
||||
* Mnemonics with sublanguage values.
|
||||
* Use them in combination with @ref app_usbd_langid_primary_t.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
APP_USBD_SUBLANG_ARABIC_SAUDI_ARABIA = APP_USB_SUBLANG_DEF(0x01U), /**< Arabic (Saudi Arabia) */
|
||||
APP_USBD_SUBLANG_ARABIC_IRAQ = APP_USB_SUBLANG_DEF(0x02U), /**< Arabic (Iraq) */
|
||||
APP_USBD_SUBLANG_ARABIC_EGYPT = APP_USB_SUBLANG_DEF(0x03U), /**< Arabic (Egypt) */
|
||||
APP_USBD_SUBLANG_ARABIC_LIBYA = APP_USB_SUBLANG_DEF(0x04U), /**< Arabic (Libya) */
|
||||
APP_USBD_SUBLANG_ARABIC_ALGERIA = APP_USB_SUBLANG_DEF(0x05U), /**< Arabic (Algeria) */
|
||||
APP_USBD_SUBLANG_ARABIC_MOROCCO = APP_USB_SUBLANG_DEF(0x06U), /**< Arabic (Morocco) */
|
||||
APP_USBD_SUBLANG_ARABIC_TUNISIA = APP_USB_SUBLANG_DEF(0x07U), /**< Arabic (Tunisia) */
|
||||
APP_USBD_SUBLANG_ARABIC_OMAN = APP_USB_SUBLANG_DEF(0x08U), /**< Arabic (Oman) */
|
||||
APP_USBD_SUBLANG_ARABIC_YEMEN = APP_USB_SUBLANG_DEF(0x09U), /**< Arabic (Yemen) */
|
||||
APP_USBD_SUBLANG_ARABIC_SYRIA = APP_USB_SUBLANG_DEF(0x10U), /**< Arabic (Syria) */
|
||||
APP_USBD_SUBLANG_ARABIC_JORDAN = APP_USB_SUBLANG_DEF(0x11U), /**< Arabic (Jordan) */
|
||||
APP_USBD_SUBLANG_ARABIC_LEBANON = APP_USB_SUBLANG_DEF(0x12U), /**< Arabic (Lebanon) */
|
||||
APP_USBD_SUBLANG_ARABIC_KUWAIT = APP_USB_SUBLANG_DEF(0x13U), /**< Arabic (Kuwait) */
|
||||
APP_USBD_SUBLANG_ARABIC_UAE = APP_USB_SUBLANG_DEF(0x14U), /**< Arabic (U.A.E.) */
|
||||
APP_USBD_SUBLANG_ARABIC_BAHRAIN = APP_USB_SUBLANG_DEF(0x15U), /**< Arabic (Bahrain) */
|
||||
APP_USBD_SUBLANG_ARABIC_QATAR = APP_USB_SUBLANG_DEF(0x16U), /**< Arabic (Qatar) */
|
||||
APP_USBD_SUBLANG_AZERI_CYRILLIC = APP_USB_SUBLANG_DEF(0x01U), /**< Azeri (Cyrillic) */
|
||||
APP_USBD_SUBLANG_AZERI_LATIN = APP_USB_SUBLANG_DEF(0x02U), /**< Azeri (Latin) */
|
||||
APP_USBD_SUBLANG_CHINESE_TRADITIONAL = APP_USB_SUBLANG_DEF(0x01U), /**< Chinese (Traditional) */
|
||||
APP_USBD_SUBLANG_CHINESE_SIMPLIFIED = APP_USB_SUBLANG_DEF(0x02U), /**< Chinese (Simplified) */
|
||||
APP_USBD_SUBLANG_CHINESE_HONGKONG = APP_USB_SUBLANG_DEF(0x03U), /**< Chinese (Hong Kong SAR, PRC) */
|
||||
APP_USBD_SUBLANG_CHINESE_SINGAPORE = APP_USB_SUBLANG_DEF(0x04U), /**< Chinese (Singapore) */
|
||||
APP_USBD_SUBLANG_CHINESE_MACAU = APP_USB_SUBLANG_DEF(0x05U), /**< Chinese (Macau SAR) */
|
||||
APP_USBD_SUBLANG_DUTCH = APP_USB_SUBLANG_DEF(0x01U), /**< Dutch */
|
||||
APP_USBD_SUBLANG_DUTCH_BELGIAN = APP_USB_SUBLANG_DEF(0x02U), /**< Dutch (Belgian) */
|
||||
APP_USBD_SUBLANG_ENGLISH_US = APP_USB_SUBLANG_DEF(0x01U), /**< English (US) */
|
||||
APP_USBD_SUBLANG_ENGLISH_UK = APP_USB_SUBLANG_DEF(0x02U), /**< English (UK) */
|
||||
APP_USBD_SUBLANG_ENGLISH_AUS = APP_USB_SUBLANG_DEF(0x03U), /**< English (Australian) */
|
||||
APP_USBD_SUBLANG_ENGLISH_CAN = APP_USB_SUBLANG_DEF(0x04U), /**< English (Canadian) */
|
||||
APP_USBD_SUBLANG_ENGLISH_NZ = APP_USB_SUBLANG_DEF(0x05U), /**< English (New Zealand) */
|
||||
APP_USBD_SUBLANG_ENGLISH_EIRE = APP_USB_SUBLANG_DEF(0x06U), /**< English (Ireland) */
|
||||
APP_USBD_SUBLANG_ENGLISH_SOUTH_AFRICA = APP_USB_SUBLANG_DEF(0x07U), /**< English (South Africa) */
|
||||
APP_USBD_SUBLANG_ENGLISH_JAMAICA = APP_USB_SUBLANG_DEF(0x08U), /**< English (Jamaica) */
|
||||
APP_USBD_SUBLANG_ENGLISH_CARIBBEAN = APP_USB_SUBLANG_DEF(0x09U), /**< English (Caribbean) */
|
||||
APP_USBD_SUBLANG_ENGLISH_BELIZE = APP_USB_SUBLANG_DEF(0x0aU), /**< English (Belize) */
|
||||
APP_USBD_SUBLANG_ENGLISH_TRINIDAD = APP_USB_SUBLANG_DEF(0x0bU), /**< English (Trinidad) */
|
||||
APP_USBD_SUBLANG_ENGLISH_PHILIPPINES = APP_USB_SUBLANG_DEF(0x0cU), /**< English (Zimbabwe) */
|
||||
APP_USBD_SUBLANG_ENGLISH_ZIMBABWE = APP_USB_SUBLANG_DEF(0x0dU), /**< English (Philippines) */
|
||||
APP_USBD_SUBLANG_FRENCH = APP_USB_SUBLANG_DEF(0x01U), /**< French */
|
||||
APP_USBD_SUBLANG_FRENCH_BELGIAN = APP_USB_SUBLANG_DEF(0x02U), /**< French (Belgian) */
|
||||
APP_USBD_SUBLANG_FRENCH_CANADIAN = APP_USB_SUBLANG_DEF(0x03U), /**< French (Canadian) */
|
||||
APP_USBD_SUBLANG_FRENCH_SWISS = APP_USB_SUBLANG_DEF(0x04U), /**< French (Switzerland) */
|
||||
APP_USBD_SUBLANG_FRENCH_LUXEMBOURG = APP_USB_SUBLANG_DEF(0x05U), /**< French (Luxembourg) */
|
||||
APP_USBD_SUBLANG_FRENCH_MONACO = APP_USB_SUBLANG_DEF(0x06U), /**< French (Monaco) */
|
||||
APP_USBD_SUBLANG_GERMAN = APP_USB_SUBLANG_DEF(0x01U), /**< German */
|
||||
APP_USBD_SUBLANG_GERMAN_SWISS = APP_USB_SUBLANG_DEF(0x02U), /**< German (Switzerland) */
|
||||
APP_USBD_SUBLANG_GERMAN_AUSTRIAN = APP_USB_SUBLANG_DEF(0x03U), /**< German (Austria) */
|
||||
APP_USBD_SUBLANG_GERMAN_LUXEMBOURG = APP_USB_SUBLANG_DEF(0x04U), /**< German (Luxembourg) */
|
||||
APP_USBD_SUBLANG_GERMAN_LIECHTENSTEIN = APP_USB_SUBLANG_DEF(0x05U), /**< German (Liechtenstein) */
|
||||
APP_USBD_SUBLANG_ITALIAN = APP_USB_SUBLANG_DEF(0x01U), /**< Italian */
|
||||
APP_USBD_SUBLANG_ITALIAN_SWISS = APP_USB_SUBLANG_DEF(0x02U), /**< Italian (Switzerland) */
|
||||
APP_USBD_SUBLANG_KASHMIRI_INDIA = APP_USB_SUBLANG_DEF(0x02U), /**< Kashmiri (India) */
|
||||
APP_USBD_SUBLANG_KOREAN = APP_USB_SUBLANG_DEF(0x01U), /**< Korean */
|
||||
APP_USBD_SUBLANG_LITHUANIAN = APP_USB_SUBLANG_DEF(0x01U), /**< Lithuanian */
|
||||
APP_USBD_SUBLANG_MALAY_MALAYSIA = APP_USB_SUBLANG_DEF(0x01U), /**< Malay (Malaysia) */
|
||||
APP_USBD_SUBLANG_MALAY_BRUNEI_DARUSSALAM = APP_USB_SUBLANG_DEF(0x02U), /**< Malay (Brunei Darassalam) */
|
||||
APP_USBD_SUBLANG_NEPALI_INDIA = APP_USB_SUBLANG_DEF(0x02U), /**< Nepali (India) */
|
||||
APP_USBD_SUBLANG_NORWEGIAN_BOKMAL = APP_USB_SUBLANG_DEF(0x01U), /**< Norwegian (Bokmal) */
|
||||
APP_USBD_SUBLANG_NORWEGIAN_NYNORSK = APP_USB_SUBLANG_DEF(0x02U), /**< Norwegian (Nynorsk) */
|
||||
APP_USBD_SUBLANG_PORTUGUESE = APP_USB_SUBLANG_DEF(0x01U), /**< Portuguese */
|
||||
APP_USBD_SUBLANG_PORTUGUESE_BRAZILIAN = APP_USB_SUBLANG_DEF(0x02U), /**< Portuguese (Brazil) */
|
||||
APP_USBD_SUBLANG_SERBIAN_LATIN = APP_USB_SUBLANG_DEF(0x02U), /**< Serbian (Latin) */
|
||||
APP_USBD_SUBLANG_SERBIAN_CYRILLIC = APP_USB_SUBLANG_DEF(0x03U), /**< Serbian (Cyrillic) */
|
||||
APP_USBD_SUBLANG_SPANISH = APP_USB_SUBLANG_DEF(0x01U), /**< Spanish (Traditional) */
|
||||
APP_USBD_SUBLANG_SPANISH_MEXICAN = APP_USB_SUBLANG_DEF(0x02U), /**< Spanish (Mexican) */
|
||||
APP_USBD_SUBLANG_SPANISH_MODERN = APP_USB_SUBLANG_DEF(0x03U), /**< Spanish (Modern) */
|
||||
APP_USBD_SUBLANG_SPANISH_GUATEMALA = APP_USB_SUBLANG_DEF(0x04U), /**< Spanish (Guatemala) */
|
||||
APP_USBD_SUBLANG_SPANISH_COSTA_RICA = APP_USB_SUBLANG_DEF(0x05U), /**< Spanish (Costa Rica) */
|
||||
APP_USBD_SUBLANG_SPANISH_PANAMA = APP_USB_SUBLANG_DEF(0x06U), /**< Spanish (Panama) */
|
||||
APP_USBD_SUBLANG_SPANISH_DOMINICAN_REPUBLIC = APP_USB_SUBLANG_DEF(0x07U), /**< Spanish (Dominican Republic) */
|
||||
APP_USBD_SUBLANG_SPANISH_VENEZUELA = APP_USB_SUBLANG_DEF(0x08U), /**< Spanish (Venezuela) */
|
||||
APP_USBD_SUBLANG_SPANISH_COLOMBIA = APP_USB_SUBLANG_DEF(0x09U), /**< Spanish (Colombia) */
|
||||
APP_USBD_SUBLANG_SPANISH_PERU = APP_USB_SUBLANG_DEF(0x0aU), /**< Spanish (Peru) */
|
||||
APP_USBD_SUBLANG_SPANISH_ARGENTINA = APP_USB_SUBLANG_DEF(0x0bU), /**< Spanish (Argentina) */
|
||||
APP_USBD_SUBLANG_SPANISH_ECUADOR = APP_USB_SUBLANG_DEF(0x0cU), /**< Spanish (Ecuador) */
|
||||
APP_USBD_SUBLANG_SPANISH_CHILE = APP_USB_SUBLANG_DEF(0x0dU), /**< Spanish (Chile) */
|
||||
APP_USBD_SUBLANG_SPANISH_URUGUAY = APP_USB_SUBLANG_DEF(0x0eU), /**< Spanish (Uruguay) */
|
||||
APP_USBD_SUBLANG_SPANISH_PARAGUAY = APP_USB_SUBLANG_DEF(0x0fU), /**< Spanish (Paraguay) */
|
||||
APP_USBD_SUBLANG_SPANISH_BOLIVIA = APP_USB_SUBLANG_DEF(0x10U), /**< Spanish (Bolivia) */
|
||||
APP_USBD_SUBLANG_SPANISH_EL_SALVADOR = APP_USB_SUBLANG_DEF(0x11U), /**< Spanish (El Salvador) */
|
||||
APP_USBD_SUBLANG_SPANISH_HONDURAS = APP_USB_SUBLANG_DEF(0x12U), /**< Spanish (Honduras) */
|
||||
APP_USBD_SUBLANG_SPANISH_NICARAGUA = APP_USB_SUBLANG_DEF(0x13U), /**< Spanish (Nicaragua) */
|
||||
APP_USBD_SUBLANG_SPANISH_PUERTO_RICO = APP_USB_SUBLANG_DEF(0x14U), /**< Spanish (Puerto Rico) */
|
||||
APP_USBD_SUBLANG_SWEDISH = APP_USB_SUBLANG_DEF(0x01U), /**< Swedish */
|
||||
APP_USBD_SUBLANG_SWEDISH_FINLAND = APP_USB_SUBLANG_DEF(0x02U), /**< Swedish (Finland) */
|
||||
APP_USBD_SUBLANG_URDU_PAKISTAN = APP_USB_SUBLANG_DEF(0x01U), /**< Urdu (Pakistan) */
|
||||
APP_USBD_SUBLANG_URDU_INDIA = APP_USB_SUBLANG_DEF(0x02U), /**< Urdu (India) */
|
||||
APP_USBD_SUBLANG_UZBEK_LATIN = APP_USB_SUBLANG_DEF(0x01U), /**< Uzbek (Latin) */
|
||||
APP_USBD_SUBLANG_UZBEK_CYRILLIC = APP_USB_SUBLANG_DEF(0x02U), /**< Uzbek (Cyrillic) */
|
||||
APP_USBD_SUBLANG_HID_USAGE_DATA_DESCRIPTOR = APP_USB_SUBLANG_DEF(0x01U), /**< HID (Usage Data Descriptor) */
|
||||
APP_USBD_SUBLANG_HID_VENDOR_DEFINED_1 = APP_USB_SUBLANG_DEF(0x3cU), /**< HID (Vendor Defined 1) */
|
||||
APP_USBD_SUBLANG_HID_VENDOR_DEFINED_2 = APP_USB_SUBLANG_DEF(0x3dU), /**< HID (Vendor Defined 2) */
|
||||
APP_USBD_SUBLANG_HID_VENDOR_DEFINED_3 = APP_USB_SUBLANG_DEF(0x3eU), /**< HID (Vendor Defined 3) */
|
||||
APP_USBD_SUBLANG_HID_VENDOR_DEFINED_4 = APP_USB_SUBLANG_DEF(0x3fU), /**< HID (Vendor Defined 4) */
|
||||
} app_usbd_langid_sub_t;
|
||||
|
||||
/**
|
||||
* @brief LANGID variable.
|
||||
*
|
||||
* The LANGID value is composed of:
|
||||
* - 10 bits (9-0) of Primary Language Identifier,
|
||||
* - 6 bits (15-10) of Sublanguage Identifier.
|
||||
*
|
||||
* @sa app_usbd_langid_primary_t
|
||||
* @sa app_usbd_langid_sub_t
|
||||
*/
|
||||
typedef uint16_t app_usbd_langid_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_LANGID_H__ */
|
||||
|
||||
+356
-356
@@ -1,356 +1,356 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_REQUEST_H__
|
||||
#define APP_USBD_REQUEST_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_usbd.h"
|
||||
#include "app_usbd_descriptor.h"
|
||||
#include "app_util_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Compiler support for anonymous unions */
|
||||
ANON_UNIONS_ENABLE;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_request USB standard requests
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 Module with types definitions used for standard requests processing.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Recipient bit-field in request type.
|
||||
*
|
||||
* Bits 4...0
|
||||
*/
|
||||
#define APP_USBD_SETUP_REQ_BF_REC BF_CX(5, 0)
|
||||
|
||||
/**
|
||||
* @brief Type bit-field in request type.
|
||||
*
|
||||
* Bits 6...5
|
||||
*/
|
||||
#define APP_USBD_SETUP_REQ_BF_TYP BF_CX(2, 5)
|
||||
|
||||
/**
|
||||
* @brief Direction bit-field in request type.
|
||||
*
|
||||
* Bit 7
|
||||
*/
|
||||
#define APP_USBD_SETUP_REQ_BF_DIR BF_CX(1, 7)
|
||||
|
||||
/**
|
||||
* @brief Recipient enumerator.
|
||||
*
|
||||
* @note It is part of @ref app_usbd_setup_reqtype_t variable type.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_SETUP_REQREC_DEVICE = 0x0, /**< The whole device is a request target */
|
||||
APP_USBD_SETUP_REQREC_INTERFACE = 0x1, /**< Selected interface is a request target */
|
||||
APP_USBD_SETUP_REQREC_ENDPOINT = 0x2, /**< Selected endpoint is a request target */
|
||||
APP_USBD_SETUP_REQREC_OTHER = 0x3 /**< Other element is a request target */
|
||||
} app_usbd_setup_reqrec_t;
|
||||
|
||||
/**
|
||||
* @brief Request type enumerator.
|
||||
*
|
||||
* @note It is part of @ref app_usbd_setup_reqtype_t variable type.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_SETUP_REQTYPE_STD = 0x0, /**< Standard request */
|
||||
APP_USBD_SETUP_REQTYPE_CLASS = 0x1, /**< Class specific request */
|
||||
APP_USBD_SETUP_REQTYPE_VENDOR = 0x2 /**< Vendor specific request */
|
||||
} app_usbd_setup_reqtype_t;
|
||||
|
||||
/**
|
||||
* @brief Direction of setup command.
|
||||
*
|
||||
* @note It is part of @ref app_usbd_setup_reqtype_t variable type.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_SETUP_REQDIR_OUT = 0x0, /**< Host to device */
|
||||
APP_USBD_SETUP_REQDIR_IN = 0x1, /**< Device to host */
|
||||
} app_usbd_setup_reqdir_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Standard requests.
|
||||
*
|
||||
* Enumerator for standard requests values.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_SETUP_STDREQ_GET_STATUS = 0x00, /**<
|
||||
* Targets: Device, Interface, Endpoint
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: Zero
|
||||
* - wIndex: Zero, (lb): Interface or Endpoint
|
||||
* - wLength: 2
|
||||
* - Data:2 bytes of data, depending on targets
|
||||
* - Device:
|
||||
* - D15..D2: Reserved (Reset to zero)
|
||||
* - D1: Remove Wakeup
|
||||
* - D0: Self Powered
|
||||
* - Interface:
|
||||
* - D15..D0: Reserved (Reset to zero)
|
||||
* - Endpoint:
|
||||
* - D15..D1: Reserved (Reset to zero)
|
||||
* - D0: Halt
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_CLEAR_FEATURE = 0x01, /**<
|
||||
* Targets: Device, Interface, Endpoint
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: Feature selector (@ref app_usbd_setup_stdfeature_t)
|
||||
* - wIndex: Zero, Interface or Endpoint
|
||||
* - wLength: 0
|
||||
* - Data: None
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_SET_FEATURE = 0x03, /**<
|
||||
* Targets: Device, Interface, Endpoint
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: Feature selector (@ref app_usbd_setup_stdfeature_t)
|
||||
* - wIndex: Zero, Interface or Endpoint
|
||||
* - wLength: 0
|
||||
* - Data: None
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_SET_ADDRESS = 0x05, /**<
|
||||
* @note This SETUP request is processed in hardware.
|
||||
* Use it only to mark current USB state.
|
||||
*
|
||||
* Targets: Device
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: New device address
|
||||
* - wIndex: 0
|
||||
* - wLength: 0
|
||||
* - Data: None
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_GET_DESCRIPTOR = 0x06, /**<
|
||||
* Targets: Device
|
||||
* - wValue: (hb): Descriptor Type and (lb): Descriptor Index
|
||||
* - wIndex: Zero of Language ID
|
||||
* - wLength: Descriptor Length
|
||||
* - Data: Descriptor
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_SET_DESCRIPTOR = 0x07, /**<
|
||||
* Not supported - Stall when called.
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_GET_CONFIGURATION = 0x08, /**<
|
||||
* Target: Device
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: 0
|
||||
* - wIndex: 0
|
||||
* - wLength: 1
|
||||
* - Data: Configuration value
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_SET_CONFIGURATION = 0x09, /**<
|
||||
* Target: Device
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: (lb): Configuration value
|
||||
* - wIndex: 0
|
||||
* - wLength: 0
|
||||
* - Data: None
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_GET_INTERFACE = 0x0A, /**<
|
||||
* Target: Interface
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: 0
|
||||
* - wIndex: Interface
|
||||
* - wLength: 1
|
||||
* - Data: Alternate setting
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_SET_INTERFACE = 0x0B, /**<
|
||||
* Target: Interface
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: Alternate setting
|
||||
* - wIndex: Interface
|
||||
* - wLength: 0
|
||||
* - Data: None
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_SYNCH_FRAME = 0x0C /**<
|
||||
* Target: Endpoint
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: 0
|
||||
* - wIndex: Endpoint
|
||||
* - wLength: 2
|
||||
* - Data: Frame Number
|
||||
*
|
||||
* @note
|
||||
* This request is used only in connection with isochronous endpoints.
|
||||
* This is rarely used and probably we would not need to support it.
|
||||
*/
|
||||
} app_usbd_setup_stdrequest_t;
|
||||
|
||||
/**
|
||||
* @brief Standard feature selectors.
|
||||
*
|
||||
* Standard features that may be disabled or enabled by
|
||||
* @ref APP_USBD_SETUP_STDREQ_CLEAR_FEATURE or @ref APP_USBD_SETUP_STDREQ_SET_FEATURE
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_SETUP_STDFEATURE_DEVICE_REMOTE_WAKEUP = 1, /**<
|
||||
* Remote wakeup feature.
|
||||
* Target: Device only
|
||||
*/
|
||||
APP_USBD_SETUP_STDFEATURE_ENDPOINT_HALT = 0, /**<
|
||||
* Stall or clear the endpoint.
|
||||
* Target: Endpoint different than default (0)
|
||||
*/
|
||||
APP_USBD_SETUP_STDFEATURE_TEST_MODE = 2 /**<
|
||||
* Upstream port test mode.
|
||||
* Power has to be cycled to exit test mode.
|
||||
* This feature cannot be cleared.
|
||||
*
|
||||
* Target: Device only
|
||||
*
|
||||
* @note
|
||||
* It should only be supported by HighSpeed capable devices.
|
||||
* Not supported in this library.
|
||||
*/
|
||||
} app_usbd_setup_stdfeature_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Universal way to access 16 bit values and its parts.
|
||||
*/
|
||||
typedef union {
|
||||
uint16_t w; //!< 16 bit access
|
||||
struct
|
||||
{
|
||||
uint8_t lb; //!< Low byte access
|
||||
uint8_t hb; //!< High byte access
|
||||
};
|
||||
} app_usbd_setup_w_t;
|
||||
|
||||
/**
|
||||
* @brief Internal redefinition of setup structure.
|
||||
*
|
||||
* Redefinition of the structure to simplify changes in the future
|
||||
* if required - app_usbd API would present setup data using app_usbd_setup_t.
|
||||
*
|
||||
* The structure layout is always the same like @ref nrf_drv_usbd_setup_t
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t bmRequestType; //!< Setup type bitfield
|
||||
uint8_t bmRequest; //!< One of @ref app_usbd_setup_stdrequest_t values or class dependent one.
|
||||
app_usbd_setup_w_t wValue; //!< byte 2, 3
|
||||
app_usbd_setup_w_t wIndex; //!< byte 4, 5
|
||||
app_usbd_setup_w_t wLength; //!< byte 6, 7
|
||||
} app_usbd_setup_t;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extract recipient from request type.
|
||||
*
|
||||
* @param[in] bmRequestType
|
||||
*
|
||||
* @return Extracted recipient field from request type value.
|
||||
*/
|
||||
static inline app_usbd_setup_reqrec_t app_usbd_setup_req_rec(uint8_t bmRequestType)
|
||||
{
|
||||
return (app_usbd_setup_reqrec_t)BF_CX_GET(bmRequestType, APP_USBD_SETUP_REQ_BF_REC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Extract type from request type.
|
||||
*
|
||||
* @param[in] bmRequestType
|
||||
*
|
||||
* @return Extracted type field from request type value.
|
||||
*/
|
||||
static inline app_usbd_setup_reqtype_t app_usbd_setup_req_typ(uint8_t bmRequestType)
|
||||
{
|
||||
return (app_usbd_setup_reqtype_t)BF_CX_GET(bmRequestType, APP_USBD_SETUP_REQ_BF_TYP);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extract direction from request type.
|
||||
*
|
||||
* @param[in] bmRequestType
|
||||
*
|
||||
* @return Extracted direction field from request type value.
|
||||
*/
|
||||
static inline app_usbd_setup_reqdir_t app_usbd_setup_req_dir(uint8_t bmRequestType)
|
||||
{
|
||||
return (app_usbd_setup_reqdir_t)BF_CX_GET(bmRequestType, APP_USBD_SETUP_REQ_BF_DIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Make request type value.
|
||||
*
|
||||
* @param[in] rec Recipient.
|
||||
* @param[in] typ Request type.
|
||||
* @param[in] dir Direction.
|
||||
*
|
||||
* @return Assembled request type value.
|
||||
*/
|
||||
static inline uint8_t app_usbd_setup_req_val(app_usbd_setup_reqrec_t rec,
|
||||
app_usbd_setup_reqtype_t typ,
|
||||
app_usbd_setup_reqdir_t dir)
|
||||
{
|
||||
uint32_t bmRequestType = (
|
||||
BF_CX_VAL(rec, APP_USBD_SETUP_REQ_BF_REC) |
|
||||
BF_CX_VAL(typ, APP_USBD_SETUP_REQ_BF_TYP) |
|
||||
BF_CX_VAL(dir, APP_USBD_SETUP_REQ_BF_DIR)
|
||||
);
|
||||
|
||||
ASSERT(bmRequestType < 256U);
|
||||
return (uint8_t)bmRequestType;
|
||||
}
|
||||
|
||||
|
||||
ANON_UNIONS_DISABLE;
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_REQUEST_H__ */
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_REQUEST_H__
|
||||
#define APP_USBD_REQUEST_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_usbd.h"
|
||||
#include "app_usbd_descriptor.h"
|
||||
#include "app_util_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Compiler support for anonymous unions */
|
||||
ANON_UNIONS_ENABLE;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_request USB standard requests
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 Module with types definitions used for standard requests processing.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Recipient bit-field in request type.
|
||||
*
|
||||
* Bits 4...0
|
||||
*/
|
||||
#define APP_USBD_SETUP_REQ_BF_REC BF_CX(5, 0)
|
||||
|
||||
/**
|
||||
* @brief Type bit-field in request type.
|
||||
*
|
||||
* Bits 6...5
|
||||
*/
|
||||
#define APP_USBD_SETUP_REQ_BF_TYP BF_CX(2, 5)
|
||||
|
||||
/**
|
||||
* @brief Direction bit-field in request type.
|
||||
*
|
||||
* Bit 7
|
||||
*/
|
||||
#define APP_USBD_SETUP_REQ_BF_DIR BF_CX(1, 7)
|
||||
|
||||
/**
|
||||
* @brief Recipient enumerator.
|
||||
*
|
||||
* @note It is part of @ref app_usbd_setup_reqtype_t variable type.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_SETUP_REQREC_DEVICE = 0x0, /**< The whole device is a request target */
|
||||
APP_USBD_SETUP_REQREC_INTERFACE = 0x1, /**< Selected interface is a request target */
|
||||
APP_USBD_SETUP_REQREC_ENDPOINT = 0x2, /**< Selected endpoint is a request target */
|
||||
APP_USBD_SETUP_REQREC_OTHER = 0x3 /**< Other element is a request target */
|
||||
} app_usbd_setup_reqrec_t;
|
||||
|
||||
/**
|
||||
* @brief Request type enumerator.
|
||||
*
|
||||
* @note It is part of @ref app_usbd_setup_reqtype_t variable type.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_SETUP_REQTYPE_STD = 0x0, /**< Standard request */
|
||||
APP_USBD_SETUP_REQTYPE_CLASS = 0x1, /**< Class specific request */
|
||||
APP_USBD_SETUP_REQTYPE_VENDOR = 0x2 /**< Vendor specific request */
|
||||
} app_usbd_setup_reqtype_t;
|
||||
|
||||
/**
|
||||
* @brief Direction of setup command.
|
||||
*
|
||||
* @note It is part of @ref app_usbd_setup_reqtype_t variable type.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_SETUP_REQDIR_OUT = 0x0, /**< Host to device */
|
||||
APP_USBD_SETUP_REQDIR_IN = 0x1, /**< Device to host */
|
||||
} app_usbd_setup_reqdir_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Standard requests.
|
||||
*
|
||||
* Enumerator for standard requests values.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_SETUP_STDREQ_GET_STATUS = 0x00, /**<
|
||||
* Targets: Device, Interface, Endpoint
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: Zero
|
||||
* - wIndex: Zero, (lb): Interface or Endpoint
|
||||
* - wLength: 2
|
||||
* - Data:2 bytes of data, depending on targets
|
||||
* - Device:
|
||||
* - D15..D2: Reserved (Reset to zero)
|
||||
* - D1: Remove Wakeup
|
||||
* - D0: Self Powered
|
||||
* - Interface:
|
||||
* - D15..D0: Reserved (Reset to zero)
|
||||
* - Endpoint:
|
||||
* - D15..D1: Reserved (Reset to zero)
|
||||
* - D0: Halt
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_CLEAR_FEATURE = 0x01, /**<
|
||||
* Targets: Device, Interface, Endpoint
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: Feature selector (@ref app_usbd_setup_stdfeature_t)
|
||||
* - wIndex: Zero, Interface or Endpoint
|
||||
* - wLength: 0
|
||||
* - Data: None
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_SET_FEATURE = 0x03, /**<
|
||||
* Targets: Device, Interface, Endpoint
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: Feature selector (@ref app_usbd_setup_stdfeature_t)
|
||||
* - wIndex: Zero, Interface or Endpoint
|
||||
* - wLength: 0
|
||||
* - Data: None
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_SET_ADDRESS = 0x05, /**<
|
||||
* @note This SETUP request is processed in hardware.
|
||||
* Use it only to mark current USB state.
|
||||
*
|
||||
* Targets: Device
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: New device address
|
||||
* - wIndex: 0
|
||||
* - wLength: 0
|
||||
* - Data: None
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_GET_DESCRIPTOR = 0x06, /**<
|
||||
* Targets: Device
|
||||
* - wValue: (hb): Descriptor Type and (lb): Descriptor Index
|
||||
* - wIndex: Zero of Language ID
|
||||
* - wLength: Descriptor Length
|
||||
* - Data: Descriptor
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_SET_DESCRIPTOR = 0x07, /**<
|
||||
* Not supported - Stall when called.
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_GET_CONFIGURATION = 0x08, /**<
|
||||
* Target: Device
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: 0
|
||||
* - wIndex: 0
|
||||
* - wLength: 1
|
||||
* - Data: Configuration value
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_SET_CONFIGURATION = 0x09, /**<
|
||||
* Target: Device
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: (lb): Configuration value
|
||||
* - wIndex: 0
|
||||
* - wLength: 0
|
||||
* - Data: None
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_GET_INTERFACE = 0x0A, /**<
|
||||
* Target: Interface
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: 0
|
||||
* - wIndex: Interface
|
||||
* - wLength: 1
|
||||
* - Data: Alternate setting
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_SET_INTERFACE = 0x0B, /**<
|
||||
* Target: Interface
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: Alternate setting
|
||||
* - wIndex: Interface
|
||||
* - wLength: 0
|
||||
* - Data: None
|
||||
*/
|
||||
APP_USBD_SETUP_STDREQ_SYNCH_FRAME = 0x0C /**<
|
||||
* Target: Endpoint
|
||||
* Expected SETUP frame format:
|
||||
* - wValue: 0
|
||||
* - wIndex: Endpoint
|
||||
* - wLength: 2
|
||||
* - Data: Frame Number
|
||||
*
|
||||
* @note
|
||||
* This request is used only in connection with isochronous endpoints.
|
||||
* This is rarely used and probably we would not need to support it.
|
||||
*/
|
||||
} app_usbd_setup_stdrequest_t;
|
||||
|
||||
/**
|
||||
* @brief Standard feature selectors.
|
||||
*
|
||||
* Standard features that may be disabled or enabled by
|
||||
* @ref APP_USBD_SETUP_STDREQ_CLEAR_FEATURE or @ref APP_USBD_SETUP_STDREQ_SET_FEATURE
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_SETUP_STDFEATURE_DEVICE_REMOTE_WAKEUP = 1, /**<
|
||||
* Remote wakeup feature.
|
||||
* Target: Device only
|
||||
*/
|
||||
APP_USBD_SETUP_STDFEATURE_ENDPOINT_HALT = 0, /**<
|
||||
* Stall or clear the endpoint.
|
||||
* Target: Endpoint different than default (0)
|
||||
*/
|
||||
APP_USBD_SETUP_STDFEATURE_TEST_MODE = 2 /**<
|
||||
* Upstream port test mode.
|
||||
* Power has to be cycled to exit test mode.
|
||||
* This feature cannot be cleared.
|
||||
*
|
||||
* Target: Device only
|
||||
*
|
||||
* @note
|
||||
* It should only be supported by HighSpeed capable devices.
|
||||
* Not supported in this library.
|
||||
*/
|
||||
} app_usbd_setup_stdfeature_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Universal way to access 16 bit values and its parts.
|
||||
*/
|
||||
typedef union {
|
||||
uint16_t w; //!< 16 bit access
|
||||
struct
|
||||
{
|
||||
uint8_t lb; //!< Low byte access
|
||||
uint8_t hb; //!< High byte access
|
||||
};
|
||||
} app_usbd_setup_w_t;
|
||||
|
||||
/**
|
||||
* @brief Internal redefinition of setup structure.
|
||||
*
|
||||
* Redefinition of the structure to simplify changes in the future
|
||||
* if required - app_usbd API would present setup data using app_usbd_setup_t.
|
||||
*
|
||||
* The structure layout is always the same like @ref nrf_drv_usbd_setup_t
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t bmRequestType; //!< Setup type bitfield
|
||||
uint8_t bmRequest; //!< One of @ref app_usbd_setup_stdrequest_t values or class dependent one.
|
||||
app_usbd_setup_w_t wValue; //!< byte 2, 3
|
||||
app_usbd_setup_w_t wIndex; //!< byte 4, 5
|
||||
app_usbd_setup_w_t wLength; //!< byte 6, 7
|
||||
} app_usbd_setup_t;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extract recipient from request type.
|
||||
*
|
||||
* @param[in] bmRequestType
|
||||
*
|
||||
* @return Extracted recipient field from request type value.
|
||||
*/
|
||||
static inline app_usbd_setup_reqrec_t app_usbd_setup_req_rec(uint8_t bmRequestType)
|
||||
{
|
||||
return (app_usbd_setup_reqrec_t)BF_CX_GET(bmRequestType, APP_USBD_SETUP_REQ_BF_REC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Extract type from request type.
|
||||
*
|
||||
* @param[in] bmRequestType
|
||||
*
|
||||
* @return Extracted type field from request type value.
|
||||
*/
|
||||
static inline app_usbd_setup_reqtype_t app_usbd_setup_req_typ(uint8_t bmRequestType)
|
||||
{
|
||||
return (app_usbd_setup_reqtype_t)BF_CX_GET(bmRequestType, APP_USBD_SETUP_REQ_BF_TYP);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Extract direction from request type.
|
||||
*
|
||||
* @param[in] bmRequestType
|
||||
*
|
||||
* @return Extracted direction field from request type value.
|
||||
*/
|
||||
static inline app_usbd_setup_reqdir_t app_usbd_setup_req_dir(uint8_t bmRequestType)
|
||||
{
|
||||
return (app_usbd_setup_reqdir_t)BF_CX_GET(bmRequestType, APP_USBD_SETUP_REQ_BF_DIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Make request type value.
|
||||
*
|
||||
* @param[in] rec Recipient.
|
||||
* @param[in] typ Request type.
|
||||
* @param[in] dir Direction.
|
||||
*
|
||||
* @return Assembled request type value.
|
||||
*/
|
||||
static inline uint8_t app_usbd_setup_req_val(app_usbd_setup_reqrec_t rec,
|
||||
app_usbd_setup_reqtype_t typ,
|
||||
app_usbd_setup_reqdir_t dir)
|
||||
{
|
||||
uint32_t bmRequestType = (
|
||||
BF_CX_VAL(rec, APP_USBD_SETUP_REQ_BF_REC) |
|
||||
BF_CX_VAL(typ, APP_USBD_SETUP_REQ_BF_TYP) |
|
||||
BF_CX_VAL(dir, APP_USBD_SETUP_REQ_BF_DIR)
|
||||
);
|
||||
|
||||
ASSERT(bmRequestType < 256U);
|
||||
return (uint8_t)bmRequestType;
|
||||
}
|
||||
|
||||
|
||||
ANON_UNIONS_DISABLE;
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_REQUEST_H__ */
|
||||
|
||||
@@ -1,84 +1,84 @@
|
||||
/**
|
||||
* Copyright (c) 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "app_usbd_serial_num.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "app_usbd.h"
|
||||
|
||||
#define SERIAL_NUMBER_STRING_SIZE (12)
|
||||
|
||||
/**@brief Serial number generated.
|
||||
*
|
||||
* Serial number generated by the @ref serial_number_string_create function.
|
||||
*/
|
||||
uint8_t g_extern_serial_number[SERIAL_NUMBER_STRING_SIZE + 1];
|
||||
|
||||
|
||||
/**@brief Function for creating the serial number string from a regular C string.
|
||||
*
|
||||
* @param[in] p_serial_number_string The serial number string. Must be terminated with \0.
|
||||
*/
|
||||
static void string_create(char * p_serial_number_string)
|
||||
{
|
||||
|
||||
for (uint32_t i = 0; i < strlen(p_serial_number_string); i++)
|
||||
{
|
||||
g_extern_serial_number[i] = (uint8_t)p_serial_number_string[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void app_usbd_serial_num_generate(void)
|
||||
{
|
||||
char serial_number_string[SERIAL_NUMBER_STRING_SIZE + 1];
|
||||
const uint16_t serial_num_high_bytes = (uint16_t)NRF_FICR->DEVICEADDR[1] | 0xC000; // The masking makes the address match the Random Static BLE address.
|
||||
const uint32_t serial_num_low_bytes = NRF_FICR->DEVICEADDR[0];
|
||||
|
||||
(void)snprintf(serial_number_string,
|
||||
SERIAL_NUMBER_STRING_SIZE + 1,
|
||||
"%04"PRIX16"%08"PRIX32,
|
||||
serial_num_high_bytes,
|
||||
serial_num_low_bytes);
|
||||
|
||||
string_create(serial_number_string);
|
||||
}
|
||||
/**
|
||||
* Copyright (c) 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "app_usbd_serial_num.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "app_usbd.h"
|
||||
|
||||
#define SERIAL_NUMBER_STRING_SIZE (12)
|
||||
|
||||
/**@brief Serial number generated.
|
||||
*
|
||||
* Serial number generated by the @ref serial_number_string_create function.
|
||||
*/
|
||||
uint8_t g_extern_serial_number[SERIAL_NUMBER_STRING_SIZE + 1];
|
||||
|
||||
|
||||
/**@brief Function for creating the serial number string from a regular C string.
|
||||
*
|
||||
* @param[in] p_serial_number_string The serial number string. Must be terminated with \0.
|
||||
*/
|
||||
static void string_create(char * p_serial_number_string)
|
||||
{
|
||||
|
||||
for (uint32_t i = 0; i < strlen(p_serial_number_string); i++)
|
||||
{
|
||||
g_extern_serial_number[i] = (uint8_t)p_serial_number_string[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void app_usbd_serial_num_generate(void)
|
||||
{
|
||||
char serial_number_string[SERIAL_NUMBER_STRING_SIZE + 1];
|
||||
const uint16_t serial_num_high_bytes = (uint16_t)NRF_FICR->DEVICEADDR[1] | 0xC000; // The masking makes the address match the Random Static BLE address.
|
||||
const uint32_t serial_num_low_bytes = NRF_FICR->DEVICEADDR[0];
|
||||
|
||||
(void)snprintf(serial_number_string,
|
||||
SERIAL_NUMBER_STRING_SIZE + 1,
|
||||
"%04"PRIX16"%08"PRIX32,
|
||||
serial_num_high_bytes,
|
||||
serial_num_low_bytes);
|
||||
|
||||
string_create(serial_number_string);
|
||||
}
|
||||
|
||||
@@ -1,75 +1,75 @@
|
||||
/**
|
||||
* Copyright (c) 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_SERIAL_NUM_H__
|
||||
#define APP_USBD_SERIAL_NUM_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_serial_num USBD serial number generator
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 Generate a standard USB serial number that is unique for each device.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**@brief Function for generating a default serial number string based on FIRC->DEVICEADDR.
|
||||
*
|
||||
* After calling this function, the serial number is ready for the USB driver.
|
||||
*
|
||||
* The generated serial number shows up as a 12-hexidecimal-digit string with no delimiters
|
||||
* (e.g 123456ABCDEF). The byte string is also printed on the PCA10059 dongle. It is also used as
|
||||
* the default advertising address in the SoftDevice.
|
||||
*/
|
||||
void app_usbd_serial_num_generate(void);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APP_USBD_SERIAL_NUM_H__
|
||||
/**
|
||||
* Copyright (c) 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_SERIAL_NUM_H__
|
||||
#define APP_USBD_SERIAL_NUM_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_serial_num USBD serial number generator
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 Generate a standard USB serial number that is unique for each device.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**@brief Function for generating a default serial number string based on FIRC->DEVICEADDR.
|
||||
*
|
||||
* After calling this function, the serial number is ready for the USB driver.
|
||||
*
|
||||
* The generated serial number shows up as a 12-hexidecimal-digit string with no delimiters
|
||||
* (e.g 123456ABCDEF). The byte string is also printed on the PCA10059 dongle. It is also used as
|
||||
* the default advertising address in the SoftDevice.
|
||||
*/
|
||||
void app_usbd_serial_num_generate(void);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // APP_USBD_SERIAL_NUM_H__
|
||||
|
||||
+295
-295
@@ -1,295 +1,295 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_config.h"
|
||||
#if APP_USBD_ENABLED
|
||||
#include "app_usbd_string_desc.h"
|
||||
#include "app_usbd_langid.h"
|
||||
#include "app_usbd_core.h"
|
||||
#include "nordic_common.h"
|
||||
#include "utf.h"
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_string_desc
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* USBD string descriptor management
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Array with language identifiers.
|
||||
*
|
||||
* This array is used to search the proper string for the selected language.
|
||||
*/
|
||||
static uint16_t const m_langids[] = { APP_USBD_STRINGS_LANGIDS };
|
||||
|
||||
/**
|
||||
* @brief Language ID descriptor.
|
||||
*
|
||||
* Language.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Mnemonics for the string positions in the array.
|
||||
*
|
||||
* The mnemonics for the indexes of the strings inside the string array.
|
||||
*/
|
||||
enum {
|
||||
APP_USBD_STRING_ID_LANGIDS_ARRAY_POS = 0, /**< Supported language identifiers. */
|
||||
|
||||
#if (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
APP_USBD_STRING_ID_MANUFACTURER_ARRAY_POS, /**< Manufacturer name. */
|
||||
#endif // (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
APP_USBD_STRING_ID_PRODUCT_ARRAY_POS, /**< Product name. */
|
||||
#endif // (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
APP_USBD_STRING_ID_SERIAL_ARRAY_POS, /**< Serial number. */
|
||||
#endif // (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
APP_USBD_STRING_ID_CONFIGURATION_ARRAY_POS, /**< Configuration string. */
|
||||
#endif // (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
|
||||
#define X(mnemonic, str_idx, ...) CONCAT_2(mnemonic, _ARRAY_POS),
|
||||
APP_USBD_STRINGS_USER
|
||||
#undef X
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief String index into internal array index conversion table.
|
||||
*
|
||||
* The array that transforms the USB string indexes into internal array position.
|
||||
* @note Value 0 is used to mark non-existing string.
|
||||
*/
|
||||
static uint8_t const m_string_translation[APP_USBD_STRING_ID_CNT] =
|
||||
{
|
||||
[APP_USBD_STRING_ID_LANGIDS] = APP_USBD_STRING_ID_LANGIDS_ARRAY_POS,
|
||||
|
||||
#if (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
[APP_USBD_STRING_ID_MANUFACTURER] = APP_USBD_STRING_ID_MANUFACTURER_ARRAY_POS,
|
||||
#endif // (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
[APP_USBD_STRING_ID_PRODUCT] = APP_USBD_STRING_ID_PRODUCT_ARRAY_POS,
|
||||
#endif // (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
[APP_USBD_STRING_ID_SERIAL] = APP_USBD_STRING_ID_SERIAL_ARRAY_POS,
|
||||
#endif // (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
[APP_USBD_STRING_ID_CONFIGURATION] = APP_USBD_STRING_ID_CONFIGURATION_ARRAY_POS,
|
||||
#endif // (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
|
||||
#define X(mnemonic, str_idx, ...) [mnemonic] = CONCAT_2(mnemonic, _ARRAY_POS),
|
||||
APP_USBD_STRINGS_USER
|
||||
#undef X
|
||||
};
|
||||
|
||||
#ifndef APP_USBD_STRINGS_MANUFACTURER_EXTERN
|
||||
#define APP_USBD_STRINGS_MANUFACTURER_EXTERN 0
|
||||
#endif
|
||||
|
||||
#if APP_USBD_STRINGS_MANUFACTURER_EXTERN
|
||||
extern uint8_t APP_USBD_STRINGS_MANUFACTURER[];
|
||||
#endif
|
||||
|
||||
#ifndef APP_USBD_STRINGS_PRODUCT_EXTERN
|
||||
#define APP_USBD_STRINGS_PRODUCT_EXTERN 0
|
||||
#endif
|
||||
|
||||
#if APP_USBD_STRINGS_PRODUCT_EXTERN
|
||||
extern uint8_t APP_USBD_STRINGS_PRODUCT[];
|
||||
#endif
|
||||
|
||||
#ifndef APP_USBD_STRING_SERIAL_EXTERN
|
||||
#define APP_USBD_STRING_SERIAL_EXTERN 0
|
||||
#endif
|
||||
|
||||
#if APP_USBD_STRING_SERIAL_EXTERN
|
||||
extern uint8_t APP_USBD_STRING_SERIAL[];
|
||||
#endif
|
||||
|
||||
#ifndef APP_USBD_STRING_CONFIGURATION_EXTERN
|
||||
#define APP_USBD_STRING_CONFIGURATION_EXTERN 0
|
||||
#endif
|
||||
|
||||
#if APP_USBD_STRING_CONFIGURATION_EXTERN
|
||||
extern uint8_t APP_USBD_STRING_CONFIGURATION[];
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief String descriptor table.
|
||||
* */
|
||||
static uint8_t const * m_string_dsc[APP_USBD_STRING_ID_CNT][ARRAY_SIZE(m_langids)] =
|
||||
{
|
||||
[APP_USBD_STRING_ID_LANGIDS_ARRAY_POS] = {APP_USBD_STRING_RAW16_DESC(APP_USBD_STRINGS_LANGIDS)},
|
||||
|
||||
#if (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
[APP_USBD_STRING_ID_MANUFACTURER_ARRAY_POS] = { APP_USBD_STRINGS_MANUFACTURER },
|
||||
#endif // (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
[APP_USBD_STRING_ID_PRODUCT_ARRAY_POS] = { APP_USBD_STRINGS_PRODUCT },
|
||||
#endif // (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
[APP_USBD_STRING_ID_SERIAL_ARRAY_POS] = { APP_USBD_STRING_SERIAL },
|
||||
#endif // (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
[APP_USBD_STRING_ID_CONFIGURATION_ARRAY_POS] = { APP_USBD_STRINGS_CONFIGURATION },
|
||||
#endif // (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
|
||||
#define X(mnemonic, str_idx, ...) [CONCAT_2(mnemonic, _ARRAY_POS)] = {__VA_ARGS__},
|
||||
APP_USBD_STRINGS_USER
|
||||
#undef X
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Function for preparing UTF16 string descriptor.
|
||||
*
|
||||
* @param idx String descriptor ID.
|
||||
* @param langid Language ID.
|
||||
*
|
||||
* @return Pointer to the string descriptor.
|
||||
*/
|
||||
static uint16_t * app_usbd_prepare_string(uint8_t idx, uint16_t langid)
|
||||
{
|
||||
if (m_string_dsc[idx][langid][0] == 0x00)
|
||||
{
|
||||
return (uint16_t *) &(m_string_dsc[idx][langid][2]);
|
||||
}
|
||||
|
||||
#if ((APP_USBD_CONFIG_DESC_STRING_SIZE * 2) + 2) <= NRF_DRV_USBD_EPSIZE
|
||||
uint16_t * string_buffer = app_usbd_core_setup_transfer_buff_get(NULL);
|
||||
#else
|
||||
static uint16_t string_buffer[APP_USBD_CONFIG_DESC_STRING_SIZE + 1];
|
||||
// + 1 element for string descriptor type and size
|
||||
#endif
|
||||
|
||||
uint8_t size = 0;
|
||||
const uint8_t * p_pos = m_string_dsc[idx][langid];
|
||||
|
||||
#if APP_USBD_CONFIG_DESC_STRING_UTF_ENABLED
|
||||
size = utf8UTF16Count((char *) p_pos, 0);
|
||||
ASSERT(size <= APP_USBD_CONFIG_DESC_STRING_SIZE);
|
||||
|
||||
uint16_t * p_out = &(string_buffer[1]);
|
||||
uint32_t rune;
|
||||
|
||||
while (*p_pos != 0)
|
||||
{
|
||||
p_pos = (uint8_t *) utf8DecodeRune((char *) p_pos, 0, &rune);
|
||||
p_out += utf16EncodeRune(rune, p_out);
|
||||
}
|
||||
#else
|
||||
while(*p_pos != 0)
|
||||
{
|
||||
ASSERT(size < APP_USBD_CONFIG_DESC_STRING_SIZE);
|
||||
++size;
|
||||
string_buffer[size] = *p_pos;
|
||||
++p_pos;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Descriptor size is length of the string times 2 bytes per character + 2 bytes for
|
||||
// descriptor type and size.
|
||||
string_buffer[0] = (0xff & (size * 2 + 2)) | ((uint16_t)APP_USBD_DESCRIPTOR_STRING) << 8;
|
||||
|
||||
return string_buffer;
|
||||
}
|
||||
|
||||
uint16_t const * app_usbd_string_desc_get(uint8_t idx, uint16_t langid)
|
||||
{
|
||||
/* LANGID string. */
|
||||
if (APP_USBD_STRING_ID_LANGIDS == idx)
|
||||
{
|
||||
return app_usbd_prepare_string(APP_USBD_STRING_ID_LANGIDS_ARRAY_POS, 0);
|
||||
}
|
||||
|
||||
/* Searching for the language. */
|
||||
uint8_t lang_idx = 0;
|
||||
if (ARRAY_SIZE(m_langids) > 1)
|
||||
{
|
||||
while (m_langids[lang_idx] != langid)
|
||||
{
|
||||
++lang_idx;
|
||||
if (lang_idx >= ARRAY_SIZE(m_langids))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the string index in array. */
|
||||
if (idx >= ARRAY_SIZE(m_string_translation))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t str_pos = m_string_translation[idx];
|
||||
if (str_pos == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((ARRAY_SIZE(m_langids) > 1) && (lang_idx != 0))
|
||||
{
|
||||
if (m_string_dsc[str_pos][lang_idx] == NULL)
|
||||
{
|
||||
lang_idx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_string_dsc[str_pos][lang_idx] == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return app_usbd_prepare_string(str_pos, lang_idx);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
#endif // APP_USBD_ENABLED
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_config.h"
|
||||
#if APP_USBD_ENABLED
|
||||
#include "app_usbd_string_desc.h"
|
||||
#include "app_usbd_langid.h"
|
||||
#include "app_usbd_core.h"
|
||||
#include "nordic_common.h"
|
||||
#include "utf.h"
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_string_desc
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* USBD string descriptor management
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Array with language identifiers.
|
||||
*
|
||||
* This array is used to search the proper string for the selected language.
|
||||
*/
|
||||
static uint16_t const m_langids[] = { APP_USBD_STRINGS_LANGIDS };
|
||||
|
||||
/**
|
||||
* @brief Language ID descriptor.
|
||||
*
|
||||
* Language.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Mnemonics for the string positions in the array.
|
||||
*
|
||||
* The mnemonics for the indexes of the strings inside the string array.
|
||||
*/
|
||||
enum {
|
||||
APP_USBD_STRING_ID_LANGIDS_ARRAY_POS = 0, /**< Supported language identifiers. */
|
||||
|
||||
#if (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
APP_USBD_STRING_ID_MANUFACTURER_ARRAY_POS, /**< Manufacturer name. */
|
||||
#endif // (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
APP_USBD_STRING_ID_PRODUCT_ARRAY_POS, /**< Product name. */
|
||||
#endif // (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
APP_USBD_STRING_ID_SERIAL_ARRAY_POS, /**< Serial number. */
|
||||
#endif // (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
APP_USBD_STRING_ID_CONFIGURATION_ARRAY_POS, /**< Configuration string. */
|
||||
#endif // (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
|
||||
#define X(mnemonic, str_idx, ...) CONCAT_2(mnemonic, _ARRAY_POS),
|
||||
APP_USBD_STRINGS_USER
|
||||
#undef X
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief String index into internal array index conversion table.
|
||||
*
|
||||
* The array that transforms the USB string indexes into internal array position.
|
||||
* @note Value 0 is used to mark non-existing string.
|
||||
*/
|
||||
static uint8_t const m_string_translation[APP_USBD_STRING_ID_CNT] =
|
||||
{
|
||||
[APP_USBD_STRING_ID_LANGIDS] = APP_USBD_STRING_ID_LANGIDS_ARRAY_POS,
|
||||
|
||||
#if (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
[APP_USBD_STRING_ID_MANUFACTURER] = APP_USBD_STRING_ID_MANUFACTURER_ARRAY_POS,
|
||||
#endif // (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
[APP_USBD_STRING_ID_PRODUCT] = APP_USBD_STRING_ID_PRODUCT_ARRAY_POS,
|
||||
#endif // (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
[APP_USBD_STRING_ID_SERIAL] = APP_USBD_STRING_ID_SERIAL_ARRAY_POS,
|
||||
#endif // (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
[APP_USBD_STRING_ID_CONFIGURATION] = APP_USBD_STRING_ID_CONFIGURATION_ARRAY_POS,
|
||||
#endif // (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
|
||||
#define X(mnemonic, str_idx, ...) [mnemonic] = CONCAT_2(mnemonic, _ARRAY_POS),
|
||||
APP_USBD_STRINGS_USER
|
||||
#undef X
|
||||
};
|
||||
|
||||
#ifndef APP_USBD_STRINGS_MANUFACTURER_EXTERN
|
||||
#define APP_USBD_STRINGS_MANUFACTURER_EXTERN 0
|
||||
#endif
|
||||
|
||||
#if APP_USBD_STRINGS_MANUFACTURER_EXTERN
|
||||
extern uint8_t APP_USBD_STRINGS_MANUFACTURER[];
|
||||
#endif
|
||||
|
||||
#ifndef APP_USBD_STRINGS_PRODUCT_EXTERN
|
||||
#define APP_USBD_STRINGS_PRODUCT_EXTERN 0
|
||||
#endif
|
||||
|
||||
#if APP_USBD_STRINGS_PRODUCT_EXTERN
|
||||
extern uint8_t APP_USBD_STRINGS_PRODUCT[];
|
||||
#endif
|
||||
|
||||
#ifndef APP_USBD_STRING_SERIAL_EXTERN
|
||||
#define APP_USBD_STRING_SERIAL_EXTERN 0
|
||||
#endif
|
||||
|
||||
#if APP_USBD_STRING_SERIAL_EXTERN
|
||||
extern uint8_t APP_USBD_STRING_SERIAL[];
|
||||
#endif
|
||||
|
||||
#ifndef APP_USBD_STRING_CONFIGURATION_EXTERN
|
||||
#define APP_USBD_STRING_CONFIGURATION_EXTERN 0
|
||||
#endif
|
||||
|
||||
#if APP_USBD_STRING_CONFIGURATION_EXTERN
|
||||
extern uint8_t APP_USBD_STRING_CONFIGURATION[];
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief String descriptor table.
|
||||
* */
|
||||
static uint8_t const * m_string_dsc[APP_USBD_STRING_ID_CNT][ARRAY_SIZE(m_langids)] =
|
||||
{
|
||||
[APP_USBD_STRING_ID_LANGIDS_ARRAY_POS] = {APP_USBD_STRING_RAW16_DESC(APP_USBD_STRINGS_LANGIDS)},
|
||||
|
||||
#if (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
[APP_USBD_STRING_ID_MANUFACTURER_ARRAY_POS] = { APP_USBD_STRINGS_MANUFACTURER },
|
||||
#endif // (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
[APP_USBD_STRING_ID_PRODUCT_ARRAY_POS] = { APP_USBD_STRINGS_PRODUCT },
|
||||
#endif // (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
[APP_USBD_STRING_ID_SERIAL_ARRAY_POS] = { APP_USBD_STRING_SERIAL },
|
||||
#endif // (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
[APP_USBD_STRING_ID_CONFIGURATION_ARRAY_POS] = { APP_USBD_STRINGS_CONFIGURATION },
|
||||
#endif // (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
|
||||
#define X(mnemonic, str_idx, ...) [CONCAT_2(mnemonic, _ARRAY_POS)] = {__VA_ARGS__},
|
||||
APP_USBD_STRINGS_USER
|
||||
#undef X
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Function for preparing UTF16 string descriptor.
|
||||
*
|
||||
* @param idx String descriptor ID.
|
||||
* @param langid Language ID.
|
||||
*
|
||||
* @return Pointer to the string descriptor.
|
||||
*/
|
||||
static uint16_t * app_usbd_prepare_string(uint8_t idx, uint16_t langid)
|
||||
{
|
||||
if (m_string_dsc[idx][langid][0] == 0x00)
|
||||
{
|
||||
return (uint16_t *) &(m_string_dsc[idx][langid][2]);
|
||||
}
|
||||
|
||||
#if ((APP_USBD_CONFIG_DESC_STRING_SIZE * 2) + 2) <= NRF_DRV_USBD_EPSIZE
|
||||
uint16_t * string_buffer = app_usbd_core_setup_transfer_buff_get(NULL);
|
||||
#else
|
||||
static uint16_t string_buffer[APP_USBD_CONFIG_DESC_STRING_SIZE + 1];
|
||||
// + 1 element for string descriptor type and size
|
||||
#endif
|
||||
|
||||
uint8_t size = 0;
|
||||
const uint8_t * p_pos = m_string_dsc[idx][langid];
|
||||
|
||||
#if APP_USBD_CONFIG_DESC_STRING_UTF_ENABLED
|
||||
size = utf8UTF16Count((char *) p_pos, 0);
|
||||
ASSERT(size <= APP_USBD_CONFIG_DESC_STRING_SIZE);
|
||||
|
||||
uint16_t * p_out = &(string_buffer[1]);
|
||||
uint32_t rune;
|
||||
|
||||
while (*p_pos != 0)
|
||||
{
|
||||
p_pos = (uint8_t *) utf8DecodeRune((char *) p_pos, 0, &rune);
|
||||
p_out += utf16EncodeRune(rune, p_out);
|
||||
}
|
||||
#else
|
||||
while(*p_pos != 0)
|
||||
{
|
||||
ASSERT(size < APP_USBD_CONFIG_DESC_STRING_SIZE);
|
||||
++size;
|
||||
string_buffer[size] = *p_pos;
|
||||
++p_pos;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Descriptor size is length of the string times 2 bytes per character + 2 bytes for
|
||||
// descriptor type and size.
|
||||
string_buffer[0] = (0xff & (size * 2 + 2)) | ((uint16_t)APP_USBD_DESCRIPTOR_STRING) << 8;
|
||||
|
||||
return string_buffer;
|
||||
}
|
||||
|
||||
uint16_t const * app_usbd_string_desc_get(uint8_t idx, uint16_t langid)
|
||||
{
|
||||
/* LANGID string. */
|
||||
if (APP_USBD_STRING_ID_LANGIDS == idx)
|
||||
{
|
||||
return app_usbd_prepare_string(APP_USBD_STRING_ID_LANGIDS_ARRAY_POS, 0);
|
||||
}
|
||||
|
||||
/* Searching for the language. */
|
||||
uint8_t lang_idx = 0;
|
||||
if (ARRAY_SIZE(m_langids) > 1)
|
||||
{
|
||||
while (m_langids[lang_idx] != langid)
|
||||
{
|
||||
++lang_idx;
|
||||
if (lang_idx >= ARRAY_SIZE(m_langids))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the string index in array. */
|
||||
if (idx >= ARRAY_SIZE(m_string_translation))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t str_pos = m_string_translation[idx];
|
||||
if (str_pos == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((ARRAY_SIZE(m_langids) > 1) && (lang_idx != 0))
|
||||
{
|
||||
if (m_string_dsc[str_pos][lang_idx] == NULL)
|
||||
{
|
||||
lang_idx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_string_dsc[str_pos][lang_idx] == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return app_usbd_prepare_string(str_pos, lang_idx);
|
||||
}
|
||||
|
||||
/** @} */
|
||||
#endif // APP_USBD_ENABLED
|
||||
|
||||
+179
-179
@@ -1,179 +1,179 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_STRING_DESC_H__
|
||||
#define APP_USBD_STRING_DESC_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "sdk_common.h"
|
||||
#include "app_usbd.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_string_desc USBD string descriptors
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 USBD string descriptor management.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USB Language identifier initialization.
|
||||
*
|
||||
* @param[in] lang Language identifier.
|
||||
*/
|
||||
#define APP_USBD_LANG(lang) \
|
||||
((app_usbd_langid_t) lang)
|
||||
|
||||
/**
|
||||
* @brief USB Language identifier with sublanguage initialization.
|
||||
*
|
||||
* @param[in] lang Language identifier.
|
||||
* @param[in] sublang Sublanguage identifier.
|
||||
*/
|
||||
#define APP_USBD_LANG_AND_SUBLANG(lang, sublang) \
|
||||
((app_usbd_langid_t) lang | (app_usbd_langid_t) sublang)
|
||||
|
||||
/**
|
||||
* @brief USB string initialization.
|
||||
*
|
||||
* Macro that creates initialization values for the USB string.
|
||||
* The string must be declared as a NULL-terminated string.
|
||||
*
|
||||
* @param[in] str NULL-terminated string.
|
||||
*
|
||||
* @return String descriptor initialization data.
|
||||
*/
|
||||
#define APP_USBD_STRING_DESC(str) (const uint8_t *)(const char[]){str}
|
||||
|
||||
/**
|
||||
* @brief USB raw 8-bit string initialization.
|
||||
*
|
||||
* Macro that creates header for raw values passed into descriptor.
|
||||
* Values must be of the uint8_t type and separated by commas.
|
||||
*
|
||||
* @param[in] ... comma-separated values.
|
||||
*
|
||||
* @return String descriptor initialization data.
|
||||
*/
|
||||
#define APP_USBD_STRING_RAW8_DESC(...) (const uint8_t[]){ \
|
||||
0x00, 0x00, /* NULL character at start to differentiate from normal string */ \
|
||||
(0xff & (sizeof((uint8_t[]){__VA_ARGS__}) + 2)), \
|
||||
(APP_USBD_DESCRIPTOR_STRING), \
|
||||
__VA_ARGS__ }
|
||||
|
||||
/**
|
||||
* @brief USB raw 16-bit string initialization.
|
||||
*
|
||||
* Macro that creates header for raw values passed into descriptor.
|
||||
* Values must be of the uint16_t type and separated by commas.
|
||||
*
|
||||
* @param[in] ... comma-separated values.
|
||||
*
|
||||
* @return String descriptor initialization data.
|
||||
*/
|
||||
#define APP_USBD_STRING_RAW16_DESC(...) (const uint8_t *) ((const uint16_t[]){ \
|
||||
0x00, /* NULL character at start to differentiate from normal string */ \
|
||||
(0xff & (sizeof((uint16_t[]){__VA_ARGS__}) + 2)) | \
|
||||
((uint16_t)APP_USBD_DESCRIPTOR_STRING) << 8, \
|
||||
__VA_ARGS__ })
|
||||
|
||||
/**
|
||||
* @brief USB string descriptors IDs
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_STRING_ID_LANGIDS = 0, /**< Supported language identifiers */
|
||||
|
||||
/// Placeholders used only for alignement of user strings. Do not use or modify them.
|
||||
|
||||
#if (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
APP_USBD_STRING_ID_MANUFACTURER_PLACEHOLDER = APP_USBD_STRING_ID_MANUFACTURER,
|
||||
#endif // (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
APP_USBD_STRING_ID_PRODUCT_PLACEHOLDER = APP_USBD_STRING_ID_PRODUCT,
|
||||
#endif // (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
APP_USBD_STRING_ID_SERIAL_PLACEHOLDER = APP_USBD_STRING_ID_SERIAL,
|
||||
#endif // (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
APP_USBD_STRING_ID_CONFIGURATION_PLACEHOLDER = APP_USBD_STRING_ID_CONFIGURATION,
|
||||
#endif // (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
|
||||
#define X(mnemonic, str_idx, ...) mnemonic str_idx,
|
||||
APP_USBD_STRINGS_USER
|
||||
#undef X
|
||||
|
||||
APP_USBD_STRING_ID_CNT /**< Total number of identifiers. */
|
||||
} app_usbd_string_desc_idx_t;
|
||||
|
||||
/**
|
||||
* @brief Get string descriptor.
|
||||
*
|
||||
* @param[in] idx String descriptor index.
|
||||
* @param[in] langid Selected language for the string.
|
||||
* @return String descriptor, or NULL if it does not exist.
|
||||
* */
|
||||
uint16_t const * app_usbd_string_desc_get(uint8_t idx, uint16_t langid);
|
||||
|
||||
/**
|
||||
* @brief Get string length.
|
||||
*
|
||||
* Function for getting string length from descriptor (descriptor returned by @ref app_usbd_string_desc_get).
|
||||
*
|
||||
* @param[in] p_str String descriptor pointer.
|
||||
* @return Total descriptor length in bytes.
|
||||
*/
|
||||
static inline size_t app_usbd_string_desc_length(uint16_t const * p_str)
|
||||
{
|
||||
return ((const app_usbd_descriptor_string_t *)p_str)->bLength;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_STRING_DESC_H__ */
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_STRING_DESC_H__
|
||||
#define APP_USBD_STRING_DESC_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "sdk_common.h"
|
||||
#include "app_usbd.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_string_desc USBD string descriptors
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 USBD string descriptor management.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USB Language identifier initialization.
|
||||
*
|
||||
* @param[in] lang Language identifier.
|
||||
*/
|
||||
#define APP_USBD_LANG(lang) \
|
||||
((app_usbd_langid_t) lang)
|
||||
|
||||
/**
|
||||
* @brief USB Language identifier with sublanguage initialization.
|
||||
*
|
||||
* @param[in] lang Language identifier.
|
||||
* @param[in] sublang Sublanguage identifier.
|
||||
*/
|
||||
#define APP_USBD_LANG_AND_SUBLANG(lang, sublang) \
|
||||
((app_usbd_langid_t) lang | (app_usbd_langid_t) sublang)
|
||||
|
||||
/**
|
||||
* @brief USB string initialization.
|
||||
*
|
||||
* Macro that creates initialization values for the USB string.
|
||||
* The string must be declared as a NULL-terminated string.
|
||||
*
|
||||
* @param[in] str NULL-terminated string.
|
||||
*
|
||||
* @return String descriptor initialization data.
|
||||
*/
|
||||
#define APP_USBD_STRING_DESC(str) (const uint8_t *)(const char[]){str}
|
||||
|
||||
/**
|
||||
* @brief USB raw 8-bit string initialization.
|
||||
*
|
||||
* Macro that creates header for raw values passed into descriptor.
|
||||
* Values must be of the uint8_t type and separated by commas.
|
||||
*
|
||||
* @param[in] ... comma-separated values.
|
||||
*
|
||||
* @return String descriptor initialization data.
|
||||
*/
|
||||
#define APP_USBD_STRING_RAW8_DESC(...) (const uint8_t[]){ \
|
||||
0x00, 0x00, /* NULL character at start to differentiate from normal string */ \
|
||||
(0xff & (sizeof((uint8_t[]){__VA_ARGS__}) + 2)), \
|
||||
(APP_USBD_DESCRIPTOR_STRING), \
|
||||
__VA_ARGS__ }
|
||||
|
||||
/**
|
||||
* @brief USB raw 16-bit string initialization.
|
||||
*
|
||||
* Macro that creates header for raw values passed into descriptor.
|
||||
* Values must be of the uint16_t type and separated by commas.
|
||||
*
|
||||
* @param[in] ... comma-separated values.
|
||||
*
|
||||
* @return String descriptor initialization data.
|
||||
*/
|
||||
#define APP_USBD_STRING_RAW16_DESC(...) (const uint8_t *) ((const uint16_t[]){ \
|
||||
0x00, /* NULL character at start to differentiate from normal string */ \
|
||||
(0xff & (sizeof((uint16_t[]){__VA_ARGS__}) + 2)) | \
|
||||
((uint16_t)APP_USBD_DESCRIPTOR_STRING) << 8, \
|
||||
__VA_ARGS__ })
|
||||
|
||||
/**
|
||||
* @brief USB string descriptors IDs
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_STRING_ID_LANGIDS = 0, /**< Supported language identifiers */
|
||||
|
||||
/// Placeholders used only for alignement of user strings. Do not use or modify them.
|
||||
|
||||
#if (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
APP_USBD_STRING_ID_MANUFACTURER_PLACEHOLDER = APP_USBD_STRING_ID_MANUFACTURER,
|
||||
#endif // (APP_USBD_STRING_ID_MANUFACTURER != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
APP_USBD_STRING_ID_PRODUCT_PLACEHOLDER = APP_USBD_STRING_ID_PRODUCT,
|
||||
#endif // (APP_USBD_STRING_ID_PRODUCT != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
APP_USBD_STRING_ID_SERIAL_PLACEHOLDER = APP_USBD_STRING_ID_SERIAL,
|
||||
#endif // (APP_USBD_STRING_ID_SERIAL != 0)
|
||||
|
||||
#if (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
APP_USBD_STRING_ID_CONFIGURATION_PLACEHOLDER = APP_USBD_STRING_ID_CONFIGURATION,
|
||||
#endif // (APP_USBD_STRING_ID_CONFIGURATION != 0)
|
||||
|
||||
#define X(mnemonic, str_idx, ...) mnemonic str_idx,
|
||||
APP_USBD_STRINGS_USER
|
||||
#undef X
|
||||
|
||||
APP_USBD_STRING_ID_CNT /**< Total number of identifiers. */
|
||||
} app_usbd_string_desc_idx_t;
|
||||
|
||||
/**
|
||||
* @brief Get string descriptor.
|
||||
*
|
||||
* @param[in] idx String descriptor index.
|
||||
* @param[in] langid Selected language for the string.
|
||||
* @return String descriptor, or NULL if it does not exist.
|
||||
* */
|
||||
uint16_t const * app_usbd_string_desc_get(uint8_t idx, uint16_t langid);
|
||||
|
||||
/**
|
||||
* @brief Get string length.
|
||||
*
|
||||
* Function for getting string length from descriptor (descriptor returned by @ref app_usbd_string_desc_get).
|
||||
*
|
||||
* @param[in] p_str String descriptor pointer.
|
||||
* @return Total descriptor length in bytes.
|
||||
*/
|
||||
static inline size_t app_usbd_string_desc_length(uint16_t const * p_str)
|
||||
{
|
||||
return ((const app_usbd_descriptor_string_t *)p_str)->bLength;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_STRING_DESC_H__ */
|
||||
|
||||
+278
-278
@@ -1,278 +1,278 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_TYPES_H__
|
||||
#define APP_USBD_TYPES_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "sdk_errors.h"
|
||||
#include "nrf_drv_usbd.h"
|
||||
#include "app_usbd_request.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_types USB Device high level library variable types definition
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 All types used by @ref app_usbd are defined here.
|
||||
* This helps to avoid cross referencing into types in different files.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Change given value to 2 digits in BCD notation.
|
||||
*
|
||||
* @param[in] val The decimal value to be converted in the range from 0 to 99.
|
||||
* @return Calculated BCD value.
|
||||
*/
|
||||
#define APP_USBD_BCD_2_MAKE(val) ( \
|
||||
((((val) % 100) / 10) * 0x10) + \
|
||||
((((val) % 10) / 1) * 0x1) \
|
||||
)
|
||||
|
||||
/**
|
||||
* @brief Change given decimal version values to 4 digits in BCD notation.
|
||||
*
|
||||
* USB specification uses 4 digits BCD version notation in many descriptors.
|
||||
* This macro changes 2 values to 4 BCD digits (one 16 bit value)
|
||||
* that describes version in USB standard.
|
||||
*
|
||||
* @param[in] major Major version.
|
||||
* @param[in] minor Minor version.
|
||||
*
|
||||
* @return Calculated 16 bit value with BCD representation of the version.
|
||||
*/
|
||||
#define APP_USBD_BCD_VER_MAKE(major, minor) \
|
||||
((APP_USBD_BCD_2_MAKE(major) << 8) | APP_USBD_BCD_2_MAKE(minor))
|
||||
|
||||
/**
|
||||
* @brief Combine endpoint address and its interval.
|
||||
*
|
||||
* @param[in] address Endpoint address
|
||||
* @param[in] interval Endpoint interval
|
||||
* @return Combined address and interval.
|
||||
*/
|
||||
#define APP_USBD_EP_WITH_INTERVAL(address, interval) \
|
||||
((1UL << 16) | ((interval) << 8) | (address))
|
||||
|
||||
#define APP_USBD_EXTRACT_INTERVAL_VALUE(combined) \
|
||||
(((combined) & 0xFF00) >> 8)
|
||||
|
||||
#define APP_USBD_EXTRACT_INTERVAL_FLAG(combined) \
|
||||
(((combined) >> 16) & 0x01)
|
||||
|
||||
/**
|
||||
* @brief Events codes.
|
||||
*
|
||||
* Redefined application event codes.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
APP_USBD_EVT_DRV_SOF = NRF_DRV_USBD_EVT_SOF, /**< See documentation for @ref NRF_DRV_USBD_EVT_SOF */
|
||||
APP_USBD_EVT_DRV_RESET = NRF_DRV_USBD_EVT_RESET, /**< See documentation for @ref NRF_DRV_USBD_EVT_RESET */
|
||||
APP_USBD_EVT_DRV_SUSPEND = NRF_DRV_USBD_EVT_SUSPEND, /**< See documentation for @ref NRF_DRV_USBD_EVT_SUSPEND */
|
||||
APP_USBD_EVT_DRV_RESUME = NRF_DRV_USBD_EVT_RESUME, /**< See documentation for @ref NRF_DRV_USBD_EVT_RESUME */
|
||||
APP_USBD_EVT_DRV_WUREQ = NRF_DRV_USBD_EVT_WUREQ, /**< See documentation for @ref NRF_DRV_USBD_EVT_WUREQ */
|
||||
APP_USBD_EVT_DRV_SETUP = NRF_DRV_USBD_EVT_SETUP, /**< This event type has special structure. See @ref app_usbd_setup_evt_t */
|
||||
APP_USBD_EVT_DRV_EPTRANSFER = NRF_DRV_USBD_EVT_EPTRANSFER, /**< See documentation for @ref NRF_DRV_USBD_EVT_EPTRANSFER */
|
||||
|
||||
APP_USBD_EVT_FIRST_POWER, /**< First power event code - for internal static assert checking */
|
||||
|
||||
APP_USBD_EVT_POWER_DETECTED, /**< See documentation for @ref NRF_DRV_POWER_USB_EVT_DETECTED */
|
||||
APP_USBD_EVT_POWER_REMOVED, /**< See documentation for @ref NRF_DRV_POWER_USB_EVT_REMOVED */
|
||||
APP_USBD_EVT_POWER_READY, /**< See documentation for @ref NRF_DRV_POWER_USB_EVT_READY */
|
||||
|
||||
|
||||
APP_USBD_EVT_FIRST_APP, /**< First application event code - for internal static assert checking */
|
||||
|
||||
APP_USBD_EVT_INST_APPEND = APP_USBD_EVT_FIRST_APP, /**< The instance was attached to the library, any configuration action can be done now */
|
||||
APP_USBD_EVT_INST_REMOVE, /**<
|
||||
* The instance is going to be removed, this event is called just before removing the instance.
|
||||
* This removing cannot be stopped.
|
||||
*/
|
||||
APP_USBD_EVT_STARTED, /**< USBD library has just been started and functional - event passed to all instances, before USBD interrupts have been enabled */
|
||||
APP_USBD_EVT_STOPPED, /**< USBD library has just been stopped and is not functional - event passed to all instances, after USBD interrupts have been disabled*/
|
||||
|
||||
APP_USBD_EVT_STATE_CHANGED, /**<
|
||||
* Informs all the classes that base state has been changed.
|
||||
* This event is processed before setup stage that caused the state change finishes (before acknowledging it).
|
||||
*/
|
||||
|
||||
APP_USBD_EVT_FIRST_INTERNAL = 0x80, /**< First internal event, used by the APP library internally. */
|
||||
|
||||
APP_USBD_EVT_HFCLK_READY = APP_USBD_EVT_FIRST_INTERNAL, /**< High frequency clock started */
|
||||
APP_USBD_EVT_START_REQ, /**< Start requested */
|
||||
APP_USBD_EVT_STOP_REQ, /**< Stop requested */
|
||||
APP_USBD_EVT_SUSPEND_REQ, /**< Suspend request - HFCLK would be released and USBD peripheral clock would be disconnected */
|
||||
APP_USBD_EVT_WAKEUP_REQ, /**< Wakeup request - start the whole wakeup generation. */
|
||||
APP_USBD_EVT_SETUP_SETADDRESS, /**<
|
||||
* Setup request to set address, separated from
|
||||
* regular EVT_SETUP because this request is
|
||||
* fully handled by hardware and for the software
|
||||
* it is only a notification about what happened
|
||||
*/
|
||||
|
||||
} app_usbd_event_type_t;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Specific application event structure.
|
||||
*
|
||||
* All the data required by the events that comes from the application level.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
app_usbd_event_type_t type; //!< Event type
|
||||
} app_usbd_evt_t;
|
||||
|
||||
/**
|
||||
* @brief Specific application event structure with setup structure included.
|
||||
*
|
||||
* This event structure would be used when @ref APP_USBD_EVT_DRV_SETUP
|
||||
* is passed to instance event handler.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
app_usbd_event_type_t type; //!< Event type
|
||||
app_usbd_setup_t setup; //!< Setup structure
|
||||
} app_usbd_setup_evt_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Complex event variable type.
|
||||
*
|
||||
* A variable that can store any kind of event.
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
app_usbd_event_type_t type; //!< Event type
|
||||
nrf_drv_usbd_evt_t drv_evt; //!< Events that comes directly from the driver.
|
||||
/**< Use this event structure only for event
|
||||
* type < @ref APP_USBD_EVT_FIRST_APP
|
||||
*/
|
||||
app_usbd_setup_evt_t setup_evt; //!< Event structure with SETUP structure included.
|
||||
/**< This structure is used in connection with
|
||||
* @ref APP_USBD_EVT_DRV_SETUP
|
||||
*/
|
||||
app_usbd_evt_t app_evt; //!< Events that comes from the application driver.
|
||||
/**< Use this event structure only for event
|
||||
* type >= @ref APP_USBD_EVT_FIRST_APP
|
||||
*/
|
||||
} app_usbd_complex_evt_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Internal event variable type.
|
||||
*
|
||||
* The variable type used for internal event processing.
|
||||
* This kind of event is the one that goes into the event queue.
|
||||
*
|
||||
* @note There is no setup event structure.
|
||||
* This structure would be created when setup event is processed.
|
||||
* The reason for that is the fact that setup event structure has high memory printout.
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
app_usbd_event_type_t type; //!< Event type
|
||||
nrf_drv_usbd_evt_t drv_evt; //!< Events that comes directly from the driver.
|
||||
/**< Use this event structure only for event
|
||||
* type < @ref APP_USBD_EVT_FIRST_APP
|
||||
*/
|
||||
app_usbd_evt_t app_evt; //!< Events that comes from the application driver.
|
||||
/**< Use this event structure only for event
|
||||
* type >= @ref APP_USBD_EVT_FIRST_APP
|
||||
*/
|
||||
} app_usbd_internal_evt_t;
|
||||
|
||||
|
||||
#ifdef DOXYGEN
|
||||
/**
|
||||
* @brief Base instance of a USBD class.
|
||||
*
|
||||
* Any USBD class instance have to begin with this instance.
|
||||
* This may then be followed by any implementation dependent data.
|
||||
*
|
||||
* For an instance it should be possible to put whole structure into FLASH.
|
||||
*
|
||||
* @note This type is early defined as incomplete type.
|
||||
* This is required for function declaration that takes the pointer
|
||||
* to this structure but in second hand - it is also placed inside
|
||||
* the instance structure.
|
||||
* @note The structure is defined in @file app_usbd_class_base.h.
|
||||
*/
|
||||
typedef struct {} app_usbd_class_inst_t;
|
||||
#else
|
||||
typedef struct app_usbd_class_inst_s app_usbd_class_inst_t;
|
||||
#endif
|
||||
/**
|
||||
* @brief Endpoint callback function.
|
||||
*
|
||||
* The function used by every class instance.
|
||||
* @param[in,out] p_inst Instance of the class.
|
||||
* @param[in] p_event Event to process.
|
||||
*
|
||||
* @note If given event is not supported by class, return @ref NRF_ERROR_NOT_SUPPORTED
|
||||
*/
|
||||
typedef ret_code_t (*app_usbd_ep_event_handler_t)(
|
||||
app_usbd_class_inst_t const * const p_inst,
|
||||
app_usbd_complex_evt_t const * const p_event
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief SOF interrupt callback function.
|
||||
*
|
||||
* @param[in] framecnt Number of current SOF frame.
|
||||
*
|
||||
* @sa app_usbd_class_sof_register
|
||||
*/
|
||||
typedef void (*app_usbd_sof_interrupt_handler_t)(uint16_t framecnt);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_TYPES_H__ */
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef APP_USBD_TYPES_H__
|
||||
#define APP_USBD_TYPES_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "sdk_errors.h"
|
||||
#include "nrf_drv_usbd.h"
|
||||
#include "app_usbd_request.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_types USB Device high level library variable types definition
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 All types used by @ref app_usbd are defined here.
|
||||
* This helps to avoid cross referencing into types in different files.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Change given value to 2 digits in BCD notation.
|
||||
*
|
||||
* @param[in] val The decimal value to be converted in the range from 0 to 99.
|
||||
* @return Calculated BCD value.
|
||||
*/
|
||||
#define APP_USBD_BCD_2_MAKE(val) ( \
|
||||
((((val) % 100) / 10) * 0x10) + \
|
||||
((((val) % 10) / 1) * 0x1) \
|
||||
)
|
||||
|
||||
/**
|
||||
* @brief Change given decimal version values to 4 digits in BCD notation.
|
||||
*
|
||||
* USB specification uses 4 digits BCD version notation in many descriptors.
|
||||
* This macro changes 2 values to 4 BCD digits (one 16 bit value)
|
||||
* that describes version in USB standard.
|
||||
*
|
||||
* @param[in] major Major version.
|
||||
* @param[in] minor Minor version.
|
||||
*
|
||||
* @return Calculated 16 bit value with BCD representation of the version.
|
||||
*/
|
||||
#define APP_USBD_BCD_VER_MAKE(major, minor) \
|
||||
((APP_USBD_BCD_2_MAKE(major) << 8) | APP_USBD_BCD_2_MAKE(minor))
|
||||
|
||||
/**
|
||||
* @brief Combine endpoint address and its interval.
|
||||
*
|
||||
* @param[in] address Endpoint address
|
||||
* @param[in] interval Endpoint interval
|
||||
* @return Combined address and interval.
|
||||
*/
|
||||
#define APP_USBD_EP_WITH_INTERVAL(address, interval) \
|
||||
((1UL << 16) | ((interval) << 8) | (address))
|
||||
|
||||
#define APP_USBD_EXTRACT_INTERVAL_VALUE(combined) \
|
||||
(((combined) & 0xFF00) >> 8)
|
||||
|
||||
#define APP_USBD_EXTRACT_INTERVAL_FLAG(combined) \
|
||||
(((combined) >> 16) & 0x01)
|
||||
|
||||
/**
|
||||
* @brief Events codes.
|
||||
*
|
||||
* Redefined application event codes.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
APP_USBD_EVT_DRV_SOF = NRF_DRV_USBD_EVT_SOF, /**< See documentation for @ref NRF_DRV_USBD_EVT_SOF */
|
||||
APP_USBD_EVT_DRV_RESET = NRF_DRV_USBD_EVT_RESET, /**< See documentation for @ref NRF_DRV_USBD_EVT_RESET */
|
||||
APP_USBD_EVT_DRV_SUSPEND = NRF_DRV_USBD_EVT_SUSPEND, /**< See documentation for @ref NRF_DRV_USBD_EVT_SUSPEND */
|
||||
APP_USBD_EVT_DRV_RESUME = NRF_DRV_USBD_EVT_RESUME, /**< See documentation for @ref NRF_DRV_USBD_EVT_RESUME */
|
||||
APP_USBD_EVT_DRV_WUREQ = NRF_DRV_USBD_EVT_WUREQ, /**< See documentation for @ref NRF_DRV_USBD_EVT_WUREQ */
|
||||
APP_USBD_EVT_DRV_SETUP = NRF_DRV_USBD_EVT_SETUP, /**< This event type has special structure. See @ref app_usbd_setup_evt_t */
|
||||
APP_USBD_EVT_DRV_EPTRANSFER = NRF_DRV_USBD_EVT_EPTRANSFER, /**< See documentation for @ref NRF_DRV_USBD_EVT_EPTRANSFER */
|
||||
|
||||
APP_USBD_EVT_FIRST_POWER, /**< First power event code - for internal static assert checking */
|
||||
|
||||
APP_USBD_EVT_POWER_DETECTED, /**< See documentation for @ref NRF_DRV_POWER_USB_EVT_DETECTED */
|
||||
APP_USBD_EVT_POWER_REMOVED, /**< See documentation for @ref NRF_DRV_POWER_USB_EVT_REMOVED */
|
||||
APP_USBD_EVT_POWER_READY, /**< See documentation for @ref NRF_DRV_POWER_USB_EVT_READY */
|
||||
|
||||
|
||||
APP_USBD_EVT_FIRST_APP, /**< First application event code - for internal static assert checking */
|
||||
|
||||
APP_USBD_EVT_INST_APPEND = APP_USBD_EVT_FIRST_APP, /**< The instance was attached to the library, any configuration action can be done now */
|
||||
APP_USBD_EVT_INST_REMOVE, /**<
|
||||
* The instance is going to be removed, this event is called just before removing the instance.
|
||||
* This removing cannot be stopped.
|
||||
*/
|
||||
APP_USBD_EVT_STARTED, /**< USBD library has just been started and functional - event passed to all instances, before USBD interrupts have been enabled */
|
||||
APP_USBD_EVT_STOPPED, /**< USBD library has just been stopped and is not functional - event passed to all instances, after USBD interrupts have been disabled*/
|
||||
|
||||
APP_USBD_EVT_STATE_CHANGED, /**<
|
||||
* Informs all the classes that base state has been changed.
|
||||
* This event is processed before setup stage that caused the state change finishes (before acknowledging it).
|
||||
*/
|
||||
|
||||
APP_USBD_EVT_FIRST_INTERNAL = 0x80, /**< First internal event, used by the APP library internally. */
|
||||
|
||||
APP_USBD_EVT_HFCLK_READY = APP_USBD_EVT_FIRST_INTERNAL, /**< High frequency clock started */
|
||||
APP_USBD_EVT_START_REQ, /**< Start requested */
|
||||
APP_USBD_EVT_STOP_REQ, /**< Stop requested */
|
||||
APP_USBD_EVT_SUSPEND_REQ, /**< Suspend request - HFCLK would be released and USBD peripheral clock would be disconnected */
|
||||
APP_USBD_EVT_WAKEUP_REQ, /**< Wakeup request - start the whole wakeup generation. */
|
||||
APP_USBD_EVT_SETUP_SETADDRESS, /**<
|
||||
* Setup request to set address, separated from
|
||||
* regular EVT_SETUP because this request is
|
||||
* fully handled by hardware and for the software
|
||||
* it is only a notification about what happened
|
||||
*/
|
||||
|
||||
} app_usbd_event_type_t;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Specific application event structure.
|
||||
*
|
||||
* All the data required by the events that comes from the application level.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
app_usbd_event_type_t type; //!< Event type
|
||||
} app_usbd_evt_t;
|
||||
|
||||
/**
|
||||
* @brief Specific application event structure with setup structure included.
|
||||
*
|
||||
* This event structure would be used when @ref APP_USBD_EVT_DRV_SETUP
|
||||
* is passed to instance event handler.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
app_usbd_event_type_t type; //!< Event type
|
||||
app_usbd_setup_t setup; //!< Setup structure
|
||||
} app_usbd_setup_evt_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Complex event variable type.
|
||||
*
|
||||
* A variable that can store any kind of event.
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
app_usbd_event_type_t type; //!< Event type
|
||||
nrf_drv_usbd_evt_t drv_evt; //!< Events that comes directly from the driver.
|
||||
/**< Use this event structure only for event
|
||||
* type < @ref APP_USBD_EVT_FIRST_APP
|
||||
*/
|
||||
app_usbd_setup_evt_t setup_evt; //!< Event structure with SETUP structure included.
|
||||
/**< This structure is used in connection with
|
||||
* @ref APP_USBD_EVT_DRV_SETUP
|
||||
*/
|
||||
app_usbd_evt_t app_evt; //!< Events that comes from the application driver.
|
||||
/**< Use this event structure only for event
|
||||
* type >= @ref APP_USBD_EVT_FIRST_APP
|
||||
*/
|
||||
} app_usbd_complex_evt_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Internal event variable type.
|
||||
*
|
||||
* The variable type used for internal event processing.
|
||||
* This kind of event is the one that goes into the event queue.
|
||||
*
|
||||
* @note There is no setup event structure.
|
||||
* This structure would be created when setup event is processed.
|
||||
* The reason for that is the fact that setup event structure has high memory printout.
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
app_usbd_event_type_t type; //!< Event type
|
||||
nrf_drv_usbd_evt_t drv_evt; //!< Events that comes directly from the driver.
|
||||
/**< Use this event structure only for event
|
||||
* type < @ref APP_USBD_EVT_FIRST_APP
|
||||
*/
|
||||
app_usbd_evt_t app_evt; //!< Events that comes from the application driver.
|
||||
/**< Use this event structure only for event
|
||||
* type >= @ref APP_USBD_EVT_FIRST_APP
|
||||
*/
|
||||
} app_usbd_internal_evt_t;
|
||||
|
||||
|
||||
#ifdef DOXYGEN
|
||||
/**
|
||||
* @brief Base instance of a USBD class.
|
||||
*
|
||||
* Any USBD class instance have to begin with this instance.
|
||||
* This may then be followed by any implementation dependent data.
|
||||
*
|
||||
* For an instance it should be possible to put whole structure into FLASH.
|
||||
*
|
||||
* @note This type is early defined as incomplete type.
|
||||
* This is required for function declaration that takes the pointer
|
||||
* to this structure but in second hand - it is also placed inside
|
||||
* the instance structure.
|
||||
* @note The structure is defined in @file app_usbd_class_base.h.
|
||||
*/
|
||||
typedef struct {} app_usbd_class_inst_t;
|
||||
#else
|
||||
typedef struct app_usbd_class_inst_s app_usbd_class_inst_t;
|
||||
#endif
|
||||
/**
|
||||
* @brief Endpoint callback function.
|
||||
*
|
||||
* The function used by every class instance.
|
||||
* @param[in,out] p_inst Instance of the class.
|
||||
* @param[in] p_event Event to process.
|
||||
*
|
||||
* @note If given event is not supported by class, return @ref NRF_ERROR_NOT_SUPPORTED
|
||||
*/
|
||||
typedef ret_code_t (*app_usbd_ep_event_handler_t)(
|
||||
app_usbd_class_inst_t const * const p_inst,
|
||||
app_usbd_complex_evt_t const * const p_event
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief SOF interrupt callback function.
|
||||
*
|
||||
* @param[in] framecnt Number of current SOF frame.
|
||||
*
|
||||
* @sa app_usbd_class_sof_register
|
||||
*/
|
||||
typedef void (*app_usbd_sof_interrupt_handler_t)(uint16_t framecnt);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_TYPES_H__ */
|
||||
|
||||
+1199
-1199
File diff suppressed because it is too large
Load Diff
+362
-362
@@ -1,362 +1,362 @@
|
||||
/**
|
||||
* Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_CDC_ACM_H__
|
||||
#define APP_USBD_CDC_ACM_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nrf_drv_usbd.h"
|
||||
#include "app_usbd_class_base.h"
|
||||
#include "app_usbd.h"
|
||||
#include "app_usbd_core.h"
|
||||
#include "app_usbd_descriptor.h"
|
||||
|
||||
#include "app_usbd_cdc_desc.h"
|
||||
#include "app_usbd_cdc_types.h"
|
||||
#include "app_usbd_cdc_acm_internal.h"
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_cdc_acm USB CDC ACM class
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 Module with types, definitions and API used by CDC ACM class.
|
||||
*
|
||||
* @details References:
|
||||
* - "Universal Serial Bus Class Definitions for Communications Devices"
|
||||
* Revision 1.2, November 3, 2010
|
||||
* - "Universal Serial Bus Communications Class Subclass Specification for PSTN Devices"
|
||||
* Revision 1.2, February 9, 2007
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef DOXYGEN
|
||||
/**
|
||||
* @brief CDC ACM class instance type.
|
||||
*
|
||||
* @ref APP_USBD_CLASS_TYPEDEF
|
||||
*/
|
||||
typedef struct { } app_usbd_cdc_acm_t;
|
||||
#else
|
||||
/*lint -save -e10 -e26 -e123 -e505 */
|
||||
APP_USBD_CLASS_TYPEDEF(app_usbd_cdc_acm, \
|
||||
APP_USBD_CDC_ACM_CONFIG(0, 0, 0, 0, 0), \
|
||||
APP_USBD_CDC_ACM_INSTANCE_SPECIFIC_DEC, \
|
||||
APP_USBD_CDC_ACM_DATA_SPECIFIC_DEC \
|
||||
);
|
||||
/*lint -restore*/
|
||||
#endif
|
||||
|
||||
|
||||
/*lint -save -e407 */
|
||||
|
||||
/**
|
||||
* @brief Events passed to user event handler.
|
||||
*
|
||||
* @note Example prototype of user event handler:
|
||||
*
|
||||
* @code
|
||||
void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst,
|
||||
app_usbd_cdc_acm_user_event_t event);
|
||||
* @endcode
|
||||
*/
|
||||
typedef enum app_usbd_cdc_acm_user_event_e {
|
||||
APP_USBD_CDC_ACM_USER_EVT_RX_DONE, /**< User event RX_DONE. */
|
||||
APP_USBD_CDC_ACM_USER_EVT_TX_DONE, /**< User event TX_DONE. */
|
||||
|
||||
APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN, /**< User event PORT_OPEN. */
|
||||
APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE, /**< User event PORT_CLOSE. */
|
||||
} app_usbd_cdc_acm_user_event_t;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/**
|
||||
* @brief Default CDC ACM descriptors.
|
||||
*
|
||||
* @param comm_interface COMM interface number.
|
||||
* @param comm_epin COMM interface IN endpoint.
|
||||
* @param data_interface DATA interface number.
|
||||
* @param data_epin DATA interface IN endpoint.
|
||||
* @param data_epout DATA interface OUT endpoint.
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_DEFAULT_DESC(comm_interface, \
|
||||
comm_epin, \
|
||||
data_interface, \
|
||||
data_epin, \
|
||||
data_epout) \
|
||||
APP_USBD_CDC_IAD_DSC(comm_interface, \
|
||||
APP_USBD_CDC_SUBCLASS_ACM, \
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_V250) \
|
||||
APP_USBD_CDC_COMM_INTERFACE_DSC(comm_interface, \
|
||||
APP_USBD_CDC_SUBCLASS_ACM, \
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_V250) \
|
||||
APP_USBD_CDC_HEADER_DSC(0x0110) \
|
||||
APP_USBD_CDC_CALL_MGMT_DSC(0x03, data_interface) \
|
||||
APP_USBD_CDC_ACM_DSC(0x02) \
|
||||
APP_USBD_CDC_UNION_DSC(comm_interface, data_interface) \
|
||||
APP_USBD_CDC_COM_EP_DSC(comm_epin, NRF_DRV_USBD_EPSIZE) \
|
||||
APP_USBD_CDC_DATA_INTERFACE_DSC(data_interface, 0, 0) \
|
||||
APP_USBD_CDC_DATA_EP_DSC(data_epin, data_epout, NRF_DRV_USBD_EPSIZE)
|
||||
|
||||
/**
|
||||
* @brief Global definition of app_usbd_cdc_acm_t class instance.
|
||||
*
|
||||
* @param instance_name Name of global instance.
|
||||
* @param user_ev_handler User event handler (optional).
|
||||
* @param comm_ifc Interface number of cdc_acm control.
|
||||
* @param data_ifc Interface number of cdc_acm DATA.
|
||||
* @param comm_ein COMM subclass IN endpoint.
|
||||
* @param data_ein DATA subclass IN endpoint.
|
||||
* @param data_eout DATA subclass OUT endpoint.
|
||||
* @param cdc_protocol CDC protocol @ref app_usbd_cdc_comm_protocol_t
|
||||
*
|
||||
* @note This macro is just simplified version of @ref APP_USBD_CDC_ACM_GLOBAL_DEF_INTERNAL.
|
||||
*
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_GLOBAL_DEF(instance_name, \
|
||||
user_ev_handler, \
|
||||
comm_ifc, \
|
||||
data_ifc, \
|
||||
comm_ein, \
|
||||
data_ein, \
|
||||
data_eout, \
|
||||
cdc_protocol) \
|
||||
APP_USBD_CDC_ACM_GLOBAL_DEF_INTERNAL(instance_name, \
|
||||
user_ev_handler, \
|
||||
comm_ifc, \
|
||||
data_ifc, \
|
||||
comm_ein, \
|
||||
data_ein, \
|
||||
data_eout, \
|
||||
cdc_protocol) \
|
||||
|
||||
/**
|
||||
* @brief Helper function to get class instance from CDC ACM class.
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
*
|
||||
* @return Base class instance.
|
||||
*/
|
||||
static inline app_usbd_class_inst_t const *
|
||||
app_usbd_cdc_acm_class_inst_get(app_usbd_cdc_acm_t const * p_cdc_acm)
|
||||
{
|
||||
return &p_cdc_acm->base;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Helper function to get cdc_acm specific request from cdc_acm class.
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
*
|
||||
* @return CDC ACM class specific request.
|
||||
*/
|
||||
static inline app_usbd_cdc_acm_req_t *
|
||||
app_usbd_cdc_acm_class_request_get(app_usbd_cdc_acm_t const * p_cdc_acm)
|
||||
{
|
||||
return &p_cdc_acm->specific.p_data->ctx.request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Helper function to get cdc_acm from base class instance.
|
||||
*
|
||||
* @param[in] p_inst Base class instance.
|
||||
*
|
||||
* @return CDC ACM class handle.
|
||||
*/
|
||||
static inline app_usbd_cdc_acm_t const *
|
||||
app_usbd_cdc_acm_class_get(app_usbd_class_inst_t const * p_inst)
|
||||
{
|
||||
return (app_usbd_cdc_acm_t const *)p_inst;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Writes data to CDC ACM serial port.
|
||||
*
|
||||
* This is asynchronous call. User should wait for @ref APP_USBD_CDC_ACM_USER_EVT_TX_DONE event
|
||||
* to be sure that all data has been sent and input buffer could be accessed again.
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
* @param[in] p_buf Input buffer.
|
||||
* @param[in] length Input buffer length.
|
||||
*
|
||||
* @return Standard error code.
|
||||
*/
|
||||
ret_code_t app_usbd_cdc_acm_write(app_usbd_cdc_acm_t const * p_cdc_acm,
|
||||
const void * p_buf,
|
||||
size_t length);
|
||||
|
||||
/**
|
||||
* @brief Returns the amount of data that was read.
|
||||
*
|
||||
* This function should be used on @ref APP_USBD_CDC_ACM_USER_EVT_RX_DONE event to get
|
||||
* information how many bytes have been transfered into user buffer.
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
*
|
||||
* @return Amount of data transfered.
|
||||
*/
|
||||
size_t app_usbd_cdc_acm_rx_size(app_usbd_cdc_acm_t const * p_cdc_acm);
|
||||
|
||||
/**
|
||||
* @brief Returns the amount of data that was stored into internal buffer
|
||||
*
|
||||
* This function should be used on @ref APP_USBD_CDC_ACM_USER_EVT_RX_DONE event to get
|
||||
* information how many bytes are waiting in internal buffer.
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
*
|
||||
* @return Amount of data waiting.
|
||||
*/
|
||||
size_t app_usbd_cdc_acm_bytes_stored(app_usbd_cdc_acm_t const * p_cdc_acm);
|
||||
|
||||
/**
|
||||
* @brief Reads data from CDC ACM serial port.
|
||||
*
|
||||
* This function uses internal buffer and double buffering for continuous transmission.
|
||||
*
|
||||
* If there is enough data in internal buffer to fill user buffer, NRF_SUCCESS is
|
||||
* returned and data is immediately available in the user buffer.
|
||||
*
|
||||
* If not, up to two user buffers can be scheduled, function returns NRF_ERROR_IO_PENDING
|
||||
* when first buffer is filled and @ref APP_USBD_CDC_ACM_USER_EVT_RX_DONE event is generated.
|
||||
*
|
||||
* @sa app_usbd_cdc_acm_read_any
|
||||
* @sa app_usbd_cdc_acm_rx_size
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
* @param[out] p_buf Output buffer.
|
||||
* @param[in] length Number of bytes to read.
|
||||
*
|
||||
* @retval NRF_SUCCESS Data is stored into user buffer.
|
||||
* @retval NRF_ERROR_IO_PENDING Awaiting transmission, when data is stored into user buffer,
|
||||
* @ref APP_USBD_CDC_ACM_USER_EVT_RX_DONE event will be raised.
|
||||
* @retval NRF_ERROR_BUSY There are already 2 buffers queued for transfers.
|
||||
* @retval other Standard error code.
|
||||
*/
|
||||
ret_code_t app_usbd_cdc_acm_read(app_usbd_cdc_acm_t const * p_cdc_acm,
|
||||
void * p_buf,
|
||||
size_t length);
|
||||
|
||||
/**
|
||||
* @brief Read any data from CDC ACM port up to given buffer size
|
||||
*
|
||||
* This function is very similar to the @ref app_usbd_cdc_acm_read but it returns
|
||||
* data as quick as any data is available, even if the given buffer was not totally full.
|
||||
*
|
||||
* @note This function cannot use double buffering.
|
||||
* @note To check the number of bytes really read use @ref app_usbd_cdc_acm_rx_size
|
||||
* function.
|
||||
*
|
||||
* @sa app_usbd_cdc_acm_read
|
||||
* @sa app_usbd_cdc_acm_rx_size
|
||||
*
|
||||
* @param p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
* @param[out] p_buf Output buffer.
|
||||
* @param[in] length Maximum number of bytes to read.
|
||||
*
|
||||
* @retval NRF_SUCCESS Data is stored into user buffer.
|
||||
* @retval NRF_ERROR_IO_PENDING Awaiting transmission, when data is stored into user buffer,
|
||||
* @ref APP_USBD_CDC_ACM_USER_EVT_RX_DONE event will be raised.
|
||||
* @retval NRF_ERROR_BUSY There is already buffer set for a transfer.
|
||||
* @retval other Standard error code.
|
||||
*/
|
||||
ret_code_t app_usbd_cdc_acm_read_any(app_usbd_cdc_acm_t const * p_cdc_acm,
|
||||
void * p_buf,
|
||||
size_t length);
|
||||
|
||||
/**
|
||||
* @brief Serial state notifications.
|
||||
* */
|
||||
typedef enum {
|
||||
APP_USBD_CDC_ACM_SERIAL_STATE_DCD = (1u << 0), /**< Notification bit DCD. */
|
||||
APP_USBD_CDC_ACM_SERIAL_STATE_DSR = (1u << 1), /**< Notification bit DSR. */
|
||||
APP_USBD_CDC_ACM_SERIAL_STATE_BREAK = (1u << 2), /**< Notification bit BREAK. */
|
||||
APP_USBD_CDC_ACM_SERIAL_STATE_RING = (1u << 3), /**< Notification bit RING. */
|
||||
APP_USBD_CDC_ACM_SERIAL_STATE_FRAMING = (1u << 4), /**< Notification bit FRAMING.*/
|
||||
APP_USBD_CDC_ACM_SERIAL_STATE_PARITY = (1u << 5), /**< Notification bit PARITY. */
|
||||
APP_USBD_CDC_ACM_SERIAL_STATE_OVERRUN = (1u << 6), /**< Notification bit OVERRUN.*/
|
||||
} app_usbd_cdc_acm_serial_state_t;
|
||||
|
||||
/**
|
||||
* @brief Serial line state.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_ACM_LINE_STATE_DTR = (1u << 0), /**< Line state bit DTR.*/
|
||||
APP_USBD_CDC_ACM_LINE_STATE_RTS = (1u << 1), /**< Line state bit RTS.*/
|
||||
} app_usbd_cdc_acm_line_state_t;
|
||||
|
||||
/**
|
||||
* @brief Serial state notification via IN interrupt endpoint.
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
* @param[in] serial_state Serial state notification type.
|
||||
* @param[in] value Serial state value.
|
||||
*
|
||||
* @return Standard error code.
|
||||
*/
|
||||
ret_code_t app_usbd_cdc_acm_serial_state_notify(app_usbd_cdc_acm_t const * p_cdc_acm,
|
||||
app_usbd_cdc_acm_serial_state_t serial_state,
|
||||
bool value);
|
||||
|
||||
/**
|
||||
* @brief Control line value get.
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
* @param[in] line_state Line control value type.
|
||||
* @param[out] value Line control value.
|
||||
*
|
||||
* @return Standard error code.
|
||||
*/
|
||||
ret_code_t app_usbd_cdc_acm_line_state_get(app_usbd_cdc_acm_t const * p_cdc_acm,
|
||||
app_usbd_cdc_acm_line_state_t line_state,
|
||||
uint32_t * value);
|
||||
|
||||
/** @} */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_CDC_ACM_H__ */
|
||||
/**
|
||||
* Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_CDC_ACM_H__
|
||||
#define APP_USBD_CDC_ACM_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nrf_drv_usbd.h"
|
||||
#include "app_usbd_class_base.h"
|
||||
#include "app_usbd.h"
|
||||
#include "app_usbd_core.h"
|
||||
#include "app_usbd_descriptor.h"
|
||||
|
||||
#include "app_usbd_cdc_desc.h"
|
||||
#include "app_usbd_cdc_types.h"
|
||||
#include "app_usbd_cdc_acm_internal.h"
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_cdc_acm USB CDC ACM class
|
||||
* @ingroup app_usbd
|
||||
*
|
||||
* @brief @tagAPI52840 Module with types, definitions and API used by CDC ACM class.
|
||||
*
|
||||
* @details References:
|
||||
* - "Universal Serial Bus Class Definitions for Communications Devices"
|
||||
* Revision 1.2, November 3, 2010
|
||||
* - "Universal Serial Bus Communications Class Subclass Specification for PSTN Devices"
|
||||
* Revision 1.2, February 9, 2007
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef DOXYGEN
|
||||
/**
|
||||
* @brief CDC ACM class instance type.
|
||||
*
|
||||
* @ref APP_USBD_CLASS_TYPEDEF
|
||||
*/
|
||||
typedef struct { } app_usbd_cdc_acm_t;
|
||||
#else
|
||||
/*lint -save -e10 -e26 -e123 -e505 */
|
||||
APP_USBD_CLASS_TYPEDEF(app_usbd_cdc_acm, \
|
||||
APP_USBD_CDC_ACM_CONFIG(0, 0, 0, 0, 0), \
|
||||
APP_USBD_CDC_ACM_INSTANCE_SPECIFIC_DEC, \
|
||||
APP_USBD_CDC_ACM_DATA_SPECIFIC_DEC \
|
||||
);
|
||||
/*lint -restore*/
|
||||
#endif
|
||||
|
||||
|
||||
/*lint -save -e407 */
|
||||
|
||||
/**
|
||||
* @brief Events passed to user event handler.
|
||||
*
|
||||
* @note Example prototype of user event handler:
|
||||
*
|
||||
* @code
|
||||
void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst,
|
||||
app_usbd_cdc_acm_user_event_t event);
|
||||
* @endcode
|
||||
*/
|
||||
typedef enum app_usbd_cdc_acm_user_event_e {
|
||||
APP_USBD_CDC_ACM_USER_EVT_RX_DONE, /**< User event RX_DONE. */
|
||||
APP_USBD_CDC_ACM_USER_EVT_TX_DONE, /**< User event TX_DONE. */
|
||||
|
||||
APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN, /**< User event PORT_OPEN. */
|
||||
APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE, /**< User event PORT_CLOSE. */
|
||||
} app_usbd_cdc_acm_user_event_t;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/**
|
||||
* @brief Default CDC ACM descriptors.
|
||||
*
|
||||
* @param comm_interface COMM interface number.
|
||||
* @param comm_epin COMM interface IN endpoint.
|
||||
* @param data_interface DATA interface number.
|
||||
* @param data_epin DATA interface IN endpoint.
|
||||
* @param data_epout DATA interface OUT endpoint.
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_DEFAULT_DESC(comm_interface, \
|
||||
comm_epin, \
|
||||
data_interface, \
|
||||
data_epin, \
|
||||
data_epout) \
|
||||
APP_USBD_CDC_IAD_DSC(comm_interface, \
|
||||
APP_USBD_CDC_SUBCLASS_ACM, \
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_V250) \
|
||||
APP_USBD_CDC_COMM_INTERFACE_DSC(comm_interface, \
|
||||
APP_USBD_CDC_SUBCLASS_ACM, \
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_V250) \
|
||||
APP_USBD_CDC_HEADER_DSC(0x0110) \
|
||||
APP_USBD_CDC_CALL_MGMT_DSC(0x03, data_interface) \
|
||||
APP_USBD_CDC_ACM_DSC(0x02) \
|
||||
APP_USBD_CDC_UNION_DSC(comm_interface, data_interface) \
|
||||
APP_USBD_CDC_COM_EP_DSC(comm_epin, NRF_DRV_USBD_EPSIZE) \
|
||||
APP_USBD_CDC_DATA_INTERFACE_DSC(data_interface, 0, 0) \
|
||||
APP_USBD_CDC_DATA_EP_DSC(data_epin, data_epout, NRF_DRV_USBD_EPSIZE)
|
||||
|
||||
/**
|
||||
* @brief Global definition of app_usbd_cdc_acm_t class instance.
|
||||
*
|
||||
* @param instance_name Name of global instance.
|
||||
* @param user_ev_handler User event handler (optional).
|
||||
* @param comm_ifc Interface number of cdc_acm control.
|
||||
* @param data_ifc Interface number of cdc_acm DATA.
|
||||
* @param comm_ein COMM subclass IN endpoint.
|
||||
* @param data_ein DATA subclass IN endpoint.
|
||||
* @param data_eout DATA subclass OUT endpoint.
|
||||
* @param cdc_protocol CDC protocol @ref app_usbd_cdc_comm_protocol_t
|
||||
*
|
||||
* @note This macro is just simplified version of @ref APP_USBD_CDC_ACM_GLOBAL_DEF_INTERNAL.
|
||||
*
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_GLOBAL_DEF(instance_name, \
|
||||
user_ev_handler, \
|
||||
comm_ifc, \
|
||||
data_ifc, \
|
||||
comm_ein, \
|
||||
data_ein, \
|
||||
data_eout, \
|
||||
cdc_protocol) \
|
||||
APP_USBD_CDC_ACM_GLOBAL_DEF_INTERNAL(instance_name, \
|
||||
user_ev_handler, \
|
||||
comm_ifc, \
|
||||
data_ifc, \
|
||||
comm_ein, \
|
||||
data_ein, \
|
||||
data_eout, \
|
||||
cdc_protocol) \
|
||||
|
||||
/**
|
||||
* @brief Helper function to get class instance from CDC ACM class.
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
*
|
||||
* @return Base class instance.
|
||||
*/
|
||||
static inline app_usbd_class_inst_t const *
|
||||
app_usbd_cdc_acm_class_inst_get(app_usbd_cdc_acm_t const * p_cdc_acm)
|
||||
{
|
||||
return &p_cdc_acm->base;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Helper function to get cdc_acm specific request from cdc_acm class.
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
*
|
||||
* @return CDC ACM class specific request.
|
||||
*/
|
||||
static inline app_usbd_cdc_acm_req_t *
|
||||
app_usbd_cdc_acm_class_request_get(app_usbd_cdc_acm_t const * p_cdc_acm)
|
||||
{
|
||||
return &p_cdc_acm->specific.p_data->ctx.request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Helper function to get cdc_acm from base class instance.
|
||||
*
|
||||
* @param[in] p_inst Base class instance.
|
||||
*
|
||||
* @return CDC ACM class handle.
|
||||
*/
|
||||
static inline app_usbd_cdc_acm_t const *
|
||||
app_usbd_cdc_acm_class_get(app_usbd_class_inst_t const * p_inst)
|
||||
{
|
||||
return (app_usbd_cdc_acm_t const *)p_inst;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Writes data to CDC ACM serial port.
|
||||
*
|
||||
* This is asynchronous call. User should wait for @ref APP_USBD_CDC_ACM_USER_EVT_TX_DONE event
|
||||
* to be sure that all data has been sent and input buffer could be accessed again.
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
* @param[in] p_buf Input buffer.
|
||||
* @param[in] length Input buffer length.
|
||||
*
|
||||
* @return Standard error code.
|
||||
*/
|
||||
ret_code_t app_usbd_cdc_acm_write(app_usbd_cdc_acm_t const * p_cdc_acm,
|
||||
const void * p_buf,
|
||||
size_t length);
|
||||
|
||||
/**
|
||||
* @brief Returns the amount of data that was read.
|
||||
*
|
||||
* This function should be used on @ref APP_USBD_CDC_ACM_USER_EVT_RX_DONE event to get
|
||||
* information how many bytes have been transfered into user buffer.
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
*
|
||||
* @return Amount of data transfered.
|
||||
*/
|
||||
size_t app_usbd_cdc_acm_rx_size(app_usbd_cdc_acm_t const * p_cdc_acm);
|
||||
|
||||
/**
|
||||
* @brief Returns the amount of data that was stored into internal buffer
|
||||
*
|
||||
* This function should be used on @ref APP_USBD_CDC_ACM_USER_EVT_RX_DONE event to get
|
||||
* information how many bytes are waiting in internal buffer.
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
*
|
||||
* @return Amount of data waiting.
|
||||
*/
|
||||
size_t app_usbd_cdc_acm_bytes_stored(app_usbd_cdc_acm_t const * p_cdc_acm);
|
||||
|
||||
/**
|
||||
* @brief Reads data from CDC ACM serial port.
|
||||
*
|
||||
* This function uses internal buffer and double buffering for continuous transmission.
|
||||
*
|
||||
* If there is enough data in internal buffer to fill user buffer, NRF_SUCCESS is
|
||||
* returned and data is immediately available in the user buffer.
|
||||
*
|
||||
* If not, up to two user buffers can be scheduled, function returns NRF_ERROR_IO_PENDING
|
||||
* when first buffer is filled and @ref APP_USBD_CDC_ACM_USER_EVT_RX_DONE event is generated.
|
||||
*
|
||||
* @sa app_usbd_cdc_acm_read_any
|
||||
* @sa app_usbd_cdc_acm_rx_size
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
* @param[out] p_buf Output buffer.
|
||||
* @param[in] length Number of bytes to read.
|
||||
*
|
||||
* @retval NRF_SUCCESS Data is stored into user buffer.
|
||||
* @retval NRF_ERROR_IO_PENDING Awaiting transmission, when data is stored into user buffer,
|
||||
* @ref APP_USBD_CDC_ACM_USER_EVT_RX_DONE event will be raised.
|
||||
* @retval NRF_ERROR_BUSY There are already 2 buffers queued for transfers.
|
||||
* @retval other Standard error code.
|
||||
*/
|
||||
ret_code_t app_usbd_cdc_acm_read(app_usbd_cdc_acm_t const * p_cdc_acm,
|
||||
void * p_buf,
|
||||
size_t length);
|
||||
|
||||
/**
|
||||
* @brief Read any data from CDC ACM port up to given buffer size
|
||||
*
|
||||
* This function is very similar to the @ref app_usbd_cdc_acm_read but it returns
|
||||
* data as quick as any data is available, even if the given buffer was not totally full.
|
||||
*
|
||||
* @note This function cannot use double buffering.
|
||||
* @note To check the number of bytes really read use @ref app_usbd_cdc_acm_rx_size
|
||||
* function.
|
||||
*
|
||||
* @sa app_usbd_cdc_acm_read
|
||||
* @sa app_usbd_cdc_acm_rx_size
|
||||
*
|
||||
* @param p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
* @param[out] p_buf Output buffer.
|
||||
* @param[in] length Maximum number of bytes to read.
|
||||
*
|
||||
* @retval NRF_SUCCESS Data is stored into user buffer.
|
||||
* @retval NRF_ERROR_IO_PENDING Awaiting transmission, when data is stored into user buffer,
|
||||
* @ref APP_USBD_CDC_ACM_USER_EVT_RX_DONE event will be raised.
|
||||
* @retval NRF_ERROR_BUSY There is already buffer set for a transfer.
|
||||
* @retval other Standard error code.
|
||||
*/
|
||||
ret_code_t app_usbd_cdc_acm_read_any(app_usbd_cdc_acm_t const * p_cdc_acm,
|
||||
void * p_buf,
|
||||
size_t length);
|
||||
|
||||
/**
|
||||
* @brief Serial state notifications.
|
||||
* */
|
||||
typedef enum {
|
||||
APP_USBD_CDC_ACM_SERIAL_STATE_DCD = (1u << 0), /**< Notification bit DCD. */
|
||||
APP_USBD_CDC_ACM_SERIAL_STATE_DSR = (1u << 1), /**< Notification bit DSR. */
|
||||
APP_USBD_CDC_ACM_SERIAL_STATE_BREAK = (1u << 2), /**< Notification bit BREAK. */
|
||||
APP_USBD_CDC_ACM_SERIAL_STATE_RING = (1u << 3), /**< Notification bit RING. */
|
||||
APP_USBD_CDC_ACM_SERIAL_STATE_FRAMING = (1u << 4), /**< Notification bit FRAMING.*/
|
||||
APP_USBD_CDC_ACM_SERIAL_STATE_PARITY = (1u << 5), /**< Notification bit PARITY. */
|
||||
APP_USBD_CDC_ACM_SERIAL_STATE_OVERRUN = (1u << 6), /**< Notification bit OVERRUN.*/
|
||||
} app_usbd_cdc_acm_serial_state_t;
|
||||
|
||||
/**
|
||||
* @brief Serial line state.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_ACM_LINE_STATE_DTR = (1u << 0), /**< Line state bit DTR.*/
|
||||
APP_USBD_CDC_ACM_LINE_STATE_RTS = (1u << 1), /**< Line state bit RTS.*/
|
||||
} app_usbd_cdc_acm_line_state_t;
|
||||
|
||||
/**
|
||||
* @brief Serial state notification via IN interrupt endpoint.
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
* @param[in] serial_state Serial state notification type.
|
||||
* @param[in] value Serial state value.
|
||||
*
|
||||
* @return Standard error code.
|
||||
*/
|
||||
ret_code_t app_usbd_cdc_acm_serial_state_notify(app_usbd_cdc_acm_t const * p_cdc_acm,
|
||||
app_usbd_cdc_acm_serial_state_t serial_state,
|
||||
bool value);
|
||||
|
||||
/**
|
||||
* @brief Control line value get.
|
||||
*
|
||||
* @param[in] p_cdc_acm CDC ACM class instance (defined by @ref APP_USBD_CDC_ACM_GLOBAL_DEF).
|
||||
* @param[in] line_state Line control value type.
|
||||
* @param[out] value Line control value.
|
||||
*
|
||||
* @return Standard error code.
|
||||
*/
|
||||
ret_code_t app_usbd_cdc_acm_line_state_get(app_usbd_cdc_acm_t const * p_cdc_acm,
|
||||
app_usbd_cdc_acm_line_state_t line_state,
|
||||
uint32_t * value);
|
||||
|
||||
/** @} */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_CDC_ACM_H__ */
|
||||
|
||||
+287
-287
@@ -1,287 +1,287 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_CDC_ACM_INTERNAL_H__
|
||||
#define APP_USBD_CDC_ACM_INTERNAL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "app_util.h"
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_cdc_acm_internal USB CDC ACM internals
|
||||
* @ingroup app_usbd_cdc_acm
|
||||
* @brief @tagAPI52840 Internals of the USB ACM class implementation.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Forward declaration of type defined by @ref APP_USBD_CLASS_TYPEDEF in cdc_acm class.
|
||||
*
|
||||
*/
|
||||
APP_USBD_CLASS_FORWARD(app_usbd_cdc_acm);
|
||||
|
||||
/*lint -save -e165*/
|
||||
/**
|
||||
* @brief Forward declaration of @ref app_usbd_cdc_acm_user_event_e.
|
||||
*
|
||||
*/
|
||||
enum app_usbd_cdc_acm_user_event_e;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/**
|
||||
* @brief User event handler.
|
||||
*
|
||||
* @param[in] p_inst Class instance.
|
||||
* @param[in] event User event.
|
||||
*
|
||||
*/
|
||||
typedef void (*app_usbd_cdc_acm_user_ev_handler_t)(app_usbd_class_inst_t const * p_inst,
|
||||
enum app_usbd_cdc_acm_user_event_e event);
|
||||
|
||||
/**
|
||||
* @brief CDC ACM class part of class instance data.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t comm_interface; //!< Interface number of cdc_acm control.
|
||||
uint8_t comm_epin; //!< COMM subclass IN endpoint.
|
||||
uint8_t data_interface; //!< Interface number of cdc_acm DATA.
|
||||
uint8_t data_epout; //!< DATA subclass OUT endpoint.
|
||||
uint8_t data_epin; //!< DATA subclass IN endpoint.
|
||||
|
||||
app_usbd_cdc_comm_protocol_t protocol; //!< User specified CDC protocol.
|
||||
|
||||
app_usbd_cdc_acm_user_ev_handler_t user_ev_handler; //!< User event handler.
|
||||
|
||||
uint8_t * p_ep_interval; //!< Endpoint intervals.
|
||||
} app_usbd_cdc_acm_inst_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief CDC ACM serial state class notify.
|
||||
*/
|
||||
typedef struct {
|
||||
app_usbd_cdc_notify_t cdc_notify; //!< CDC notify.
|
||||
uint16_t serial_state; //!< Serial port state.
|
||||
} app_usbd_cdc_acm_notify_t;
|
||||
|
||||
/**
|
||||
* @brief CDC ACM class specific request handled via control endpoint.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t type; //!< Request type.
|
||||
uint8_t len; //!< Request length.
|
||||
|
||||
union {
|
||||
app_usbd_cdc_line_coding_t line_coding; //!< CDC ACM current line coding.
|
||||
app_usbd_cdc_acm_notify_t notify; //!< CDC ACM class notify.
|
||||
} payload;
|
||||
} app_usbd_cdc_acm_req_t;
|
||||
|
||||
/**
|
||||
* @brief CDC ACM rx transfer buffer.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t * p_buf; //!< User buffer pointer.
|
||||
size_t read_left; //!< Bytes left to read into buffer.
|
||||
} cdc_rx_buffer_t;
|
||||
|
||||
/**
|
||||
* @brief CDC ACM class context.
|
||||
*/
|
||||
typedef struct {
|
||||
app_usbd_cdc_acm_req_t request; //!< CDC ACM class request.
|
||||
app_usbd_cdc_line_coding_t line_coding; //!< CDC ACM current line coding.
|
||||
|
||||
uint16_t line_state; //!< CDC ACM line state bitmap, DTE side.
|
||||
uint16_t serial_state; //!< CDC ACM serial state bitmap, DCE side.
|
||||
|
||||
cdc_rx_buffer_t rx_transfer[2]; //!< User receive transfers.
|
||||
|
||||
uint8_t internal_rx_buf[NRF_DRV_USBD_EPSIZE]; //!< Internal receive buffer.
|
||||
uint8_t * p_copy_pos; //!< Current copy position from internal buffer.
|
||||
|
||||
size_t bytes_left; //!< Bytes left in internal buffer to copy.
|
||||
size_t bytes_read; //!< Bytes currently written to user buffer.
|
||||
size_t last_read; //!< Bytes read in last transfer.
|
||||
size_t cur_read; //!< Bytes currently read to internal buffer.
|
||||
} app_usbd_cdc_acm_ctx_t;
|
||||
|
||||
/**
|
||||
* @brief Default interval value for comm endpoint IN
|
||||
*
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_DEFAULT_INTERVAL 0x10
|
||||
|
||||
/**
|
||||
* @brief CDC ACM class configuration macro.
|
||||
*
|
||||
* Used by @ref APP_USBD_CDC_ACM_GLOBAL_DEF
|
||||
*
|
||||
* @param iface_comm Interface number of cdc_acm control.
|
||||
* @param epin_comm COMM subclass IN endpoint.
|
||||
* @param iface_data Interface number of cdc_acm DATA.
|
||||
* @param epin_data DATA subclass IN endpoint.
|
||||
* @param epout_data DATA subclass OUT endpoint.
|
||||
*
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_CONFIG(iface_comm, epin_comm, iface_data, epin_data, epout_data) \
|
||||
((iface_comm, epin_comm), \
|
||||
(iface_data, epin_data, epout_data))
|
||||
|
||||
|
||||
/**
|
||||
* @brief Specific class constant data for cdc_acm class.
|
||||
*
|
||||
* @ref app_usbd_cdc_acm_inst_t
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_INSTANCE_SPECIFIC_DEC app_usbd_cdc_acm_inst_t inst;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Configures cdc_acm class instance.
|
||||
*
|
||||
* @param user_event_handler User event handler.
|
||||
* @param comm_ifc Interface number of cdc_acm control.
|
||||
* @param comm_ein COMM subclass IN endpoint.
|
||||
* @param data_ifc Interface number of cdc_acm DATA.
|
||||
* @param data_ein DATA subclass IN endpoint.
|
||||
* @param data_eout DATA subclass OUT endpoint.
|
||||
* @param cdc_protocol CDC protocol.
|
||||
* @param ep_list List of endpoints and intervals
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_INST_CONFIG(user_event_handler, \
|
||||
comm_ifc, \
|
||||
comm_ein, \
|
||||
data_ifc, \
|
||||
data_ein, \
|
||||
data_eout, \
|
||||
cdc_protocol, \
|
||||
ep_list) \
|
||||
.inst = { \
|
||||
.user_ev_handler = user_event_handler, \
|
||||
.comm_interface = comm_ifc, \
|
||||
.comm_epin = comm_ifc, \
|
||||
.data_interface = data_ifc, \
|
||||
.data_epin = data_ein, \
|
||||
.data_epout = data_eout, \
|
||||
.protocol = cdc_protocol, \
|
||||
.p_ep_interval = ep_list \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Specific class data for cdc_acm class.
|
||||
*
|
||||
* @ref app_usbd_cdc_acm_ctx_t
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_DATA_SPECIFIC_DEC app_usbd_cdc_acm_ctx_t ctx;
|
||||
|
||||
|
||||
/**
|
||||
* @brief CDC ACM class descriptors config macro.
|
||||
*
|
||||
* @param interface_number Interface number.
|
||||
* @param ... Extracted endpoint list.
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_DSC_CONFIG(interface_number, ...) { \
|
||||
APP_USBD_CDC_ACM_INTERFACE_DSC(interface_number, \
|
||||
0, \
|
||||
0, \
|
||||
APP_USBD_CDC_ACM_SUBCLASS_CDC_ACMCONTROL) \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Public cdc_acm class interface.
|
||||
*
|
||||
*/
|
||||
extern const app_usbd_class_methods_t app_usbd_cdc_acm_class_methods;
|
||||
|
||||
/**
|
||||
* @brief Global definition of @ref app_usbd_cdc_acm_t class.
|
||||
*
|
||||
* @param instance_name Name of global instance.
|
||||
* @param user_ev_handler User event handler.
|
||||
* @param comm_ifc Interface number of cdc_acm control.
|
||||
* @param data_ifc Interface number of cdc_acm DATA.
|
||||
* @param comm_ein COMM subclass IN endpoint.
|
||||
* @param data_ein DATA subclass IN endpoint.
|
||||
* @param data_eout DATA subclass OUT endpoint.
|
||||
* @param cdc_protocol CDC protocol @ref app_usbd_cdc_comm_protocol_t
|
||||
*/
|
||||
/*lint -save -emacro(26 64 123 505 572 651, APP_USBD_CDC_ACM_GLOBAL_DEF_INTERNAL)*/
|
||||
#define APP_USBD_CDC_ACM_GLOBAL_DEF_INTERNAL(instance_name, \
|
||||
user_ev_handler, \
|
||||
comm_ifc, \
|
||||
data_ifc, \
|
||||
comm_ein, \
|
||||
data_ein, \
|
||||
data_eout, \
|
||||
cdc_protocol) \
|
||||
static uint8_t CONCAT_2(instance_name, _ep) = { \
|
||||
(APP_USBD_EXTRACT_INTERVAL_FLAG(comm_ein) ? APP_USBD_EXTRACT_INTERVAL_VALUE(comm_ein) \
|
||||
: APP_USBD_CDC_ACM_DEFAULT_INTERVAL)}; \
|
||||
APP_USBD_CLASS_INST_GLOBAL_DEF( \
|
||||
instance_name, \
|
||||
app_usbd_cdc_acm, \
|
||||
&app_usbd_cdc_acm_class_methods, \
|
||||
APP_USBD_CDC_ACM_CONFIG(comm_ifc, comm_ein, data_ifc, data_ein, data_eout), \
|
||||
(APP_USBD_CDC_ACM_INST_CONFIG(user_ev_handler, \
|
||||
comm_ifc, \
|
||||
comm_ein, \
|
||||
data_ifc, \
|
||||
data_ein, \
|
||||
data_eout, \
|
||||
cdc_protocol, \
|
||||
&CONCAT_2(instance_name, _ep))) \
|
||||
)
|
||||
/*lint -restore*/
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_CDC_ACM_INTERNAL_H__ */
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_CDC_ACM_INTERNAL_H__
|
||||
#define APP_USBD_CDC_ACM_INTERNAL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "app_util.h"
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_cdc_acm_internal USB CDC ACM internals
|
||||
* @ingroup app_usbd_cdc_acm
|
||||
* @brief @tagAPI52840 Internals of the USB ACM class implementation.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Forward declaration of type defined by @ref APP_USBD_CLASS_TYPEDEF in cdc_acm class.
|
||||
*
|
||||
*/
|
||||
APP_USBD_CLASS_FORWARD(app_usbd_cdc_acm);
|
||||
|
||||
/*lint -save -e165*/
|
||||
/**
|
||||
* @brief Forward declaration of @ref app_usbd_cdc_acm_user_event_e.
|
||||
*
|
||||
*/
|
||||
enum app_usbd_cdc_acm_user_event_e;
|
||||
|
||||
/*lint -restore*/
|
||||
|
||||
/**
|
||||
* @brief User event handler.
|
||||
*
|
||||
* @param[in] p_inst Class instance.
|
||||
* @param[in] event User event.
|
||||
*
|
||||
*/
|
||||
typedef void (*app_usbd_cdc_acm_user_ev_handler_t)(app_usbd_class_inst_t const * p_inst,
|
||||
enum app_usbd_cdc_acm_user_event_e event);
|
||||
|
||||
/**
|
||||
* @brief CDC ACM class part of class instance data.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t comm_interface; //!< Interface number of cdc_acm control.
|
||||
uint8_t comm_epin; //!< COMM subclass IN endpoint.
|
||||
uint8_t data_interface; //!< Interface number of cdc_acm DATA.
|
||||
uint8_t data_epout; //!< DATA subclass OUT endpoint.
|
||||
uint8_t data_epin; //!< DATA subclass IN endpoint.
|
||||
|
||||
app_usbd_cdc_comm_protocol_t protocol; //!< User specified CDC protocol.
|
||||
|
||||
app_usbd_cdc_acm_user_ev_handler_t user_ev_handler; //!< User event handler.
|
||||
|
||||
uint8_t * p_ep_interval; //!< Endpoint intervals.
|
||||
} app_usbd_cdc_acm_inst_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief CDC ACM serial state class notify.
|
||||
*/
|
||||
typedef struct {
|
||||
app_usbd_cdc_notify_t cdc_notify; //!< CDC notify.
|
||||
uint16_t serial_state; //!< Serial port state.
|
||||
} app_usbd_cdc_acm_notify_t;
|
||||
|
||||
/**
|
||||
* @brief CDC ACM class specific request handled via control endpoint.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t type; //!< Request type.
|
||||
uint8_t len; //!< Request length.
|
||||
|
||||
union {
|
||||
app_usbd_cdc_line_coding_t line_coding; //!< CDC ACM current line coding.
|
||||
app_usbd_cdc_acm_notify_t notify; //!< CDC ACM class notify.
|
||||
} payload;
|
||||
} app_usbd_cdc_acm_req_t;
|
||||
|
||||
/**
|
||||
* @brief CDC ACM rx transfer buffer.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t * p_buf; //!< User buffer pointer.
|
||||
size_t read_left; //!< Bytes left to read into buffer.
|
||||
} cdc_rx_buffer_t;
|
||||
|
||||
/**
|
||||
* @brief CDC ACM class context.
|
||||
*/
|
||||
typedef struct {
|
||||
app_usbd_cdc_acm_req_t request; //!< CDC ACM class request.
|
||||
app_usbd_cdc_line_coding_t line_coding; //!< CDC ACM current line coding.
|
||||
|
||||
uint16_t line_state; //!< CDC ACM line state bitmap, DTE side.
|
||||
uint16_t serial_state; //!< CDC ACM serial state bitmap, DCE side.
|
||||
|
||||
cdc_rx_buffer_t rx_transfer[2]; //!< User receive transfers.
|
||||
|
||||
uint8_t internal_rx_buf[NRF_DRV_USBD_EPSIZE]; //!< Internal receive buffer.
|
||||
uint8_t * p_copy_pos; //!< Current copy position from internal buffer.
|
||||
|
||||
size_t bytes_left; //!< Bytes left in internal buffer to copy.
|
||||
size_t bytes_read; //!< Bytes currently written to user buffer.
|
||||
size_t last_read; //!< Bytes read in last transfer.
|
||||
size_t cur_read; //!< Bytes currently read to internal buffer.
|
||||
} app_usbd_cdc_acm_ctx_t;
|
||||
|
||||
/**
|
||||
* @brief Default interval value for comm endpoint IN
|
||||
*
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_DEFAULT_INTERVAL 0x10
|
||||
|
||||
/**
|
||||
* @brief CDC ACM class configuration macro.
|
||||
*
|
||||
* Used by @ref APP_USBD_CDC_ACM_GLOBAL_DEF
|
||||
*
|
||||
* @param iface_comm Interface number of cdc_acm control.
|
||||
* @param epin_comm COMM subclass IN endpoint.
|
||||
* @param iface_data Interface number of cdc_acm DATA.
|
||||
* @param epin_data DATA subclass IN endpoint.
|
||||
* @param epout_data DATA subclass OUT endpoint.
|
||||
*
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_CONFIG(iface_comm, epin_comm, iface_data, epin_data, epout_data) \
|
||||
((iface_comm, epin_comm), \
|
||||
(iface_data, epin_data, epout_data))
|
||||
|
||||
|
||||
/**
|
||||
* @brief Specific class constant data for cdc_acm class.
|
||||
*
|
||||
* @ref app_usbd_cdc_acm_inst_t
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_INSTANCE_SPECIFIC_DEC app_usbd_cdc_acm_inst_t inst;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Configures cdc_acm class instance.
|
||||
*
|
||||
* @param user_event_handler User event handler.
|
||||
* @param comm_ifc Interface number of cdc_acm control.
|
||||
* @param comm_ein COMM subclass IN endpoint.
|
||||
* @param data_ifc Interface number of cdc_acm DATA.
|
||||
* @param data_ein DATA subclass IN endpoint.
|
||||
* @param data_eout DATA subclass OUT endpoint.
|
||||
* @param cdc_protocol CDC protocol.
|
||||
* @param ep_list List of endpoints and intervals
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_INST_CONFIG(user_event_handler, \
|
||||
comm_ifc, \
|
||||
comm_ein, \
|
||||
data_ifc, \
|
||||
data_ein, \
|
||||
data_eout, \
|
||||
cdc_protocol, \
|
||||
ep_list) \
|
||||
.inst = { \
|
||||
.user_ev_handler = user_event_handler, \
|
||||
.comm_interface = comm_ifc, \
|
||||
.comm_epin = comm_ifc, \
|
||||
.data_interface = data_ifc, \
|
||||
.data_epin = data_ein, \
|
||||
.data_epout = data_eout, \
|
||||
.protocol = cdc_protocol, \
|
||||
.p_ep_interval = ep_list \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Specific class data for cdc_acm class.
|
||||
*
|
||||
* @ref app_usbd_cdc_acm_ctx_t
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_DATA_SPECIFIC_DEC app_usbd_cdc_acm_ctx_t ctx;
|
||||
|
||||
|
||||
/**
|
||||
* @brief CDC ACM class descriptors config macro.
|
||||
*
|
||||
* @param interface_number Interface number.
|
||||
* @param ... Extracted endpoint list.
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_DSC_CONFIG(interface_number, ...) { \
|
||||
APP_USBD_CDC_ACM_INTERFACE_DSC(interface_number, \
|
||||
0, \
|
||||
0, \
|
||||
APP_USBD_CDC_ACM_SUBCLASS_CDC_ACMCONTROL) \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Public cdc_acm class interface.
|
||||
*
|
||||
*/
|
||||
extern const app_usbd_class_methods_t app_usbd_cdc_acm_class_methods;
|
||||
|
||||
/**
|
||||
* @brief Global definition of @ref app_usbd_cdc_acm_t class.
|
||||
*
|
||||
* @param instance_name Name of global instance.
|
||||
* @param user_ev_handler User event handler.
|
||||
* @param comm_ifc Interface number of cdc_acm control.
|
||||
* @param data_ifc Interface number of cdc_acm DATA.
|
||||
* @param comm_ein COMM subclass IN endpoint.
|
||||
* @param data_ein DATA subclass IN endpoint.
|
||||
* @param data_eout DATA subclass OUT endpoint.
|
||||
* @param cdc_protocol CDC protocol @ref app_usbd_cdc_comm_protocol_t
|
||||
*/
|
||||
/*lint -save -emacro(26 64 123 505 572 651, APP_USBD_CDC_ACM_GLOBAL_DEF_INTERNAL)*/
|
||||
#define APP_USBD_CDC_ACM_GLOBAL_DEF_INTERNAL(instance_name, \
|
||||
user_ev_handler, \
|
||||
comm_ifc, \
|
||||
data_ifc, \
|
||||
comm_ein, \
|
||||
data_ein, \
|
||||
data_eout, \
|
||||
cdc_protocol) \
|
||||
static uint8_t CONCAT_2(instance_name, _ep) = { \
|
||||
(APP_USBD_EXTRACT_INTERVAL_FLAG(comm_ein) ? APP_USBD_EXTRACT_INTERVAL_VALUE(comm_ein) \
|
||||
: APP_USBD_CDC_ACM_DEFAULT_INTERVAL)}; \
|
||||
APP_USBD_CLASS_INST_GLOBAL_DEF( \
|
||||
instance_name, \
|
||||
app_usbd_cdc_acm, \
|
||||
&app_usbd_cdc_acm_class_methods, \
|
||||
APP_USBD_CDC_ACM_CONFIG(comm_ifc, comm_ein, data_ifc, data_ein, data_eout), \
|
||||
(APP_USBD_CDC_ACM_INST_CONFIG(user_ev_handler, \
|
||||
comm_ifc, \
|
||||
comm_ein, \
|
||||
data_ifc, \
|
||||
data_ein, \
|
||||
data_eout, \
|
||||
cdc_protocol, \
|
||||
&CONCAT_2(instance_name, _ep))) \
|
||||
)
|
||||
/*lint -restore*/
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_CDC_ACM_INTERNAL_H__ */
|
||||
|
||||
+208
-208
@@ -1,208 +1,208 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_CDC_DESC_H__
|
||||
#define APP_USBD_CDC_DESC_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "app_usbd_descriptor.h"
|
||||
#include "app_usbd_cdc_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_cdc_desc CDC class descriptors
|
||||
* @brief @tagAPI52840 Descriptors used in the USB CDC class implementation.
|
||||
* @ingroup app_usbd_cdc_acm
|
||||
*
|
||||
* A group of macros used to initialize CDC descriptors
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializer of IAD descriptor for CDC class.
|
||||
*
|
||||
* @param interface_number Interface number.
|
||||
* @param subclass Subclass, @ref app_usbd_cdc_subclass_t.
|
||||
* @param protocol Protocol, @ref app_usbd_cdc_comm_protocol_t.
|
||||
*/
|
||||
#define APP_USBD_CDC_IAD_DSC(interface_number, subclass, protocol) \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_iad_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_INTERFACE_ASSOCIATION, \
|
||||
/*.bFirstInterface = */ interface_number, \
|
||||
/*.bInterfaceCount = */ 2, \
|
||||
/*.bFunctionClass = */ APP_USBD_CDC_COMM_CLASS, \
|
||||
/*.bFunctionSubClass = */ subclass, \
|
||||
/*.bFunctionProtocol = */ protocol, \
|
||||
/*.iFunction = */ 0, \
|
||||
|
||||
/**
|
||||
* @brief Initializer of interface descriptor for CDC COMM class.
|
||||
*
|
||||
* @param interface_number Interface number.
|
||||
* @param subclass Subclass, @ref app_usbd_cdc_subclass_t.
|
||||
* @param protocol Protocol, @ref app_usbd_cdc_comm_protocol_t.
|
||||
*/
|
||||
#define APP_USBD_CDC_COMM_INTERFACE_DSC(interface_number, subclass, protocol) \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_iface_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_INTERFACE, \
|
||||
/*.bInterfaceNumber = */ interface_number, \
|
||||
/*.bAlternateSetting = */ 0x00, \
|
||||
/*.bNumEndpoints = */ 1, \
|
||||
/*.bInterfaceClass = */ APP_USBD_CDC_COMM_CLASS, \
|
||||
/*.bInterfaceSubClass = */ subclass, \
|
||||
/*.bInterfaceProtocol = */ protocol, \
|
||||
/*.iInterface = 0, */ 0x00, \
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializer of interface descriptor for CDC DATA class.
|
||||
*
|
||||
* @param interface_number Interface number.
|
||||
* @param subclass Subclass, @ref app_usbd_cdc_subclass_t.
|
||||
* @param protocol Protocol, @ref app_usbd_cdc_data_protocol_t.
|
||||
*/
|
||||
#define APP_USBD_CDC_DATA_INTERFACE_DSC(interface_number, subclass, protocol) \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_iface_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_INTERFACE, \
|
||||
/*.bInterfaceNumber = */ interface_number, \
|
||||
/*.bAlternateSetting = */ 0x00, \
|
||||
/*.bNumEndpoints = */ 2, \
|
||||
/*.bInterfaceClass = */ APP_USBD_CDC_DATA_CLASS, \
|
||||
/*.bInterfaceSubClass = */ subclass, \
|
||||
/*.bInterfaceProtocol = */ protocol, \
|
||||
/*.iInterface = 0, */ 0x00, \
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializer of endpoint descriptor for CDC COM class.
|
||||
*
|
||||
* @param endpoint_in IN endpoint.
|
||||
* @param ep_size Endpoint size.
|
||||
*/
|
||||
#define APP_USBD_CDC_COM_EP_DSC(endpoint_in, ep_size) \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_ep_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_ENDPOINT, \
|
||||
/*.bEndpointAddress = */ endpoint_in, \
|
||||
/*.bmAttributes = */ APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_INTERRUPT, \
|
||||
/*.wMaxPacketSize = */ APP_USBD_U16_TO_RAW_DSC(ep_size), \
|
||||
/*.bInterval = */ 16, \
|
||||
|
||||
/**
|
||||
* @brief Initializer of endpoint descriptors for CDC DATA class.
|
||||
*
|
||||
* @param endpoint_in IN endpoint.
|
||||
* @param endpoint_out OUT endpoint.
|
||||
* @param ep_size Endpoint size.
|
||||
*/
|
||||
#define APP_USBD_CDC_DATA_EP_DSC(endpoint_in, endpoint_out, ep_size) \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_ep_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_ENDPOINT, \
|
||||
/*.bEndpointAddress = */ endpoint_in, \
|
||||
/*.bmAttributes = */ APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_BULK, \
|
||||
/*.wMaxPacketSize = */ APP_USBD_U16_TO_RAW_DSC(ep_size), \
|
||||
/*.bInterval = */ 0, \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_ep_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_ENDPOINT, \
|
||||
/*.bEndpointAddress = */ endpoint_out, \
|
||||
/*.bmAttributes = */ APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_BULK, \
|
||||
/*.wMaxPacketSize = */ APP_USBD_U16_TO_RAW_DSC(ep_size), \
|
||||
/*.bInterval = */ 0, \
|
||||
|
||||
/**
|
||||
* @brief Initializer of endpoint descriptors for CDC header descriptor.
|
||||
*
|
||||
* @param bcd_cdc BCD CDC version.
|
||||
*/
|
||||
#define APP_USBD_CDC_HEADER_DSC(bcd_cdc) \
|
||||
/*.bLength = */ sizeof(app_usbd_cdc_desc_header_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_CDC_CS_INTERFACE, \
|
||||
/*.bDescriptorSubtype = */ APP_USBD_CDC_SCS_HEADER, \
|
||||
/*.bcdCDC = */ APP_USBD_U16_TO_RAW_DSC(bcd_cdc), \
|
||||
|
||||
/**
|
||||
* @brief Initializer of endpoint descriptors for CDC call management descriptor.
|
||||
*
|
||||
* @param capabilities Capabilities.
|
||||
* @param data_interface Data interface.
|
||||
*/
|
||||
#define APP_USBD_CDC_CALL_MGMT_DSC(capabilities, data_interface) \
|
||||
/*.bLength = */ sizeof(app_usbd_cdc_desc_call_mgmt_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_CDC_CS_INTERFACE, \
|
||||
/*.bDescriptorSubtype = */ APP_USBD_CDC_SCS_CALL_MGMT, \
|
||||
/*.bmCapabilities = */ capabilities, \
|
||||
/*.bDataInterface = */ data_interface, \
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializer of endpoint descriptors for CDC DATA class.
|
||||
*
|
||||
* @param capabilities Capabilities.
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_DSC(capabilities) \
|
||||
/*.bLength = */ sizeof(app_usbd_cdc_desc_acm_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_CDC_CS_INTERFACE, \
|
||||
/*.bDescriptorSubtype = */ APP_USBD_CDC_SCS_ACM, \
|
||||
/*.bmCapabilities = */ capabilities, \
|
||||
|
||||
/**
|
||||
* @brief Initializer of endpoint descriptors for CDC DATA class.
|
||||
*
|
||||
* @param control_interface Control interface.
|
||||
* @param ... Subordinate interfaces list.
|
||||
*/
|
||||
#define APP_USBD_CDC_UNION_DSC(control_interface, ...) \
|
||||
/*.bLength = */ sizeof(app_usbd_cdc_desc_union_t) + (NUM_VA_ARGS(__VA_ARGS__)), \
|
||||
/*.bDescriptorType = */ APP_USBD_CDC_CS_INTERFACE, \
|
||||
/*.bDescriptorSubtype = */ APP_USBD_CDC_SCS_UNION, \
|
||||
/*.bControlInterface = */ control_interface, \
|
||||
/*.bSubordinateInterface = */ __VA_ARGS__, \
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_CDC_H__ */
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_CDC_DESC_H__
|
||||
#define APP_USBD_CDC_DESC_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "app_usbd_descriptor.h"
|
||||
#include "app_usbd_cdc_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_cdc_desc CDC class descriptors
|
||||
* @brief @tagAPI52840 Descriptors used in the USB CDC class implementation.
|
||||
* @ingroup app_usbd_cdc_acm
|
||||
*
|
||||
* A group of macros used to initialize CDC descriptors
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializer of IAD descriptor for CDC class.
|
||||
*
|
||||
* @param interface_number Interface number.
|
||||
* @param subclass Subclass, @ref app_usbd_cdc_subclass_t.
|
||||
* @param protocol Protocol, @ref app_usbd_cdc_comm_protocol_t.
|
||||
*/
|
||||
#define APP_USBD_CDC_IAD_DSC(interface_number, subclass, protocol) \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_iad_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_INTERFACE_ASSOCIATION, \
|
||||
/*.bFirstInterface = */ interface_number, \
|
||||
/*.bInterfaceCount = */ 2, \
|
||||
/*.bFunctionClass = */ APP_USBD_CDC_COMM_CLASS, \
|
||||
/*.bFunctionSubClass = */ subclass, \
|
||||
/*.bFunctionProtocol = */ protocol, \
|
||||
/*.iFunction = */ 0, \
|
||||
|
||||
/**
|
||||
* @brief Initializer of interface descriptor for CDC COMM class.
|
||||
*
|
||||
* @param interface_number Interface number.
|
||||
* @param subclass Subclass, @ref app_usbd_cdc_subclass_t.
|
||||
* @param protocol Protocol, @ref app_usbd_cdc_comm_protocol_t.
|
||||
*/
|
||||
#define APP_USBD_CDC_COMM_INTERFACE_DSC(interface_number, subclass, protocol) \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_iface_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_INTERFACE, \
|
||||
/*.bInterfaceNumber = */ interface_number, \
|
||||
/*.bAlternateSetting = */ 0x00, \
|
||||
/*.bNumEndpoints = */ 1, \
|
||||
/*.bInterfaceClass = */ APP_USBD_CDC_COMM_CLASS, \
|
||||
/*.bInterfaceSubClass = */ subclass, \
|
||||
/*.bInterfaceProtocol = */ protocol, \
|
||||
/*.iInterface = 0, */ 0x00, \
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializer of interface descriptor for CDC DATA class.
|
||||
*
|
||||
* @param interface_number Interface number.
|
||||
* @param subclass Subclass, @ref app_usbd_cdc_subclass_t.
|
||||
* @param protocol Protocol, @ref app_usbd_cdc_data_protocol_t.
|
||||
*/
|
||||
#define APP_USBD_CDC_DATA_INTERFACE_DSC(interface_number, subclass, protocol) \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_iface_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_INTERFACE, \
|
||||
/*.bInterfaceNumber = */ interface_number, \
|
||||
/*.bAlternateSetting = */ 0x00, \
|
||||
/*.bNumEndpoints = */ 2, \
|
||||
/*.bInterfaceClass = */ APP_USBD_CDC_DATA_CLASS, \
|
||||
/*.bInterfaceSubClass = */ subclass, \
|
||||
/*.bInterfaceProtocol = */ protocol, \
|
||||
/*.iInterface = 0, */ 0x00, \
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializer of endpoint descriptor for CDC COM class.
|
||||
*
|
||||
* @param endpoint_in IN endpoint.
|
||||
* @param ep_size Endpoint size.
|
||||
*/
|
||||
#define APP_USBD_CDC_COM_EP_DSC(endpoint_in, ep_size) \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_ep_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_ENDPOINT, \
|
||||
/*.bEndpointAddress = */ endpoint_in, \
|
||||
/*.bmAttributes = */ APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_INTERRUPT, \
|
||||
/*.wMaxPacketSize = */ APP_USBD_U16_TO_RAW_DSC(ep_size), \
|
||||
/*.bInterval = */ 16, \
|
||||
|
||||
/**
|
||||
* @brief Initializer of endpoint descriptors for CDC DATA class.
|
||||
*
|
||||
* @param endpoint_in IN endpoint.
|
||||
* @param endpoint_out OUT endpoint.
|
||||
* @param ep_size Endpoint size.
|
||||
*/
|
||||
#define APP_USBD_CDC_DATA_EP_DSC(endpoint_in, endpoint_out, ep_size) \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_ep_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_ENDPOINT, \
|
||||
/*.bEndpointAddress = */ endpoint_in, \
|
||||
/*.bmAttributes = */ APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_BULK, \
|
||||
/*.wMaxPacketSize = */ APP_USBD_U16_TO_RAW_DSC(ep_size), \
|
||||
/*.bInterval = */ 0, \
|
||||
/*.bLength = */ sizeof(app_usbd_descriptor_ep_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_DESCRIPTOR_ENDPOINT, \
|
||||
/*.bEndpointAddress = */ endpoint_out, \
|
||||
/*.bmAttributes = */ APP_USBD_DESCRIPTOR_EP_ATTR_TYPE_BULK, \
|
||||
/*.wMaxPacketSize = */ APP_USBD_U16_TO_RAW_DSC(ep_size), \
|
||||
/*.bInterval = */ 0, \
|
||||
|
||||
/**
|
||||
* @brief Initializer of endpoint descriptors for CDC header descriptor.
|
||||
*
|
||||
* @param bcd_cdc BCD CDC version.
|
||||
*/
|
||||
#define APP_USBD_CDC_HEADER_DSC(bcd_cdc) \
|
||||
/*.bLength = */ sizeof(app_usbd_cdc_desc_header_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_CDC_CS_INTERFACE, \
|
||||
/*.bDescriptorSubtype = */ APP_USBD_CDC_SCS_HEADER, \
|
||||
/*.bcdCDC = */ APP_USBD_U16_TO_RAW_DSC(bcd_cdc), \
|
||||
|
||||
/**
|
||||
* @brief Initializer of endpoint descriptors for CDC call management descriptor.
|
||||
*
|
||||
* @param capabilities Capabilities.
|
||||
* @param data_interface Data interface.
|
||||
*/
|
||||
#define APP_USBD_CDC_CALL_MGMT_DSC(capabilities, data_interface) \
|
||||
/*.bLength = */ sizeof(app_usbd_cdc_desc_call_mgmt_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_CDC_CS_INTERFACE, \
|
||||
/*.bDescriptorSubtype = */ APP_USBD_CDC_SCS_CALL_MGMT, \
|
||||
/*.bmCapabilities = */ capabilities, \
|
||||
/*.bDataInterface = */ data_interface, \
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializer of endpoint descriptors for CDC DATA class.
|
||||
*
|
||||
* @param capabilities Capabilities.
|
||||
*/
|
||||
#define APP_USBD_CDC_ACM_DSC(capabilities) \
|
||||
/*.bLength = */ sizeof(app_usbd_cdc_desc_acm_t), \
|
||||
/*.bDescriptorType = */ APP_USBD_CDC_CS_INTERFACE, \
|
||||
/*.bDescriptorSubtype = */ APP_USBD_CDC_SCS_ACM, \
|
||||
/*.bmCapabilities = */ capabilities, \
|
||||
|
||||
/**
|
||||
* @brief Initializer of endpoint descriptors for CDC DATA class.
|
||||
*
|
||||
* @param control_interface Control interface.
|
||||
* @param ... Subordinate interfaces list.
|
||||
*/
|
||||
#define APP_USBD_CDC_UNION_DSC(control_interface, ...) \
|
||||
/*.bLength = */ sizeof(app_usbd_cdc_desc_union_t) + (NUM_VA_ARGS(__VA_ARGS__)), \
|
||||
/*.bDescriptorType = */ APP_USBD_CDC_CS_INTERFACE, \
|
||||
/*.bDescriptorSubtype = */ APP_USBD_CDC_SCS_UNION, \
|
||||
/*.bControlInterface = */ control_interface, \
|
||||
/*.bSubordinateInterface = */ __VA_ARGS__, \
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_CDC_H__ */
|
||||
|
||||
+360
-360
@@ -1,360 +1,360 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_CDC_TYPES_H__
|
||||
#define APP_USBD_CDC_TYPES_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_cdc_types CDC class types
|
||||
* @ingroup app_usbd_cdc_acm
|
||||
*
|
||||
* @brief @tagAPI52840 Variable types used by the CDC class implementation.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Communications Interface Class code.
|
||||
*
|
||||
* Used for control interface in communication class.
|
||||
* @ref app_usbd_descriptor_iface_t::bInterfaceClass
|
||||
*/
|
||||
#define APP_USBD_CDC_COMM_CLASS 0x02
|
||||
|
||||
/**
|
||||
* @brief Data Class Interface code.
|
||||
*
|
||||
* Used for data interface in communication class.
|
||||
* @ref app_usbd_descriptor_iface_t::bInterfaceClass
|
||||
*/
|
||||
#define APP_USBD_CDC_DATA_CLASS 0x0A
|
||||
|
||||
/**
|
||||
* @brief CDC subclass possible values.
|
||||
*
|
||||
* @ref app_usbd_descriptor_iface_t::bInterfaceSubClass
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_SUBCLASS_RESERVED = 0x00, /**< Reserved in documentation. */
|
||||
APP_USBD_CDC_SUBCLASS_DLCM = 0x01, /**< Direct Line Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_ACM = 0x02, /**< Abstract Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_TCM = 0x03, /**< Telephone Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_MCCM = 0x04, /**< Multi-Channel Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_CAPI = 0x05, /**< CAPI Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_ENCM = 0x06, /**< Ethernet Networking Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_ATM = 0x07, /**< ATM Networking Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_WHCM = 0x08, /**< Wireless Handset Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_DM = 0x09, /**< Device Management. */
|
||||
APP_USBD_CDC_SUBCLASS_MDLM = 0x0A, /**< Mobile Direct Line Model. */
|
||||
APP_USBD_CDC_SUBCLASS_OBEX = 0x0B, /**< OBEX. */
|
||||
APP_USBD_CDC_SUBCLASS_EEM = 0x0C, /**< Ethernet Emulation Model. */
|
||||
APP_USBD_CDC_SUBCLASS_NCM = 0x0D /**< Network Control Model. */
|
||||
} app_usbd_cdc_subclass_t;
|
||||
|
||||
/**
|
||||
* @brief CDC protocol possible values.
|
||||
*
|
||||
* @ref app_usbd_descriptor_iface_t::bInterfaceProtocol
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_COMM_PROTOCOL_NONE = 0x00, /**< No class specific protocol required. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_V250 = 0x01, /**< AT Commands: V.250 etc. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_PCCA101 = 0x02, /**< AT Commands defined by PCCA-101. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_PCCA101_ANNEXO = 0x03, /**< AT Commands defined by PCCA-101 & Annex O. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_GSM707 = 0x04, /**< AT Commands defined by GSM 07.07. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_3GPP_27007 = 0x05, /**< AT Commands defined by 3GPP 27.007. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_CDMA = 0x06, /**< AT Commands defined by TIA for CDMA. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_EEM = 0x07, /**< Ethernet Emulation Model. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_EXTERNAL = 0xFE, /**< External Protocol: Commands defined by Command Set Functional Descriptor. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_VENDOR = 0xFF /**< Vendor-specific. */
|
||||
} app_usbd_cdc_comm_protocol_t;
|
||||
|
||||
/**
|
||||
* @brief CDC data interface protocols possible values.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_DATA_PROTOCOL_NONE = 0x00, /**< No class specific protocol required. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_NTB = 0x01, /**< Network Transfer Block. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_ISDN_BRI = 0x30, /**< Physical interface protocol for ISDN BRI. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_HDLC = 0x31, /**< HDLC. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_TRANSPARENT = 0x32, /**< Transparent. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_Q921M = 0x50, /**< Management protocol for Q.921 data link protocol. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_Q921 = 0x51, /**< Data link protocol for Q.921. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_Q921TM = 0x52, /**< TEI-multiplexor for Q.921 data link protocol. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_V42BIS = 0x90, /**< Data compression procedures. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_Q931 = 0x91, /**< Euro-ISDN protocol control. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_V120 = 0x92, /**< V.24 rate adaptation to ISDN. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_CAPI20 = 0x93, /**< CAPI Commands. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_HOST = 0xFD, /**< Host based driver.
|
||||
* @note This protocol code should only be used in messages
|
||||
* between host and device to identify the host driver portion
|
||||
* of a protocol stack.
|
||||
*/
|
||||
APP_USBD_CDC_DATA_PROTOCOL_EXTERNAL = 0xFE, /**< The protocol(s) are described using a Protocol Unit Functional
|
||||
* Descriptors on Communications Class Interface.
|
||||
*/
|
||||
APP_USBD_CDC_DATA_PROTOCOL_VENDOR = 0xFF /**< Vendor-specific. */
|
||||
} app_usbd_cdc_data_protocol_t;
|
||||
|
||||
/**
|
||||
* @brief CDC Functional Descriptor types.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_CS_INTERFACE = 0x24, /**< Class specific interface descriptor type.*/
|
||||
APP_USBD_CDC_CS_ENDPOINT = 0x25 /**< Class specific endpoint descriptor type.*/
|
||||
} app_usbd_cdc_func_type_t;
|
||||
|
||||
/**
|
||||
* @brief CDC Functional Descriptor subtypes.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_SCS_HEADER = 0x00, /**< Header Functional Descriptor, which marks the beginning of the concatenated set of functional descriptors for the interface. */
|
||||
APP_USBD_CDC_SCS_CALL_MGMT = 0x01, /**< Call Management Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_ACM = 0x02, /**< Abstract Control Management Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_DLM = 0x03, /**< Direct Line Management Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_TEL_R = 0x04, /**< Telephone Ringer Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_TEL_CAP = 0x05, /**< Telephone Call and Line State Reporting Capabilities Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_UNION = 0x06, /**< Union Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_COUNTRY_SEL = 0x07, /**< Country Selection Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_TEL_OM = 0x08, /**< Telephone Operational Modes Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_USB_TERM = 0x09, /**< USB Terminal Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_NCT = 0x0A, /**< Network Channel Terminal Descriptor. */
|
||||
APP_USBD_CDC_SCS_PU = 0x0B, /**< Protocol Unit Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_EU = 0x0C, /**< Extension Unit Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_MCM = 0x0D, /**< Multi-Channel Management Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_CAPI = 0x0E, /**< CAPI Control Management Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_ETH = 0x0F, /**< Ethernet Networking Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_ATM = 0x10, /**< ATM Networking Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_WHCM = 0x11, /**< Wireless Handset Control Model Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_MDLM = 0x12, /**< Mobile Direct Line Model Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_MDLM_DET = 0x13, /**< MDLM Detail Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_DMM = 0x14, /**< Device Management Model Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_OBEX = 0x15, /**< OBEX Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_CS = 0x16, /**< Command Set Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_CS_DET = 0x17, /**< Command Set Detail Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_TEL_CM = 0x18, /**< Telephone Control Model Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_OBEX_SI = 0x19, /**< OBEX Service Identifier Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_NCM = 0x1A /**< NCM Functional Descriptor. */
|
||||
} app_usbd_cdc_func_subtype_t;
|
||||
|
||||
/* Make all descriptors packed */
|
||||
#pragma pack(push, 1)
|
||||
|
||||
/**
|
||||
* @brief Header Functional Descriptor.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t bFunctionLength; //!< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< @ref APP_USBD_CDC_CS_INTERFACE descriptor type.
|
||||
uint8_t bDescriptorSubtype; //!< Descriptor subtype @ref APP_USBD_CDC_SCS_HEADER.
|
||||
uint8_t bcdCDC[2]; //!< USB Class Definitions for Communications Devices Specification release number in binary-coded decimal.
|
||||
} app_usbd_cdc_desc_header_t;
|
||||
|
||||
/**
|
||||
* @brief Call management capabilities.
|
||||
*
|
||||
* @ref app_usbd_cdc_desc_call_mgmt_t::bmCapabilities bit.
|
||||
* */
|
||||
typedef enum {
|
||||
APP_USBD_CDC_CALL_MGMT_SUPPORTED = (1 << 0), /**< Call management capability bit 0.*/
|
||||
APP_USBD_CDC_CALL_MGMT_OVER_DCI = (1 << 1), /**< Call management capability bit 1.*/
|
||||
} app_subd_cdc_call_mgmt_cap_t;
|
||||
|
||||
/**
|
||||
* @brief CDC Call Management Functional Descriptor.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t bFunctionLength; //!< Size of this functional descriptor, in bytes.
|
||||
uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_CDC_CS_INTERFACE.
|
||||
uint8_t bDescriptorSubtype; //!< Descriptor subtype @ref APP_USBD_CDC_SCS_CALL_MGMT.
|
||||
uint8_t bmCapabilities; //!< Capabilities @ref app_subd_cdc_call_mgmt_cap_t.
|
||||
uint8_t bDataInterface; //!< Data interface number.
|
||||
} app_usbd_cdc_desc_call_mgmt_t;
|
||||
|
||||
/**
|
||||
* @brief ACM capabilities.
|
||||
*
|
||||
* @ref app_usbd_cdc_desc_acm_t::bmCapabilities bit.
|
||||
* */
|
||||
typedef enum {
|
||||
APP_USBD_CDC_ACM_FEATURE_REQUESTS = (1 << 0), /**< ACM capability bit FEATURE_REQUESTS. */
|
||||
APP_USBD_CDC_ACM_LINE_REQUESTS = (1 << 1), /**< ACM capability bit LINE_REQUESTS. */
|
||||
APP_USBD_CDC_ACM_SENDBREAK_REQUESTS = (1 << 2), /**< ACM capability bit SENDBREAK_REQUESTS.*/
|
||||
APP_USBD_CDC_ACM_NOTIFY_REQUESTS = (1 << 3), /**< ACM capability bit NOTIFY_REQUESTS. */
|
||||
} app_subd_cdc_acm_cap_t;
|
||||
|
||||
/**
|
||||
* @brief CDC ACM Functional Descriptor.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t bFunctionLength; //!< Size of this functional descriptor, in bytes.
|
||||
uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_CDC_CS_INTERFACE.
|
||||
uint8_t bDescriptorSubtype; //!< Descriptor subtype @ref APP_USBD_CDC_SCS_ACM.
|
||||
uint8_t bmCapabilities; //!< Capabilities @ref app_subd_cdc_acm_cap_t.
|
||||
} app_usbd_cdc_desc_acm_t;
|
||||
|
||||
/**
|
||||
* @brief Union Functional Descriptor.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t bFunctionLength; //!< Size of this functional descriptor, in bytes.
|
||||
uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_CDC_CS_INTERFACE.
|
||||
uint8_t bDescriptorSubtype; //!< Descriptor subtype @ref APP_USBD_CDC_SCS_UNION.
|
||||
uint8_t bControlInterface; //!< The interface number of the Communications or Data Class interface, designated as the controlling interface for the union.
|
||||
uint8_t bSubordinateInterface[]; //!< Interface number of subordinate interfaces in the union. Number of interfaced depends on descriptor size.
|
||||
} app_usbd_cdc_desc_union_t;
|
||||
|
||||
/**
|
||||
* @brief Country Selection Functional Descriptor.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t bFunctionLength; //!< Size of this functional descriptor, in bytes.
|
||||
uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_CDC_CS_INTERFACE.
|
||||
uint8_t bDescriptorSubtype; //!< Descriptor subtype @ref APP_USBD_CDC_SCS_COUNTRY_SEL.
|
||||
uint8_t iCountryCodeRelDate; //!< Index of a string giving the release date for the implemented ISO 3166 Country Codes.
|
||||
} app_usbd_cdc_desc_country_sel_t;
|
||||
|
||||
/**
|
||||
* @brief CDC Requests
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
/* CDC General */
|
||||
APP_USBD_CDC_REQ_SEND_ENCAPSULATED_COMMAND = 0x00, /**< This request is used to issue a command in the format of the supported control protocol of the Communications Class interface. */
|
||||
APP_USBD_CDC_REQ_GET_ENCAPSULATED_RESPONSE = 0x01, /**< This request is used to request a response in the format of the supported control protocol of the Communications Class interface. */
|
||||
/* CDC PSTN */
|
||||
APP_USBD_CDC_REQ_SET_COMM_FEATURE = 0x02, /**< This request controls the settings for a particular communications feature of a particular target. */
|
||||
APP_USBD_CDC_REQ_GET_COMM_FEATURE = 0x03, /**< This request returns the current settings for the communications feature as selected. */
|
||||
APP_USBD_CDC_REQ_CLEAR_COMM_FEATURE = 0x04, /**< This request controls the settings for a particular communications feature of a particular target, setting the selected feature to its default state. */
|
||||
APP_USBD_CDC_REQ_SET_AUX_LINE_STATE = 0x10, /**< This request is used to connect or disconnect a secondary jack to POTS circuit or CODEC, depending on hook state. */
|
||||
APP_USBD_CDC_REQ_SET_HOOK_STATE = 0x11, /**< This request is used to set the necessary PSTN line relay code for on-hook, off-hook, and caller ID states. */
|
||||
APP_USBD_CDC_REQ_PULSE_SETUP = 0x12, /**< This request is used to prepare for a pulse-dialing cycle. */
|
||||
APP_USBD_CDC_REQ_SEND_PULSE = 0x13, /**< This request is used to generate a specified number of make/break pulse cycles. */
|
||||
APP_USBD_CDC_REQ_SET_PULSE_TIME = 0x14, /**< This request sets the timing of the make and break periods for pulse dialing. */
|
||||
APP_USBD_CDC_REQ_RING_AUX_JACK = 0x15, /**< This request is used to generate a ring signal on a secondary phone jack. */
|
||||
APP_USBD_CDC_REQ_SET_LINE_CODING = 0x20, /**< This request allows the host to specify typical asynchronous line-character formatting properties. */
|
||||
APP_USBD_CDC_REQ_GET_LINE_CODING = 0x21, /**< This request allows the host to find out the currently configured line coding. */
|
||||
APP_USBD_CDC_REQ_SET_CONTROL_LINE_STATE = 0x22, /**< This request generates RS-232/V.24 style control signals. */
|
||||
APP_USBD_CDC_REQ_SEND_BREAK = 0x23, /**< This request sends special carrier modulation that generates an RS-232 style break. */
|
||||
APP_USBD_CDC_REQ_SET_RINGER_PARMS = 0x30, /**< This request configures the ringer for the communications device. */
|
||||
APP_USBD_CDC_REQ_GET_RINGER_PARMS = 0x31, /**< This request returns the ringer capabilities of the device and the current status of the device’s ringer. */
|
||||
APP_USBD_CDC_REQ_SET_OPERATION_PARMS = 0x32, /**< Sets the operational mode for the device, between a simple mode, standalone mode and a host centric mode. */
|
||||
APP_USBD_CDC_REQ_GET_OPERATION_PARMS = 0x33, /**< This request gets the current operational mode for the device. */
|
||||
APP_USBD_CDC_REQ_SET_LINE_PARMS = 0x34, /**< This request is used to change the state of the line, corresponding to the interface or master interface of a union to which the command was sent. */
|
||||
APP_USBD_CDC_REQ_GET_LINE_PARMS = 0x35, /**< This request is used to report the state of the line that corresponds to the interface or master interface of a union to which the command was sent. */
|
||||
APP_USBD_CDC_REQ_DIAL_DIGITS = 0x36, /**< This request dials the DTMF digits over the specified line. */
|
||||
} app_usbd_cdc_req_id_t;
|
||||
|
||||
/**
|
||||
* @brief CDC Notifications.
|
||||
*/
|
||||
typedef enum {
|
||||
/* CDC General */
|
||||
APP_USBD_CDC_NOTIF_NETWORK_CONNECTION = 0x00, /**< This notification allows the device to notify the host about network connection status. */
|
||||
APP_USBD_CDC_NOTIF_RESPONSE_AVAILABLE = 0x01, /**< This notification allows the device to notify the host that a response is available.
|
||||
* This response can be retrieved with a subsequent GetEncapsulatedResponse request.
|
||||
_ */
|
||||
APP_USBD_CDC_NOTIF_CONNECTION_SPEED_CHANGE = 0x2A, /**< This notification allows the device to inform the host-networking driver
|
||||
* that a change in either the up-link or the down-link bit rate of the connection has occurred.
|
||||
*/
|
||||
/* CDC PSTN */
|
||||
APP_USBD_CDC_NOTIF_AUX_JACK_HOOK_STATE = 0x08, /**< (DLM) This notification indicates the loop has changed on the auxiliary phone interface of the USB device. */
|
||||
APP_USBD_CDC_NOTIF_RING_DETECT = 0x09, /**< (DLM) This notification indicates ring voltage on the POTS line interface of the USB device. */
|
||||
APP_USBD_CDC_NOTIF_SERIAL_STATE = 0x20, /**< (ACM) This notification sends asynchronous notification of UART status. */
|
||||
APP_USBD_CDC_NOTIF_CALL_STATE_CHANGE = 0x28, /**< (TCM) This notification identifies that a change has occurred to the state of a call on the line corresponding to the interface or union for the line. */
|
||||
APP_USBD_CDC_NOTIF_LINE_STATE_CHANGE = 0x29 /**< (TCM) This notification identifies that a change has occurred to the state of the line corresponding to the interface or master interface of a union sending the notification message. */
|
||||
} app_usbd_cdc_notify_id_t;
|
||||
|
||||
/**
|
||||
* @brief Notification sent via CDC COMM endpoint.
|
||||
* */
|
||||
typedef struct {
|
||||
uint8_t bmRequestType; //!< Request type.
|
||||
uint8_t bmRequest; //!< Request ID @ref app_usbd_cdc_req_id_t.
|
||||
uint16_t wValue; //!< Value field.
|
||||
uint16_t wIndex; //!< Index field.
|
||||
uint16_t wLength; //!< Length of payload following.
|
||||
} app_usbd_cdc_notify_t;
|
||||
|
||||
/**
|
||||
* @brief CDC line coding structure.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t dwDTERate[4]; //!< Line baudrate.
|
||||
uint8_t bCharFormat; //!< Character format @ref app_usbd_cdc_line_stopbit_t.
|
||||
uint8_t bParityType; //!< Parity bits @ref app_usbd_cdc_line_parity_t.
|
||||
uint8_t bDataBits; //!< Number of data bits.
|
||||
} app_usbd_cdc_line_coding_t;
|
||||
|
||||
/**
|
||||
* @brief Possible values of @ref app_usbd_cdc_line_coding_t::bCharFormat.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_LINE_STOPBIT_1 = 0, /**< 1 stop bit. */
|
||||
APP_USBD_CDC_LINE_STOPBIT_1_5 = 1, /**< 1.5 stop bits. */
|
||||
APP_USBD_CDC_LINE_STOPBIT_2 = 2, /**< 2 stop bits. */
|
||||
} app_usbd_cdc_line_stopbit_t;
|
||||
|
||||
/**
|
||||
* @brief Possible values of @ref app_usbd_cdc_line_coding_t::bParityType.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_LINE_PARITY_NONE = 0, /**< No parity. */
|
||||
APP_USBD_CDC_LINE_PARITY_ODD = 1, /**< Odd parity. */
|
||||
APP_USBD_CDC_LINE_PARITY_EVEN = 2, /**< Even parity. */
|
||||
APP_USBD_CDC_LINE_PARITY_MARK = 3, /**< Parity forced to 0 (space).*/
|
||||
APP_USBD_CDC_LINE_PARITY_SPACE = 4, /**< Parity forced to 1 (mark). */
|
||||
} app_usbd_cdc_line_parity_t;
|
||||
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
/** @} */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_TYPES_H__ */
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_CDC_TYPES_H__
|
||||
#define APP_USBD_CDC_TYPES_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_cdc_types CDC class types
|
||||
* @ingroup app_usbd_cdc_acm
|
||||
*
|
||||
* @brief @tagAPI52840 Variable types used by the CDC class implementation.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Communications Interface Class code.
|
||||
*
|
||||
* Used for control interface in communication class.
|
||||
* @ref app_usbd_descriptor_iface_t::bInterfaceClass
|
||||
*/
|
||||
#define APP_USBD_CDC_COMM_CLASS 0x02
|
||||
|
||||
/**
|
||||
* @brief Data Class Interface code.
|
||||
*
|
||||
* Used for data interface in communication class.
|
||||
* @ref app_usbd_descriptor_iface_t::bInterfaceClass
|
||||
*/
|
||||
#define APP_USBD_CDC_DATA_CLASS 0x0A
|
||||
|
||||
/**
|
||||
* @brief CDC subclass possible values.
|
||||
*
|
||||
* @ref app_usbd_descriptor_iface_t::bInterfaceSubClass
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_SUBCLASS_RESERVED = 0x00, /**< Reserved in documentation. */
|
||||
APP_USBD_CDC_SUBCLASS_DLCM = 0x01, /**< Direct Line Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_ACM = 0x02, /**< Abstract Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_TCM = 0x03, /**< Telephone Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_MCCM = 0x04, /**< Multi-Channel Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_CAPI = 0x05, /**< CAPI Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_ENCM = 0x06, /**< Ethernet Networking Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_ATM = 0x07, /**< ATM Networking Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_WHCM = 0x08, /**< Wireless Handset Control Model. */
|
||||
APP_USBD_CDC_SUBCLASS_DM = 0x09, /**< Device Management. */
|
||||
APP_USBD_CDC_SUBCLASS_MDLM = 0x0A, /**< Mobile Direct Line Model. */
|
||||
APP_USBD_CDC_SUBCLASS_OBEX = 0x0B, /**< OBEX. */
|
||||
APP_USBD_CDC_SUBCLASS_EEM = 0x0C, /**< Ethernet Emulation Model. */
|
||||
APP_USBD_CDC_SUBCLASS_NCM = 0x0D /**< Network Control Model. */
|
||||
} app_usbd_cdc_subclass_t;
|
||||
|
||||
/**
|
||||
* @brief CDC protocol possible values.
|
||||
*
|
||||
* @ref app_usbd_descriptor_iface_t::bInterfaceProtocol
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_COMM_PROTOCOL_NONE = 0x00, /**< No class specific protocol required. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_V250 = 0x01, /**< AT Commands: V.250 etc. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_PCCA101 = 0x02, /**< AT Commands defined by PCCA-101. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_PCCA101_ANNEXO = 0x03, /**< AT Commands defined by PCCA-101 & Annex O. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_GSM707 = 0x04, /**< AT Commands defined by GSM 07.07. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_3GPP_27007 = 0x05, /**< AT Commands defined by 3GPP 27.007. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_AT_CDMA = 0x06, /**< AT Commands defined by TIA for CDMA. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_EEM = 0x07, /**< Ethernet Emulation Model. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_EXTERNAL = 0xFE, /**< External Protocol: Commands defined by Command Set Functional Descriptor. */
|
||||
APP_USBD_CDC_COMM_PROTOCOL_VENDOR = 0xFF /**< Vendor-specific. */
|
||||
} app_usbd_cdc_comm_protocol_t;
|
||||
|
||||
/**
|
||||
* @brief CDC data interface protocols possible values.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_DATA_PROTOCOL_NONE = 0x00, /**< No class specific protocol required. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_NTB = 0x01, /**< Network Transfer Block. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_ISDN_BRI = 0x30, /**< Physical interface protocol for ISDN BRI. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_HDLC = 0x31, /**< HDLC. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_TRANSPARENT = 0x32, /**< Transparent. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_Q921M = 0x50, /**< Management protocol for Q.921 data link protocol. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_Q921 = 0x51, /**< Data link protocol for Q.921. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_Q921TM = 0x52, /**< TEI-multiplexor for Q.921 data link protocol. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_V42BIS = 0x90, /**< Data compression procedures. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_Q931 = 0x91, /**< Euro-ISDN protocol control. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_V120 = 0x92, /**< V.24 rate adaptation to ISDN. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_CAPI20 = 0x93, /**< CAPI Commands. */
|
||||
APP_USBD_CDC_DATA_PROTOCOL_HOST = 0xFD, /**< Host based driver.
|
||||
* @note This protocol code should only be used in messages
|
||||
* between host and device to identify the host driver portion
|
||||
* of a protocol stack.
|
||||
*/
|
||||
APP_USBD_CDC_DATA_PROTOCOL_EXTERNAL = 0xFE, /**< The protocol(s) are described using a Protocol Unit Functional
|
||||
* Descriptors on Communications Class Interface.
|
||||
*/
|
||||
APP_USBD_CDC_DATA_PROTOCOL_VENDOR = 0xFF /**< Vendor-specific. */
|
||||
} app_usbd_cdc_data_protocol_t;
|
||||
|
||||
/**
|
||||
* @brief CDC Functional Descriptor types.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_CS_INTERFACE = 0x24, /**< Class specific interface descriptor type.*/
|
||||
APP_USBD_CDC_CS_ENDPOINT = 0x25 /**< Class specific endpoint descriptor type.*/
|
||||
} app_usbd_cdc_func_type_t;
|
||||
|
||||
/**
|
||||
* @brief CDC Functional Descriptor subtypes.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_SCS_HEADER = 0x00, /**< Header Functional Descriptor, which marks the beginning of the concatenated set of functional descriptors for the interface. */
|
||||
APP_USBD_CDC_SCS_CALL_MGMT = 0x01, /**< Call Management Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_ACM = 0x02, /**< Abstract Control Management Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_DLM = 0x03, /**< Direct Line Management Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_TEL_R = 0x04, /**< Telephone Ringer Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_TEL_CAP = 0x05, /**< Telephone Call and Line State Reporting Capabilities Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_UNION = 0x06, /**< Union Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_COUNTRY_SEL = 0x07, /**< Country Selection Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_TEL_OM = 0x08, /**< Telephone Operational Modes Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_USB_TERM = 0x09, /**< USB Terminal Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_NCT = 0x0A, /**< Network Channel Terminal Descriptor. */
|
||||
APP_USBD_CDC_SCS_PU = 0x0B, /**< Protocol Unit Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_EU = 0x0C, /**< Extension Unit Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_MCM = 0x0D, /**< Multi-Channel Management Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_CAPI = 0x0E, /**< CAPI Control Management Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_ETH = 0x0F, /**< Ethernet Networking Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_ATM = 0x10, /**< ATM Networking Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_WHCM = 0x11, /**< Wireless Handset Control Model Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_MDLM = 0x12, /**< Mobile Direct Line Model Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_MDLM_DET = 0x13, /**< MDLM Detail Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_DMM = 0x14, /**< Device Management Model Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_OBEX = 0x15, /**< OBEX Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_CS = 0x16, /**< Command Set Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_CS_DET = 0x17, /**< Command Set Detail Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_TEL_CM = 0x18, /**< Telephone Control Model Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_OBEX_SI = 0x19, /**< OBEX Service Identifier Functional Descriptor. */
|
||||
APP_USBD_CDC_SCS_NCM = 0x1A /**< NCM Functional Descriptor. */
|
||||
} app_usbd_cdc_func_subtype_t;
|
||||
|
||||
/* Make all descriptors packed */
|
||||
#pragma pack(push, 1)
|
||||
|
||||
/**
|
||||
* @brief Header Functional Descriptor.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t bFunctionLength; //!< Size of this descriptor in bytes.
|
||||
uint8_t bDescriptorType; //!< @ref APP_USBD_CDC_CS_INTERFACE descriptor type.
|
||||
uint8_t bDescriptorSubtype; //!< Descriptor subtype @ref APP_USBD_CDC_SCS_HEADER.
|
||||
uint8_t bcdCDC[2]; //!< USB Class Definitions for Communications Devices Specification release number in binary-coded decimal.
|
||||
} app_usbd_cdc_desc_header_t;
|
||||
|
||||
/**
|
||||
* @brief Call management capabilities.
|
||||
*
|
||||
* @ref app_usbd_cdc_desc_call_mgmt_t::bmCapabilities bit.
|
||||
* */
|
||||
typedef enum {
|
||||
APP_USBD_CDC_CALL_MGMT_SUPPORTED = (1 << 0), /**< Call management capability bit 0.*/
|
||||
APP_USBD_CDC_CALL_MGMT_OVER_DCI = (1 << 1), /**< Call management capability bit 1.*/
|
||||
} app_subd_cdc_call_mgmt_cap_t;
|
||||
|
||||
/**
|
||||
* @brief CDC Call Management Functional Descriptor.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t bFunctionLength; //!< Size of this functional descriptor, in bytes.
|
||||
uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_CDC_CS_INTERFACE.
|
||||
uint8_t bDescriptorSubtype; //!< Descriptor subtype @ref APP_USBD_CDC_SCS_CALL_MGMT.
|
||||
uint8_t bmCapabilities; //!< Capabilities @ref app_subd_cdc_call_mgmt_cap_t.
|
||||
uint8_t bDataInterface; //!< Data interface number.
|
||||
} app_usbd_cdc_desc_call_mgmt_t;
|
||||
|
||||
/**
|
||||
* @brief ACM capabilities.
|
||||
*
|
||||
* @ref app_usbd_cdc_desc_acm_t::bmCapabilities bit.
|
||||
* */
|
||||
typedef enum {
|
||||
APP_USBD_CDC_ACM_FEATURE_REQUESTS = (1 << 0), /**< ACM capability bit FEATURE_REQUESTS. */
|
||||
APP_USBD_CDC_ACM_LINE_REQUESTS = (1 << 1), /**< ACM capability bit LINE_REQUESTS. */
|
||||
APP_USBD_CDC_ACM_SENDBREAK_REQUESTS = (1 << 2), /**< ACM capability bit SENDBREAK_REQUESTS.*/
|
||||
APP_USBD_CDC_ACM_NOTIFY_REQUESTS = (1 << 3), /**< ACM capability bit NOTIFY_REQUESTS. */
|
||||
} app_subd_cdc_acm_cap_t;
|
||||
|
||||
/**
|
||||
* @brief CDC ACM Functional Descriptor.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t bFunctionLength; //!< Size of this functional descriptor, in bytes.
|
||||
uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_CDC_CS_INTERFACE.
|
||||
uint8_t bDescriptorSubtype; //!< Descriptor subtype @ref APP_USBD_CDC_SCS_ACM.
|
||||
uint8_t bmCapabilities; //!< Capabilities @ref app_subd_cdc_acm_cap_t.
|
||||
} app_usbd_cdc_desc_acm_t;
|
||||
|
||||
/**
|
||||
* @brief Union Functional Descriptor.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t bFunctionLength; //!< Size of this functional descriptor, in bytes.
|
||||
uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_CDC_CS_INTERFACE.
|
||||
uint8_t bDescriptorSubtype; //!< Descriptor subtype @ref APP_USBD_CDC_SCS_UNION.
|
||||
uint8_t bControlInterface; //!< The interface number of the Communications or Data Class interface, designated as the controlling interface for the union.
|
||||
uint8_t bSubordinateInterface[]; //!< Interface number of subordinate interfaces in the union. Number of interfaced depends on descriptor size.
|
||||
} app_usbd_cdc_desc_union_t;
|
||||
|
||||
/**
|
||||
* @brief Country Selection Functional Descriptor.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t bFunctionLength; //!< Size of this functional descriptor, in bytes.
|
||||
uint8_t bDescriptorType; //!< Descriptor type @ref APP_USBD_CDC_CS_INTERFACE.
|
||||
uint8_t bDescriptorSubtype; //!< Descriptor subtype @ref APP_USBD_CDC_SCS_COUNTRY_SEL.
|
||||
uint8_t iCountryCodeRelDate; //!< Index of a string giving the release date for the implemented ISO 3166 Country Codes.
|
||||
} app_usbd_cdc_desc_country_sel_t;
|
||||
|
||||
/**
|
||||
* @brief CDC Requests
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
/* CDC General */
|
||||
APP_USBD_CDC_REQ_SEND_ENCAPSULATED_COMMAND = 0x00, /**< This request is used to issue a command in the format of the supported control protocol of the Communications Class interface. */
|
||||
APP_USBD_CDC_REQ_GET_ENCAPSULATED_RESPONSE = 0x01, /**< This request is used to request a response in the format of the supported control protocol of the Communications Class interface. */
|
||||
/* CDC PSTN */
|
||||
APP_USBD_CDC_REQ_SET_COMM_FEATURE = 0x02, /**< This request controls the settings for a particular communications feature of a particular target. */
|
||||
APP_USBD_CDC_REQ_GET_COMM_FEATURE = 0x03, /**< This request returns the current settings for the communications feature as selected. */
|
||||
APP_USBD_CDC_REQ_CLEAR_COMM_FEATURE = 0x04, /**< This request controls the settings for a particular communications feature of a particular target, setting the selected feature to its default state. */
|
||||
APP_USBD_CDC_REQ_SET_AUX_LINE_STATE = 0x10, /**< This request is used to connect or disconnect a secondary jack to POTS circuit or CODEC, depending on hook state. */
|
||||
APP_USBD_CDC_REQ_SET_HOOK_STATE = 0x11, /**< This request is used to set the necessary PSTN line relay code for on-hook, off-hook, and caller ID states. */
|
||||
APP_USBD_CDC_REQ_PULSE_SETUP = 0x12, /**< This request is used to prepare for a pulse-dialing cycle. */
|
||||
APP_USBD_CDC_REQ_SEND_PULSE = 0x13, /**< This request is used to generate a specified number of make/break pulse cycles. */
|
||||
APP_USBD_CDC_REQ_SET_PULSE_TIME = 0x14, /**< This request sets the timing of the make and break periods for pulse dialing. */
|
||||
APP_USBD_CDC_REQ_RING_AUX_JACK = 0x15, /**< This request is used to generate a ring signal on a secondary phone jack. */
|
||||
APP_USBD_CDC_REQ_SET_LINE_CODING = 0x20, /**< This request allows the host to specify typical asynchronous line-character formatting properties. */
|
||||
APP_USBD_CDC_REQ_GET_LINE_CODING = 0x21, /**< This request allows the host to find out the currently configured line coding. */
|
||||
APP_USBD_CDC_REQ_SET_CONTROL_LINE_STATE = 0x22, /**< This request generates RS-232/V.24 style control signals. */
|
||||
APP_USBD_CDC_REQ_SEND_BREAK = 0x23, /**< This request sends special carrier modulation that generates an RS-232 style break. */
|
||||
APP_USBD_CDC_REQ_SET_RINGER_PARMS = 0x30, /**< This request configures the ringer for the communications device. */
|
||||
APP_USBD_CDC_REQ_GET_RINGER_PARMS = 0x31, /**< This request returns the ringer capabilities of the device and the current status of the device’s ringer. */
|
||||
APP_USBD_CDC_REQ_SET_OPERATION_PARMS = 0x32, /**< Sets the operational mode for the device, between a simple mode, standalone mode and a host centric mode. */
|
||||
APP_USBD_CDC_REQ_GET_OPERATION_PARMS = 0x33, /**< This request gets the current operational mode for the device. */
|
||||
APP_USBD_CDC_REQ_SET_LINE_PARMS = 0x34, /**< This request is used to change the state of the line, corresponding to the interface or master interface of a union to which the command was sent. */
|
||||
APP_USBD_CDC_REQ_GET_LINE_PARMS = 0x35, /**< This request is used to report the state of the line that corresponds to the interface or master interface of a union to which the command was sent. */
|
||||
APP_USBD_CDC_REQ_DIAL_DIGITS = 0x36, /**< This request dials the DTMF digits over the specified line. */
|
||||
} app_usbd_cdc_req_id_t;
|
||||
|
||||
/**
|
||||
* @brief CDC Notifications.
|
||||
*/
|
||||
typedef enum {
|
||||
/* CDC General */
|
||||
APP_USBD_CDC_NOTIF_NETWORK_CONNECTION = 0x00, /**< This notification allows the device to notify the host about network connection status. */
|
||||
APP_USBD_CDC_NOTIF_RESPONSE_AVAILABLE = 0x01, /**< This notification allows the device to notify the host that a response is available.
|
||||
* This response can be retrieved with a subsequent GetEncapsulatedResponse request.
|
||||
_ */
|
||||
APP_USBD_CDC_NOTIF_CONNECTION_SPEED_CHANGE = 0x2A, /**< This notification allows the device to inform the host-networking driver
|
||||
* that a change in either the up-link or the down-link bit rate of the connection has occurred.
|
||||
*/
|
||||
/* CDC PSTN */
|
||||
APP_USBD_CDC_NOTIF_AUX_JACK_HOOK_STATE = 0x08, /**< (DLM) This notification indicates the loop has changed on the auxiliary phone interface of the USB device. */
|
||||
APP_USBD_CDC_NOTIF_RING_DETECT = 0x09, /**< (DLM) This notification indicates ring voltage on the POTS line interface of the USB device. */
|
||||
APP_USBD_CDC_NOTIF_SERIAL_STATE = 0x20, /**< (ACM) This notification sends asynchronous notification of UART status. */
|
||||
APP_USBD_CDC_NOTIF_CALL_STATE_CHANGE = 0x28, /**< (TCM) This notification identifies that a change has occurred to the state of a call on the line corresponding to the interface or union for the line. */
|
||||
APP_USBD_CDC_NOTIF_LINE_STATE_CHANGE = 0x29 /**< (TCM) This notification identifies that a change has occurred to the state of the line corresponding to the interface or master interface of a union sending the notification message. */
|
||||
} app_usbd_cdc_notify_id_t;
|
||||
|
||||
/**
|
||||
* @brief Notification sent via CDC COMM endpoint.
|
||||
* */
|
||||
typedef struct {
|
||||
uint8_t bmRequestType; //!< Request type.
|
||||
uint8_t bmRequest; //!< Request ID @ref app_usbd_cdc_req_id_t.
|
||||
uint16_t wValue; //!< Value field.
|
||||
uint16_t wIndex; //!< Index field.
|
||||
uint16_t wLength; //!< Length of payload following.
|
||||
} app_usbd_cdc_notify_t;
|
||||
|
||||
/**
|
||||
* @brief CDC line coding structure.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t dwDTERate[4]; //!< Line baudrate.
|
||||
uint8_t bCharFormat; //!< Character format @ref app_usbd_cdc_line_stopbit_t.
|
||||
uint8_t bParityType; //!< Parity bits @ref app_usbd_cdc_line_parity_t.
|
||||
uint8_t bDataBits; //!< Number of data bits.
|
||||
} app_usbd_cdc_line_coding_t;
|
||||
|
||||
/**
|
||||
* @brief Possible values of @ref app_usbd_cdc_line_coding_t::bCharFormat.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_LINE_STOPBIT_1 = 0, /**< 1 stop bit. */
|
||||
APP_USBD_CDC_LINE_STOPBIT_1_5 = 1, /**< 1.5 stop bits. */
|
||||
APP_USBD_CDC_LINE_STOPBIT_2 = 2, /**< 2 stop bits. */
|
||||
} app_usbd_cdc_line_stopbit_t;
|
||||
|
||||
/**
|
||||
* @brief Possible values of @ref app_usbd_cdc_line_coding_t::bParityType.
|
||||
*/
|
||||
typedef enum {
|
||||
APP_USBD_CDC_LINE_PARITY_NONE = 0, /**< No parity. */
|
||||
APP_USBD_CDC_LINE_PARITY_ODD = 1, /**< Odd parity. */
|
||||
APP_USBD_CDC_LINE_PARITY_EVEN = 2, /**< Even parity. */
|
||||
APP_USBD_CDC_LINE_PARITY_MARK = 3, /**< Parity forced to 0 (space).*/
|
||||
APP_USBD_CDC_LINE_PARITY_SPACE = 4, /**< Parity forced to 1 (mark). */
|
||||
} app_usbd_cdc_line_parity_t;
|
||||
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
/** @} */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* APP_USBD_TYPES_H__ */
|
||||
|
||||
+130
-130
@@ -1,130 +1,130 @@
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_STRING_CONFIG_H
|
||||
#define APP_USBD_STRING_CONFIG_H
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_string_conf USBD string configuration
|
||||
* @ingroup app_usbd_string_desc
|
||||
*
|
||||
* @brief @tagAPI52840 Configuration of the string module that can be easily affected by the final
|
||||
* user.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Supported languages identifiers
|
||||
*
|
||||
* Comma separated list of supported languages.
|
||||
*/
|
||||
#define APP_USBD_STRINGS_LANGIDS \
|
||||
((uint16_t)APP_USBD_LANG_ENGLISH | (uint16_t)APP_USBD_SUBLANG_ENGLISH_US)
|
||||
|
||||
/**
|
||||
* @brief Manufacturer name string descriptor
|
||||
*
|
||||
* Comma separated list of manufacturer names for each defined language.
|
||||
* Use @ref APP_USBD_STRING_DESC macro to create string descriptor.
|
||||
*
|
||||
* The order of manufacturer names has to be the same like in
|
||||
* @ref APP_USBD_STRINGS_LANGIDS.
|
||||
*/
|
||||
#define APP_USBD_STRINGS_MANUFACTURER \
|
||||
APP_USBD_STRING_DESC("Nordic Semiconductor")
|
||||
|
||||
/**
|
||||
* @brief Define whether @ref APP_USBD_STRINGS_MANUFACTURER is created by @ref APP_USBD_STRING_DESC
|
||||
* or declared as global variable.
|
||||
* */
|
||||
#define APP_USBD_STRINGS_MANUFACTURER_EXTERN 0
|
||||
|
||||
/**
|
||||
* @brief Product name string descriptor
|
||||
*
|
||||
* List of product names defined the same way like in @ref APP_USBD_STRINGS_MANUFACTURER
|
||||
*/
|
||||
#define APP_USBD_STRINGS_PRODUCT \
|
||||
APP_USBD_STRING_DESC("nRF52840 OpenThread Device")
|
||||
|
||||
|
||||
/**
|
||||
* @brief Define whether @ref APP_USBD_STRINGS_PRODUCT is created by @ref APP_USBD_STRING_DESC
|
||||
* or declared as global variable.
|
||||
* */
|
||||
#define APP_USBD_STRINGS_PRODUCT_EXTERN 0
|
||||
|
||||
/**
|
||||
* @brief Serial number string descriptor
|
||||
*
|
||||
* Create serial number string descriptor using @ref APP_USBD_STRING_DESC,
|
||||
* or configure it to point to any internal variable pointer filled with descriptor.
|
||||
*
|
||||
* @note
|
||||
* There is only one SERIAL number inside the library and it is Language independent.
|
||||
*/
|
||||
#define APP_USBD_STRING_SERIAL g_extern_serial_number
|
||||
|
||||
/**
|
||||
* @brief Define whether @ref APP_USBD_STRING_SERIAL is created by @ref APP_USBD_STRING_DESC
|
||||
* or declared as global variable.
|
||||
* */
|
||||
#define APP_USBD_STRING_SERIAL_EXTERN 1
|
||||
|
||||
/**
|
||||
* @brief User strings default values
|
||||
*
|
||||
* This value stores all application specific user strings with its default initialization.
|
||||
* The setup is done by X-macros.
|
||||
* Expected macro parameters:
|
||||
* @code
|
||||
* X(mnemonic, [=str_idx], ...)
|
||||
* @endcode
|
||||
* - @c mnemonic: Mnemonic of the string descriptor that would be added to
|
||||
* @ref app_usbd_string_desc_idx_t enumerator.
|
||||
* - @c str_idx : String index value, may be set or left empty.
|
||||
* For example WinUSB driver requires descriptor to be present on 0xEE index.
|
||||
* Then use X(USBD_STRING_WINUSB, =0xEE, (APP_USBD_STRING_DESC(...)))
|
||||
* - @c ... : List of string descriptors for each defined language.
|
||||
*/
|
||||
#define APP_USBD_STRINGS_USER \
|
||||
X(APP_USER_1, , APP_USBD_STRING_DESC("User 1"))
|
||||
|
||||
/** @} */
|
||||
#endif /* APP_USBD_STRING_CONFIG_H */
|
||||
/**
|
||||
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef APP_USBD_STRING_CONFIG_H
|
||||
#define APP_USBD_STRING_CONFIG_H
|
||||
|
||||
/**
|
||||
* @defgroup app_usbd_string_conf USBD string configuration
|
||||
* @ingroup app_usbd_string_desc
|
||||
*
|
||||
* @brief @tagAPI52840 Configuration of the string module that can be easily affected by the final
|
||||
* user.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Supported languages identifiers
|
||||
*
|
||||
* Comma separated list of supported languages.
|
||||
*/
|
||||
#define APP_USBD_STRINGS_LANGIDS \
|
||||
((uint16_t)APP_USBD_LANG_ENGLISH | (uint16_t)APP_USBD_SUBLANG_ENGLISH_US)
|
||||
|
||||
/**
|
||||
* @brief Manufacturer name string descriptor
|
||||
*
|
||||
* Comma separated list of manufacturer names for each defined language.
|
||||
* Use @ref APP_USBD_STRING_DESC macro to create string descriptor.
|
||||
*
|
||||
* The order of manufacturer names has to be the same like in
|
||||
* @ref APP_USBD_STRINGS_LANGIDS.
|
||||
*/
|
||||
#define APP_USBD_STRINGS_MANUFACTURER \
|
||||
APP_USBD_STRING_DESC("Nordic Semiconductor")
|
||||
|
||||
/**
|
||||
* @brief Define whether @ref APP_USBD_STRINGS_MANUFACTURER is created by @ref APP_USBD_STRING_DESC
|
||||
* or declared as global variable.
|
||||
* */
|
||||
#define APP_USBD_STRINGS_MANUFACTURER_EXTERN 0
|
||||
|
||||
/**
|
||||
* @brief Product name string descriptor
|
||||
*
|
||||
* List of product names defined the same way like in @ref APP_USBD_STRINGS_MANUFACTURER
|
||||
*/
|
||||
#define APP_USBD_STRINGS_PRODUCT \
|
||||
APP_USBD_STRING_DESC("nRF52840 OpenThread Device")
|
||||
|
||||
|
||||
/**
|
||||
* @brief Define whether @ref APP_USBD_STRINGS_PRODUCT is created by @ref APP_USBD_STRING_DESC
|
||||
* or declared as global variable.
|
||||
* */
|
||||
#define APP_USBD_STRINGS_PRODUCT_EXTERN 0
|
||||
|
||||
/**
|
||||
* @brief Serial number string descriptor
|
||||
*
|
||||
* Create serial number string descriptor using @ref APP_USBD_STRING_DESC,
|
||||
* or configure it to point to any internal variable pointer filled with descriptor.
|
||||
*
|
||||
* @note
|
||||
* There is only one SERIAL number inside the library and it is Language independent.
|
||||
*/
|
||||
#define APP_USBD_STRING_SERIAL g_extern_serial_number
|
||||
|
||||
/**
|
||||
* @brief Define whether @ref APP_USBD_STRING_SERIAL is created by @ref APP_USBD_STRING_DESC
|
||||
* or declared as global variable.
|
||||
* */
|
||||
#define APP_USBD_STRING_SERIAL_EXTERN 1
|
||||
|
||||
/**
|
||||
* @brief User strings default values
|
||||
*
|
||||
* This value stores all application specific user strings with its default initialization.
|
||||
* The setup is done by X-macros.
|
||||
* Expected macro parameters:
|
||||
* @code
|
||||
* X(mnemonic, [=str_idx], ...)
|
||||
* @endcode
|
||||
* - @c mnemonic: Mnemonic of the string descriptor that would be added to
|
||||
* @ref app_usbd_string_desc_idx_t enumerator.
|
||||
* - @c str_idx : String index value, may be set or left empty.
|
||||
* For example WinUSB driver requires descriptor to be present on 0xEE index.
|
||||
* Then use X(USBD_STRING_WINUSB, =0xEE, (APP_USBD_STRING_DESC(...)))
|
||||
* - @c ... : List of string descriptors for each defined language.
|
||||
*/
|
||||
#define APP_USBD_STRINGS_USER \
|
||||
X(APP_USER_1, , APP_USBD_STRING_DESC("User 1"))
|
||||
|
||||
/** @} */
|
||||
#endif /* APP_USBD_STRING_CONFIG_H */
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
Copyright (c) 2016 Pietro Gagliardi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
(this is called the MIT License or Expat License; see http://www.opensource.org/licenses/MIT)
|
||||
Copyright (c) 2016 Pietro Gagliardi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
(this is called the MIT License or Expat License; see http://www.opensource.org/licenses/MIT)
|
||||
|
||||
+350
-350
@@ -1,350 +1,350 @@
|
||||
// utf by pietro gagliardi (andlabs) — https://github.com/andlabs/utf/
|
||||
// 10 november 2016
|
||||
#include "utf.h"
|
||||
|
||||
// this code imitates Go's unicode/utf8 and unicode/utf16
|
||||
// the biggest difference is that a rune is unsigned instead of signed (because Go guarantees what a right shift on a signed number will do, whereas C does not)
|
||||
// it is also an imitation so we can license it under looser terms than the Go source
|
||||
#define badrune 0xFFFD
|
||||
|
||||
// encoded must be at most 4 bytes
|
||||
// TODO clean this code up somehow
|
||||
size_t utf8EncodeRune(uint32_t rune, char *encoded)
|
||||
{
|
||||
uint8_t b;
|
||||
uint8_t c = 0;
|
||||
uint8_t d = 0;
|
||||
uint8_t e = 0;
|
||||
size_t n;
|
||||
|
||||
// not in the valid range for Unicode
|
||||
if (rune > 0x10FFFF)
|
||||
rune = badrune;
|
||||
// surrogate runes cannot be encoded
|
||||
if (rune >= 0xD800 && rune < 0xE000)
|
||||
rune = badrune;
|
||||
|
||||
if (rune < 0x80) { // ASCII bytes represent themselves
|
||||
b = (uint8_t) (rune & 0xFF);
|
||||
n = 1;
|
||||
goto done;
|
||||
}
|
||||
if (rune < 0x800) { // two-byte encoding
|
||||
c = (uint8_t) (rune & 0x3F);
|
||||
c |= 0x80;
|
||||
rune >>= 6;
|
||||
b = (uint8_t) (rune & 0x1F);
|
||||
b |= 0xC0;
|
||||
n = 2;
|
||||
goto done;
|
||||
}
|
||||
if (rune < 0x10000) { // three-byte encoding
|
||||
d = (uint8_t) (rune & 0x3F);
|
||||
d |= 0x80;
|
||||
rune >>= 6;
|
||||
c = (uint8_t) (rune & 0x3F);
|
||||
c |= 0x80;
|
||||
rune >>= 6;
|
||||
b = (uint8_t) (rune & 0x0F);
|
||||
b |= 0xE0;
|
||||
n = 3;
|
||||
goto done;
|
||||
}
|
||||
// otherwise use a four-byte encoding
|
||||
e = (uint8_t) (rune & 0x3F);
|
||||
e |= 0x80;
|
||||
rune >>= 6;
|
||||
d = (uint8_t) (rune & 0x3F);
|
||||
d |= 0x80;
|
||||
rune >>= 6;
|
||||
c = (uint8_t) (rune & 0x3F);
|
||||
c |= 0x80;
|
||||
rune >>= 6;
|
||||
b = (uint8_t) (rune & 0x07);
|
||||
b |= 0xF0;
|
||||
n = 4;
|
||||
|
||||
done:
|
||||
encoded[0] = b;
|
||||
if (n > 1)
|
||||
encoded[1] = c;
|
||||
if (n > 2)
|
||||
encoded[2] = d;
|
||||
if (n > 3)
|
||||
encoded[3] = e;
|
||||
return n;
|
||||
}
|
||||
|
||||
const char *utf8DecodeRune(const char *s, size_t nElem, uint32_t *rune)
|
||||
{
|
||||
uint8_t b, c;
|
||||
uint8_t lowestAllowed, highestAllowed;
|
||||
size_t i, expected;
|
||||
int bad;
|
||||
|
||||
b = (uint8_t) (*s);
|
||||
if (b < 0x80) { // ASCII bytes represent themselves
|
||||
*rune = b;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
// 0xC0 and 0xC1 cover 2-byte overlong equivalents
|
||||
// 0xF5 to 0xFD cover values > 0x10FFFF
|
||||
// 0xFE and 0xFF were never defined (always illegal)
|
||||
if (b < 0xC2 || b > 0xF4) { // invalid
|
||||
*rune = badrune;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
|
||||
// this determines the range of allowed first continuation bytes
|
||||
lowestAllowed = 0x80;
|
||||
highestAllowed = 0xBF;
|
||||
switch (b) {
|
||||
case 0xE0:
|
||||
// disallow 3-byte overlong equivalents
|
||||
lowestAllowed = 0xA0;
|
||||
break;
|
||||
case 0xED:
|
||||
// disallow surrogate characters
|
||||
highestAllowed = 0x9F;
|
||||
break;
|
||||
case 0xF0:
|
||||
// disallow 4-byte overlong equivalents
|
||||
lowestAllowed = 0x90;
|
||||
break;
|
||||
case 0xF4:
|
||||
// disallow values > 0x10FFFF
|
||||
highestAllowed = 0x8F;
|
||||
break;
|
||||
}
|
||||
|
||||
// and this determines how many continuation bytes are expected
|
||||
expected = 1;
|
||||
if (b >= 0xE0)
|
||||
expected++;
|
||||
if (b >= 0xF0)
|
||||
expected++;
|
||||
if (nElem != 0) { // are there enough bytes?
|
||||
nElem--;
|
||||
if (nElem < expected) { // nope
|
||||
*rune = badrune;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
// ensure that everything is correct
|
||||
// if not, **only** consume the initial byte
|
||||
bad = 0;
|
||||
for (i = 0; i < expected; i++) {
|
||||
c = (uint8_t) (s[1 + i]);
|
||||
if (c < lowestAllowed || c > highestAllowed) {
|
||||
bad = 1;
|
||||
break;
|
||||
}
|
||||
// the old lowestAllowed and highestAllowed is only for the first continuation byte
|
||||
lowestAllowed = 0x80;
|
||||
highestAllowed = 0xBF;
|
||||
}
|
||||
if (bad) {
|
||||
*rune = badrune;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
|
||||
// now do the topmost bits
|
||||
if (b < 0xE0)
|
||||
*rune = b & 0x1F;
|
||||
else if (b < 0xF0)
|
||||
*rune = b & 0x0F;
|
||||
else
|
||||
*rune = b & 0x07;
|
||||
s++; // we can finally move on
|
||||
|
||||
// now do the continuation bytes
|
||||
for (; expected; expected--) {
|
||||
c = (uint8_t) (*s);
|
||||
s++;
|
||||
c &= 0x3F; // strip continuation bits
|
||||
*rune <<= 6;
|
||||
*rune |= c;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
// encoded must have at most 2 elements
|
||||
size_t utf16EncodeRune(uint32_t rune, uint16_t *encoded)
|
||||
{
|
||||
uint16_t low, high;
|
||||
|
||||
// not in the valid range for Unicode
|
||||
if (rune > 0x10FFFF)
|
||||
rune = badrune;
|
||||
// surrogate runes cannot be encoded
|
||||
if (rune >= 0xD800 && rune < 0xE000)
|
||||
rune = badrune;
|
||||
|
||||
if (rune < 0x10000) {
|
||||
encoded[0] = (uint16_t) rune;
|
||||
return 1;
|
||||
}
|
||||
|
||||
rune -= 0x10000;
|
||||
low = (uint16_t) (rune & 0x3FF);
|
||||
rune >>= 10;
|
||||
high = (uint16_t) (rune & 0x3FF);
|
||||
encoded[0] = high | 0xD800;
|
||||
encoded[1] = low | 0xDC00;
|
||||
return 2;
|
||||
}
|
||||
|
||||
// TODO see if this can be cleaned up somehow
|
||||
const uint16_t *utf16DecodeRune(const uint16_t *s, size_t nElem, uint32_t *rune)
|
||||
{
|
||||
uint16_t high, low;
|
||||
|
||||
if (*s < 0xD800 || *s >= 0xE000) {
|
||||
// self-representing character
|
||||
*rune = *s;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
if (*s >= 0xDC00) {
|
||||
// out-of-order surrogates
|
||||
*rune = badrune;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
if (nElem == 1) { // not enough elements
|
||||
*rune = badrune;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
high = *s;
|
||||
high &= 0x3FF;
|
||||
if (s[1] < 0xDC00 || s[1] >= 0xE000) {
|
||||
// bad surrogate pair
|
||||
*rune = badrune;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
s++;
|
||||
low = *s;
|
||||
s++;
|
||||
low &= 0x3FF;
|
||||
*rune = high;
|
||||
*rune <<= 10;
|
||||
*rune |= low;
|
||||
*rune += 0x10000;
|
||||
return s;
|
||||
}
|
||||
|
||||
// TODO find a way to reduce the code in all of these somehow
|
||||
// TODO find a way to remove u as well
|
||||
size_t utf8RuneCount(const char *s, size_t nElem)
|
||||
{
|
||||
size_t len;
|
||||
uint32_t rune;
|
||||
|
||||
if (nElem != 0) {
|
||||
const char *t, *u;
|
||||
|
||||
len = 0;
|
||||
t = s;
|
||||
while (nElem != 0) {
|
||||
u = utf8DecodeRune(t, nElem, &rune);
|
||||
len++;
|
||||
nElem -= u - t;
|
||||
t = u;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
len = 0;
|
||||
while (*s) {
|
||||
s = utf8DecodeRune(s, nElem, &rune);
|
||||
len++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t utf8UTF16Count(const char *s, size_t nElem)
|
||||
{
|
||||
size_t len;
|
||||
uint32_t rune;
|
||||
uint16_t encoded[2];
|
||||
|
||||
if (nElem != 0) {
|
||||
const char *t, *u;
|
||||
|
||||
len = 0;
|
||||
t = s;
|
||||
while (nElem != 0) {
|
||||
u = utf8DecodeRune(t, nElem, &rune);
|
||||
len += utf16EncodeRune(rune, encoded);
|
||||
nElem -= u - t;
|
||||
t = u;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
len = 0;
|
||||
while (*s) {
|
||||
s = utf8DecodeRune(s, nElem, &rune);
|
||||
len += utf16EncodeRune(rune, encoded);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t utf16RuneCount(const uint16_t *s, size_t nElem)
|
||||
{
|
||||
size_t len;
|
||||
uint32_t rune;
|
||||
|
||||
if (nElem != 0) {
|
||||
const uint16_t *t, *u;
|
||||
|
||||
len = 0;
|
||||
t = s;
|
||||
while (nElem != 0) {
|
||||
u = utf16DecodeRune(t, nElem, &rune);
|
||||
len++;
|
||||
nElem -= u - t;
|
||||
t = u;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
len = 0;
|
||||
while (*s) {
|
||||
s = utf16DecodeRune(s, nElem, &rune);
|
||||
len++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t utf16UTF8Count(const uint16_t *s, size_t nElem)
|
||||
{
|
||||
size_t len;
|
||||
uint32_t rune;
|
||||
char encoded[4];
|
||||
|
||||
if (nElem != 0) {
|
||||
const uint16_t *t, *u;
|
||||
|
||||
len = 0;
|
||||
t = s;
|
||||
while (nElem != 0) {
|
||||
u = utf16DecodeRune(t, nElem, &rune);
|
||||
len += utf8EncodeRune(rune, encoded);
|
||||
nElem -= u - t;
|
||||
t = u;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
len = 0;
|
||||
while (*s) {
|
||||
s = utf16DecodeRune(s, nElem, &rune);
|
||||
len += utf8EncodeRune(rune, encoded);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
// utf by pietro gagliardi (andlabs) — https://github.com/andlabs/utf/
|
||||
// 10 november 2016
|
||||
#include "utf.h"
|
||||
|
||||
// this code imitates Go's unicode/utf8 and unicode/utf16
|
||||
// the biggest difference is that a rune is unsigned instead of signed (because Go guarantees what a right shift on a signed number will do, whereas C does not)
|
||||
// it is also an imitation so we can license it under looser terms than the Go source
|
||||
#define badrune 0xFFFD
|
||||
|
||||
// encoded must be at most 4 bytes
|
||||
// TODO clean this code up somehow
|
||||
size_t utf8EncodeRune(uint32_t rune, char *encoded)
|
||||
{
|
||||
uint8_t b;
|
||||
uint8_t c = 0;
|
||||
uint8_t d = 0;
|
||||
uint8_t e = 0;
|
||||
size_t n;
|
||||
|
||||
// not in the valid range for Unicode
|
||||
if (rune > 0x10FFFF)
|
||||
rune = badrune;
|
||||
// surrogate runes cannot be encoded
|
||||
if (rune >= 0xD800 && rune < 0xE000)
|
||||
rune = badrune;
|
||||
|
||||
if (rune < 0x80) { // ASCII bytes represent themselves
|
||||
b = (uint8_t) (rune & 0xFF);
|
||||
n = 1;
|
||||
goto done;
|
||||
}
|
||||
if (rune < 0x800) { // two-byte encoding
|
||||
c = (uint8_t) (rune & 0x3F);
|
||||
c |= 0x80;
|
||||
rune >>= 6;
|
||||
b = (uint8_t) (rune & 0x1F);
|
||||
b |= 0xC0;
|
||||
n = 2;
|
||||
goto done;
|
||||
}
|
||||
if (rune < 0x10000) { // three-byte encoding
|
||||
d = (uint8_t) (rune & 0x3F);
|
||||
d |= 0x80;
|
||||
rune >>= 6;
|
||||
c = (uint8_t) (rune & 0x3F);
|
||||
c |= 0x80;
|
||||
rune >>= 6;
|
||||
b = (uint8_t) (rune & 0x0F);
|
||||
b |= 0xE0;
|
||||
n = 3;
|
||||
goto done;
|
||||
}
|
||||
// otherwise use a four-byte encoding
|
||||
e = (uint8_t) (rune & 0x3F);
|
||||
e |= 0x80;
|
||||
rune >>= 6;
|
||||
d = (uint8_t) (rune & 0x3F);
|
||||
d |= 0x80;
|
||||
rune >>= 6;
|
||||
c = (uint8_t) (rune & 0x3F);
|
||||
c |= 0x80;
|
||||
rune >>= 6;
|
||||
b = (uint8_t) (rune & 0x07);
|
||||
b |= 0xF0;
|
||||
n = 4;
|
||||
|
||||
done:
|
||||
encoded[0] = b;
|
||||
if (n > 1)
|
||||
encoded[1] = c;
|
||||
if (n > 2)
|
||||
encoded[2] = d;
|
||||
if (n > 3)
|
||||
encoded[3] = e;
|
||||
return n;
|
||||
}
|
||||
|
||||
const char *utf8DecodeRune(const char *s, size_t nElem, uint32_t *rune)
|
||||
{
|
||||
uint8_t b, c;
|
||||
uint8_t lowestAllowed, highestAllowed;
|
||||
size_t i, expected;
|
||||
int bad;
|
||||
|
||||
b = (uint8_t) (*s);
|
||||
if (b < 0x80) { // ASCII bytes represent themselves
|
||||
*rune = b;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
// 0xC0 and 0xC1 cover 2-byte overlong equivalents
|
||||
// 0xF5 to 0xFD cover values > 0x10FFFF
|
||||
// 0xFE and 0xFF were never defined (always illegal)
|
||||
if (b < 0xC2 || b > 0xF4) { // invalid
|
||||
*rune = badrune;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
|
||||
// this determines the range of allowed first continuation bytes
|
||||
lowestAllowed = 0x80;
|
||||
highestAllowed = 0xBF;
|
||||
switch (b) {
|
||||
case 0xE0:
|
||||
// disallow 3-byte overlong equivalents
|
||||
lowestAllowed = 0xA0;
|
||||
break;
|
||||
case 0xED:
|
||||
// disallow surrogate characters
|
||||
highestAllowed = 0x9F;
|
||||
break;
|
||||
case 0xF0:
|
||||
// disallow 4-byte overlong equivalents
|
||||
lowestAllowed = 0x90;
|
||||
break;
|
||||
case 0xF4:
|
||||
// disallow values > 0x10FFFF
|
||||
highestAllowed = 0x8F;
|
||||
break;
|
||||
}
|
||||
|
||||
// and this determines how many continuation bytes are expected
|
||||
expected = 1;
|
||||
if (b >= 0xE0)
|
||||
expected++;
|
||||
if (b >= 0xF0)
|
||||
expected++;
|
||||
if (nElem != 0) { // are there enough bytes?
|
||||
nElem--;
|
||||
if (nElem < expected) { // nope
|
||||
*rune = badrune;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
// ensure that everything is correct
|
||||
// if not, **only** consume the initial byte
|
||||
bad = 0;
|
||||
for (i = 0; i < expected; i++) {
|
||||
c = (uint8_t) (s[1 + i]);
|
||||
if (c < lowestAllowed || c > highestAllowed) {
|
||||
bad = 1;
|
||||
break;
|
||||
}
|
||||
// the old lowestAllowed and highestAllowed is only for the first continuation byte
|
||||
lowestAllowed = 0x80;
|
||||
highestAllowed = 0xBF;
|
||||
}
|
||||
if (bad) {
|
||||
*rune = badrune;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
|
||||
// now do the topmost bits
|
||||
if (b < 0xE0)
|
||||
*rune = b & 0x1F;
|
||||
else if (b < 0xF0)
|
||||
*rune = b & 0x0F;
|
||||
else
|
||||
*rune = b & 0x07;
|
||||
s++; // we can finally move on
|
||||
|
||||
// now do the continuation bytes
|
||||
for (; expected; expected--) {
|
||||
c = (uint8_t) (*s);
|
||||
s++;
|
||||
c &= 0x3F; // strip continuation bits
|
||||
*rune <<= 6;
|
||||
*rune |= c;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
// encoded must have at most 2 elements
|
||||
size_t utf16EncodeRune(uint32_t rune, uint16_t *encoded)
|
||||
{
|
||||
uint16_t low, high;
|
||||
|
||||
// not in the valid range for Unicode
|
||||
if (rune > 0x10FFFF)
|
||||
rune = badrune;
|
||||
// surrogate runes cannot be encoded
|
||||
if (rune >= 0xD800 && rune < 0xE000)
|
||||
rune = badrune;
|
||||
|
||||
if (rune < 0x10000) {
|
||||
encoded[0] = (uint16_t) rune;
|
||||
return 1;
|
||||
}
|
||||
|
||||
rune -= 0x10000;
|
||||
low = (uint16_t) (rune & 0x3FF);
|
||||
rune >>= 10;
|
||||
high = (uint16_t) (rune & 0x3FF);
|
||||
encoded[0] = high | 0xD800;
|
||||
encoded[1] = low | 0xDC00;
|
||||
return 2;
|
||||
}
|
||||
|
||||
// TODO see if this can be cleaned up somehow
|
||||
const uint16_t *utf16DecodeRune(const uint16_t *s, size_t nElem, uint32_t *rune)
|
||||
{
|
||||
uint16_t high, low;
|
||||
|
||||
if (*s < 0xD800 || *s >= 0xE000) {
|
||||
// self-representing character
|
||||
*rune = *s;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
if (*s >= 0xDC00) {
|
||||
// out-of-order surrogates
|
||||
*rune = badrune;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
if (nElem == 1) { // not enough elements
|
||||
*rune = badrune;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
high = *s;
|
||||
high &= 0x3FF;
|
||||
if (s[1] < 0xDC00 || s[1] >= 0xE000) {
|
||||
// bad surrogate pair
|
||||
*rune = badrune;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
s++;
|
||||
low = *s;
|
||||
s++;
|
||||
low &= 0x3FF;
|
||||
*rune = high;
|
||||
*rune <<= 10;
|
||||
*rune |= low;
|
||||
*rune += 0x10000;
|
||||
return s;
|
||||
}
|
||||
|
||||
// TODO find a way to reduce the code in all of these somehow
|
||||
// TODO find a way to remove u as well
|
||||
size_t utf8RuneCount(const char *s, size_t nElem)
|
||||
{
|
||||
size_t len;
|
||||
uint32_t rune;
|
||||
|
||||
if (nElem != 0) {
|
||||
const char *t, *u;
|
||||
|
||||
len = 0;
|
||||
t = s;
|
||||
while (nElem != 0) {
|
||||
u = utf8DecodeRune(t, nElem, &rune);
|
||||
len++;
|
||||
nElem -= u - t;
|
||||
t = u;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
len = 0;
|
||||
while (*s) {
|
||||
s = utf8DecodeRune(s, nElem, &rune);
|
||||
len++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t utf8UTF16Count(const char *s, size_t nElem)
|
||||
{
|
||||
size_t len;
|
||||
uint32_t rune;
|
||||
uint16_t encoded[2];
|
||||
|
||||
if (nElem != 0) {
|
||||
const char *t, *u;
|
||||
|
||||
len = 0;
|
||||
t = s;
|
||||
while (nElem != 0) {
|
||||
u = utf8DecodeRune(t, nElem, &rune);
|
||||
len += utf16EncodeRune(rune, encoded);
|
||||
nElem -= u - t;
|
||||
t = u;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
len = 0;
|
||||
while (*s) {
|
||||
s = utf8DecodeRune(s, nElem, &rune);
|
||||
len += utf16EncodeRune(rune, encoded);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t utf16RuneCount(const uint16_t *s, size_t nElem)
|
||||
{
|
||||
size_t len;
|
||||
uint32_t rune;
|
||||
|
||||
if (nElem != 0) {
|
||||
const uint16_t *t, *u;
|
||||
|
||||
len = 0;
|
||||
t = s;
|
||||
while (nElem != 0) {
|
||||
u = utf16DecodeRune(t, nElem, &rune);
|
||||
len++;
|
||||
nElem -= u - t;
|
||||
t = u;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
len = 0;
|
||||
while (*s) {
|
||||
s = utf16DecodeRune(s, nElem, &rune);
|
||||
len++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t utf16UTF8Count(const uint16_t *s, size_t nElem)
|
||||
{
|
||||
size_t len;
|
||||
uint32_t rune;
|
||||
char encoded[4];
|
||||
|
||||
if (nElem != 0) {
|
||||
const uint16_t *t, *u;
|
||||
|
||||
len = 0;
|
||||
t = s;
|
||||
while (nElem != 0) {
|
||||
u = utf16DecodeRune(t, nElem, &rune);
|
||||
len += utf8EncodeRune(rune, encoded);
|
||||
nElem -= u - t;
|
||||
t = u;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
len = 0;
|
||||
while (*s) {
|
||||
s = utf16DecodeRune(s, nElem, &rune);
|
||||
len += utf8EncodeRune(rune, encoded);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
+61
-61
@@ -1,61 +1,61 @@
|
||||
// utf by pietro gagliardi (andlabs) — https://github.com/andlabs/utf/
|
||||
// 10 november 2016
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// if nElem == 0, assume the buffer has no upper limit and is '\0' terminated
|
||||
// otherwise, assume buffer is NOT '\0' terminated but is bounded by nElem *elements*
|
||||
|
||||
extern size_t utf8EncodeRune(uint32_t rune, char *encoded);
|
||||
extern const char *utf8DecodeRune(const char *s, size_t nElem, uint32_t *rune);
|
||||
extern size_t utf16EncodeRune(uint32_t rune, uint16_t *encoded);
|
||||
extern const uint16_t *utf16DecodeRune(const uint16_t *s, size_t nElem, uint32_t *rune);
|
||||
|
||||
extern size_t utf8RuneCount(const char *s, size_t nElem);
|
||||
extern size_t utf8UTF16Count(const char *s, size_t nElem);
|
||||
extern size_t utf16RuneCount(const uint16_t *s, size_t nElem);
|
||||
extern size_t utf16UTF8Count(const uint16_t *s, size_t nElem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
// Provide overloads on Windows for using these functions with wchar_t and WCHAR when wchar_t is a keyword in C++ mode (the default).
|
||||
// Otherwise, you'd need to cast to pass a wchar_t pointer, WCHAR pointer, or equivalent to these functions.
|
||||
// We use __wchar_t to be independent of the setting; see https://blogs.msdn.microsoft.com/oldnewthing/20161201-00/?p=94836 (ironically posted one day after I initially wrote this code!).
|
||||
// TODO check this on MinGW-w64
|
||||
// TODO check this under /Wall
|
||||
// TODO C-style casts enough? or will that fail in /Wall?
|
||||
// TODO same for UniChar/unichar on Mac? if both are unsigned then we have nothing to worry about
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
inline size_t utf16EncodeRune(uint32_t rune, __wchar_t *encoded)
|
||||
{
|
||||
return utf16EncodeRune(rune, reinterpret_cast<uint16_t *>(encoded));
|
||||
}
|
||||
|
||||
inline const __wchar_t *utf16DecodeRune(const __wchar_t *s, size_t nElem, uint32_t *rune)
|
||||
{
|
||||
const uint16_t *ret;
|
||||
|
||||
ret = utf16DecodeRune(reinterpret_cast<const uint16_t *>(s), nElem, rune);
|
||||
return reinterpret_cast<const __wchar_t *>(ret);
|
||||
}
|
||||
|
||||
inline size_t utf16RuneCount(const __wchar_t *s, size_t nElem)
|
||||
{
|
||||
return utf16RuneCount(reinterpret_cast<const uint16_t *>(s), nElem);
|
||||
}
|
||||
|
||||
inline size_t utf16UTF8Count(const __wchar_t *s, size_t nElem)
|
||||
{
|
||||
return utf16UTF8Count(reinterpret_cast<const uint16_t *>(s), nElem);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
// utf by pietro gagliardi (andlabs) — https://github.com/andlabs/utf/
|
||||
// 10 november 2016
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// if nElem == 0, assume the buffer has no upper limit and is '\0' terminated
|
||||
// otherwise, assume buffer is NOT '\0' terminated but is bounded by nElem *elements*
|
||||
|
||||
extern size_t utf8EncodeRune(uint32_t rune, char *encoded);
|
||||
extern const char *utf8DecodeRune(const char *s, size_t nElem, uint32_t *rune);
|
||||
extern size_t utf16EncodeRune(uint32_t rune, uint16_t *encoded);
|
||||
extern const uint16_t *utf16DecodeRune(const uint16_t *s, size_t nElem, uint32_t *rune);
|
||||
|
||||
extern size_t utf8RuneCount(const char *s, size_t nElem);
|
||||
extern size_t utf8UTF16Count(const char *s, size_t nElem);
|
||||
extern size_t utf16RuneCount(const uint16_t *s, size_t nElem);
|
||||
extern size_t utf16UTF8Count(const uint16_t *s, size_t nElem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
// Provide overloads on Windows for using these functions with wchar_t and WCHAR when wchar_t is a keyword in C++ mode (the default).
|
||||
// Otherwise, you'd need to cast to pass a wchar_t pointer, WCHAR pointer, or equivalent to these functions.
|
||||
// We use __wchar_t to be independent of the setting; see https://blogs.msdn.microsoft.com/oldnewthing/20161201-00/?p=94836 (ironically posted one day after I initially wrote this code!).
|
||||
// TODO check this on MinGW-w64
|
||||
// TODO check this under /Wall
|
||||
// TODO C-style casts enough? or will that fail in /Wall?
|
||||
// TODO same for UniChar/unichar on Mac? if both are unsigned then we have nothing to worry about
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
inline size_t utf16EncodeRune(uint32_t rune, __wchar_t *encoded)
|
||||
{
|
||||
return utf16EncodeRune(rune, reinterpret_cast<uint16_t *>(encoded));
|
||||
}
|
||||
|
||||
inline const __wchar_t *utf16DecodeRune(const __wchar_t *s, size_t nElem, uint32_t *rune)
|
||||
{
|
||||
const uint16_t *ret;
|
||||
|
||||
ret = utf16DecodeRune(reinterpret_cast<const uint16_t *>(s), nElem, rune);
|
||||
return reinterpret_cast<const __wchar_t *>(ret);
|
||||
}
|
||||
|
||||
inline size_t utf16RuneCount(const __wchar_t *s, size_t nElem)
|
||||
{
|
||||
return utf16RuneCount(reinterpret_cast<const uint16_t *>(s), nElem);
|
||||
}
|
||||
|
||||
inline size_t utf16UTF8Count(const __wchar_t *s, size_t nElem)
|
||||
{
|
||||
return utf16UTF8Count(reinterpret_cast<const uint16_t *>(s), nElem);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+35
-35
@@ -1,35 +1,35 @@
|
||||
Copyright (c) 2007 - 2018, Nordic Semiconductor ASA
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form, except as embedded into a Nordic
|
||||
Semiconductor ASA integrated circuit in a product or a software update for
|
||||
such product, must reproduce the above copyright notice, this list of
|
||||
conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
contributors may be used to endorse or promote products derived from this
|
||||
software without specific prior written permission.
|
||||
|
||||
4. This software, with or without modification, must only be used with a
|
||||
Nordic Semiconductor ASA integrated circuit.
|
||||
|
||||
5. Any software provided in binary form under this license must not be reverse
|
||||
engineered, decompiled, modified and/or disassembled.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
Copyright (c) 2007 - 2018, Nordic Semiconductor ASA
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form, except as embedded into a Nordic
|
||||
Semiconductor ASA integrated circuit in a product or a software update for
|
||||
such product, must reproduce the above copyright notice, this list of
|
||||
conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
contributors may be used to endorse or promote products derived from this
|
||||
software without specific prior written permission.
|
||||
|
||||
4. This software, with or without modification, must only be used with a
|
||||
Nordic Semiconductor ASA integrated circuit.
|
||||
|
||||
5. Any software provided in binary form under this license must not be reverse
|
||||
engineered, decompiled, modified and/or disassembled.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
+268
-268
@@ -1,268 +1,268 @@
|
||||
/*
|
||||
* Copyright (c) 2014 - 2017, Nordic Semiconductor ASA
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
@defgroup nrf_mbr_api Master Boot Record API
|
||||
@{
|
||||
|
||||
@brief APIs for updating SoftDevice and BootLoader
|
||||
|
||||
*/
|
||||
|
||||
#ifndef NRF_MBR_H__
|
||||
#define NRF_MBR_H__
|
||||
|
||||
#include "nrf_svc.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup NRF_MBR_DEFINES Defines
|
||||
* @{ */
|
||||
|
||||
/**@brief MBR SVC Base number. */
|
||||
#define MBR_SVC_BASE (0x18)
|
||||
|
||||
/**@brief Page size in words. */
|
||||
#define MBR_PAGE_SIZE_IN_WORDS (1024)
|
||||
|
||||
/** @brief The size that must be reserved for the MBR when a SoftDevice is written to flash.
|
||||
This is the offset where the first byte of the SoftDevice hex file is written. */
|
||||
#define MBR_SIZE (0x1000)
|
||||
|
||||
/** @brief Location (in the flash memory) of the bootloader address. */
|
||||
#define MBR_BOOTLOADER_ADDR (0xFF8)
|
||||
|
||||
/** @brief Location (in UICR) of the bootloader address. */
|
||||
#define MBR_UICR_BOOTLOADER_ADDR (&(NRF_UICR->NRFFW[0]))
|
||||
|
||||
/** @brief Location (in the flash memory) of the address of the MBR parameter page. */
|
||||
#define MBR_PARAM_PAGE_ADDR (0xFFC)
|
||||
|
||||
/** @brief Location (in UICR) of the address of the MBR parameter page. */
|
||||
#define MBR_UICR_PARAM_PAGE_ADDR (&(NRF_UICR->NRFFW[1]))
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @addtogroup NRF_MBR_ENUMS Enumerations
|
||||
* @{ */
|
||||
|
||||
/**@brief nRF Master Boot Record API SVC numbers. */
|
||||
enum NRF_MBR_SVCS
|
||||
{
|
||||
SD_MBR_COMMAND = MBR_SVC_BASE, /**< ::sd_mbr_command */
|
||||
};
|
||||
|
||||
/**@brief Possible values for ::sd_mbr_command_t.command */
|
||||
enum NRF_MBR_COMMANDS
|
||||
{
|
||||
SD_MBR_COMMAND_COPY_BL, /**< Copy a new BootLoader. @see ::sd_mbr_command_copy_bl_t*/
|
||||
SD_MBR_COMMAND_COPY_SD, /**< Copy a new SoftDevice. @see ::sd_mbr_command_copy_sd_t*/
|
||||
SD_MBR_COMMAND_INIT_SD, /**< Initialize forwarding interrupts to SD, and run reset function in SD. Does not require any parameters in ::sd_mbr_command_t params.*/
|
||||
SD_MBR_COMMAND_COMPARE, /**< This command works like memcmp. @see ::sd_mbr_command_compare_t*/
|
||||
SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET, /**< Change the address the MBR starts after a reset. @see ::sd_mbr_command_vector_table_base_set_t*/
|
||||
SD_MBR_COMMAND_RESERVED,
|
||||
SD_MBR_COMMAND_IRQ_FORWARD_ADDRESS_SET, /**< Start forwarding all interrupts to this address. @see ::sd_mbr_command_irq_forward_address_set_t*/
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @addtogroup NRF_MBR_TYPES Types
|
||||
* @{ */
|
||||
|
||||
/**@brief This command copies part of a new SoftDevice
|
||||
*
|
||||
* The destination area is erased before copying.
|
||||
* If dst is in the middle of a flash page, that whole flash page will be erased.
|
||||
* If (dst+len) is in the middle of a flash page, that whole flash page will be erased.
|
||||
*
|
||||
* The user of this function is responsible for setting the BPROT registers.
|
||||
*
|
||||
* @retval ::NRF_SUCCESS indicates that the contents of the memory blocks where copied correctly.
|
||||
* @retval ::NRF_ERROR_INTERNAL indicates that the contents of the memory blocks where not verified correctly after copying.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t *src; /**< Pointer to the source of data to be copied.*/
|
||||
uint32_t *dst; /**< Pointer to the destination where the content is to be copied.*/
|
||||
uint32_t len; /**< Number of 32 bit words to copy. Must be a multiple of @ref MBR_PAGE_SIZE_IN_WORDS words.*/
|
||||
} sd_mbr_command_copy_sd_t;
|
||||
|
||||
|
||||
/**@brief This command works like memcmp, but takes the length in words.
|
||||
*
|
||||
* @retval ::NRF_SUCCESS indicates that the contents of both memory blocks are equal.
|
||||
* @retval ::NRF_ERROR_NULL indicates that the contents of the memory blocks are not equal.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t *ptr1; /**< Pointer to block of memory. */
|
||||
uint32_t *ptr2; /**< Pointer to block of memory. */
|
||||
uint32_t len; /**< Number of 32 bit words to compare.*/
|
||||
} sd_mbr_command_compare_t;
|
||||
|
||||
|
||||
/**@brief This command copies a new BootLoader.
|
||||
*
|
||||
* The MBR assumes that either @ref MBR_BOOTLOADER_ADDR or @ref MBR_UICR_BOOTLOADER_ADDR is set to
|
||||
* the address where the bootloader will be copied. If both addresses are set, the MBR will prioritize
|
||||
* @ref MBR_BOOTLOADER_ADDR.
|
||||
*
|
||||
* The bootloader destination is erased by this function.
|
||||
* If (destination+bl_len) is in the middle of a flash page, that whole flash page will be erased.
|
||||
*
|
||||
* This command requires that @ref MBR_PARAM_PAGE_ADDR or @ref MBR_UICR_PARAM_PAGE_ADDR is set,
|
||||
* see @ref sd_mbr_command.
|
||||
*
|
||||
* This command will use the flash protect peripheral (BPROT or ACL) to protect the flash that is
|
||||
* not intended to be written.
|
||||
*
|
||||
* On success, this function will not return. It will start the new bootloader from reset-vector as normal.
|
||||
*
|
||||
* @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen.
|
||||
* @retval ::NRF_ERROR_FORBIDDEN if the bootloader address is not set.
|
||||
* @retval ::NRF_ERROR_INVALID_LENGTH if parameters attempts to read or write outside flash area.
|
||||
* @retval ::NRF_ERROR_NO_MEM No MBR parameter page is provided. See @ref sd_mbr_command.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t *bl_src; /**< Pointer to the source of the bootloader to be be copied.*/
|
||||
uint32_t bl_len; /**< Number of 32 bit words to copy for BootLoader. */
|
||||
} sd_mbr_command_copy_bl_t;
|
||||
|
||||
/**@brief Change the address the MBR starts after a reset
|
||||
*
|
||||
* Once this function has been called, this address is where the MBR will start to forward
|
||||
* interrupts to after a reset.
|
||||
*
|
||||
* To restore default forwarding, this function should be called with @ref address set to 0. If a
|
||||
* bootloader is present, interrupts will be forwarded to the bootloader. If not, interrupts will
|
||||
* be forwarded to the SoftDevice.
|
||||
*
|
||||
* The location of a bootloader can be specified in @ref MBR_BOOTLOADER_ADDR or
|
||||
* @ref MBR_UICR_BOOTLOADER_ADDR. If both addresses are set, the MBR will prioritize
|
||||
* @ref MBR_BOOTLOADER_ADDR.
|
||||
*
|
||||
* This command requires that @ref MBR_PARAM_PAGE_ADDR or @ref MBR_UICR_PARAM_PAGE_ADDR is set,
|
||||
* see @ref sd_mbr_command.
|
||||
*
|
||||
* On success, this function will not return. It will reset the device.
|
||||
*
|
||||
* @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen.
|
||||
* @retval ::NRF_ERROR_INVALID_ADDR if parameter address is outside of the flash size.
|
||||
* @retval ::NRF_ERROR_NO_MEM No MBR parameter page is provided. See @ref sd_mbr_command.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t address; /**< The base address of the interrupt vector table for forwarded interrupts.*/
|
||||
} sd_mbr_command_vector_table_base_set_t;
|
||||
|
||||
/**@brief Sets the base address of the interrupt vector table for interrupts forwarded from the MBR
|
||||
*
|
||||
* Unlike sd_mbr_command_vector_table_base_set_t, this function does not reset, and it does not
|
||||
* change where the MBR starts after reset.
|
||||
*
|
||||
* @retval ::NRF_SUCCESS
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t address; /**< The base address of the interrupt vector table for forwarded interrupts.*/
|
||||
} sd_mbr_command_irq_forward_address_set_t;
|
||||
|
||||
/**@brief Input structure containing data used when calling ::sd_mbr_command
|
||||
*
|
||||
* Depending on what command value that is set, the corresponding params value type must also be
|
||||
* set. See @ref NRF_MBR_COMMANDS for command types and corresponding params value type. If command
|
||||
* @ref SD_MBR_COMMAND_INIT_SD is set, it is not necessary to set any values under params.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t command; /**< Type of command to be issued. See @ref NRF_MBR_COMMANDS. */
|
||||
union
|
||||
{
|
||||
sd_mbr_command_copy_sd_t copy_sd; /**< Parameters for copy SoftDevice.*/
|
||||
sd_mbr_command_compare_t compare; /**< Parameters for verify.*/
|
||||
sd_mbr_command_copy_bl_t copy_bl; /**< Parameters for copy BootLoader. Requires parameter page. */
|
||||
sd_mbr_command_vector_table_base_set_t base_set; /**< Parameters for vector table base set. Requires parameter page.*/
|
||||
sd_mbr_command_irq_forward_address_set_t irq_forward_address_set; /**< Parameters for irq forward address set*/
|
||||
} params; /**< Command parameters. */
|
||||
} sd_mbr_command_t;
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @addtogroup NRF_MBR_FUNCTIONS Functions
|
||||
* @{ */
|
||||
|
||||
/**@brief Issue Master Boot Record commands
|
||||
*
|
||||
* Commands used when updating a SoftDevice and bootloader.
|
||||
*
|
||||
* The @ref SD_MBR_COMMAND_COPY_BL and @ref SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET requires
|
||||
* parameters to be retained by the MBR when resetting the IC. This is done in a separate flash
|
||||
* page. The location of the flash page should be provided by the application in either
|
||||
* @ref MBR_PARAM_PAGE_ADDR or @ref MBR_UICR_PARAM_PAGE_ADDR. If both addresses are set, the MBR
|
||||
* will prioritize @ref MBR_PARAM_PAGE_ADDR. This page will be cleared by the MBR and is used to
|
||||
* store the command before reset. When an address is specified, the page it refers to must not be
|
||||
* used by the application. If no address is provided by the application, i.e. both
|
||||
* @ref MBR_PARAM_PAGE_ADDR and @ref MBR_UICR_PARAM_PAGE_ADDR is 0xFFFFFFFF, MBR commands which use
|
||||
* flash will be unavailable and return @ref NRF_ERROR_NO_MEM.
|
||||
*
|
||||
* @param[in] param Pointer to a struct describing the command.
|
||||
*
|
||||
* @note For a complete set of return values, see ::sd_mbr_command_copy_sd_t,
|
||||
* ::sd_mbr_command_copy_bl_t, ::sd_mbr_command_compare_t,
|
||||
* ::sd_mbr_command_vector_table_base_set_t, ::sd_mbr_command_irq_forward_address_set_t
|
||||
*
|
||||
* @retval ::NRF_ERROR_NO_MEM No MBR parameter page provided
|
||||
* @retval ::NRF_ERROR_INVALID_PARAM if an invalid command is given.
|
||||
*/
|
||||
SVCALL(SD_MBR_COMMAND, uint32_t, sd_mbr_command(sd_mbr_command_t* param));
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // NRF_MBR_H__
|
||||
|
||||
/**
|
||||
@}
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2014 - 2017, Nordic Semiconductor ASA
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
@defgroup nrf_mbr_api Master Boot Record API
|
||||
@{
|
||||
|
||||
@brief APIs for updating SoftDevice and BootLoader
|
||||
|
||||
*/
|
||||
|
||||
#ifndef NRF_MBR_H__
|
||||
#define NRF_MBR_H__
|
||||
|
||||
#include "nrf_svc.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup NRF_MBR_DEFINES Defines
|
||||
* @{ */
|
||||
|
||||
/**@brief MBR SVC Base number. */
|
||||
#define MBR_SVC_BASE (0x18)
|
||||
|
||||
/**@brief Page size in words. */
|
||||
#define MBR_PAGE_SIZE_IN_WORDS (1024)
|
||||
|
||||
/** @brief The size that must be reserved for the MBR when a SoftDevice is written to flash.
|
||||
This is the offset where the first byte of the SoftDevice hex file is written. */
|
||||
#define MBR_SIZE (0x1000)
|
||||
|
||||
/** @brief Location (in the flash memory) of the bootloader address. */
|
||||
#define MBR_BOOTLOADER_ADDR (0xFF8)
|
||||
|
||||
/** @brief Location (in UICR) of the bootloader address. */
|
||||
#define MBR_UICR_BOOTLOADER_ADDR (&(NRF_UICR->NRFFW[0]))
|
||||
|
||||
/** @brief Location (in the flash memory) of the address of the MBR parameter page. */
|
||||
#define MBR_PARAM_PAGE_ADDR (0xFFC)
|
||||
|
||||
/** @brief Location (in UICR) of the address of the MBR parameter page. */
|
||||
#define MBR_UICR_PARAM_PAGE_ADDR (&(NRF_UICR->NRFFW[1]))
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @addtogroup NRF_MBR_ENUMS Enumerations
|
||||
* @{ */
|
||||
|
||||
/**@brief nRF Master Boot Record API SVC numbers. */
|
||||
enum NRF_MBR_SVCS
|
||||
{
|
||||
SD_MBR_COMMAND = MBR_SVC_BASE, /**< ::sd_mbr_command */
|
||||
};
|
||||
|
||||
/**@brief Possible values for ::sd_mbr_command_t.command */
|
||||
enum NRF_MBR_COMMANDS
|
||||
{
|
||||
SD_MBR_COMMAND_COPY_BL, /**< Copy a new BootLoader. @see ::sd_mbr_command_copy_bl_t*/
|
||||
SD_MBR_COMMAND_COPY_SD, /**< Copy a new SoftDevice. @see ::sd_mbr_command_copy_sd_t*/
|
||||
SD_MBR_COMMAND_INIT_SD, /**< Initialize forwarding interrupts to SD, and run reset function in SD. Does not require any parameters in ::sd_mbr_command_t params.*/
|
||||
SD_MBR_COMMAND_COMPARE, /**< This command works like memcmp. @see ::sd_mbr_command_compare_t*/
|
||||
SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET, /**< Change the address the MBR starts after a reset. @see ::sd_mbr_command_vector_table_base_set_t*/
|
||||
SD_MBR_COMMAND_RESERVED,
|
||||
SD_MBR_COMMAND_IRQ_FORWARD_ADDRESS_SET, /**< Start forwarding all interrupts to this address. @see ::sd_mbr_command_irq_forward_address_set_t*/
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @addtogroup NRF_MBR_TYPES Types
|
||||
* @{ */
|
||||
|
||||
/**@brief This command copies part of a new SoftDevice
|
||||
*
|
||||
* The destination area is erased before copying.
|
||||
* If dst is in the middle of a flash page, that whole flash page will be erased.
|
||||
* If (dst+len) is in the middle of a flash page, that whole flash page will be erased.
|
||||
*
|
||||
* The user of this function is responsible for setting the BPROT registers.
|
||||
*
|
||||
* @retval ::NRF_SUCCESS indicates that the contents of the memory blocks where copied correctly.
|
||||
* @retval ::NRF_ERROR_INTERNAL indicates that the contents of the memory blocks where not verified correctly after copying.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t *src; /**< Pointer to the source of data to be copied.*/
|
||||
uint32_t *dst; /**< Pointer to the destination where the content is to be copied.*/
|
||||
uint32_t len; /**< Number of 32 bit words to copy. Must be a multiple of @ref MBR_PAGE_SIZE_IN_WORDS words.*/
|
||||
} sd_mbr_command_copy_sd_t;
|
||||
|
||||
|
||||
/**@brief This command works like memcmp, but takes the length in words.
|
||||
*
|
||||
* @retval ::NRF_SUCCESS indicates that the contents of both memory blocks are equal.
|
||||
* @retval ::NRF_ERROR_NULL indicates that the contents of the memory blocks are not equal.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t *ptr1; /**< Pointer to block of memory. */
|
||||
uint32_t *ptr2; /**< Pointer to block of memory. */
|
||||
uint32_t len; /**< Number of 32 bit words to compare.*/
|
||||
} sd_mbr_command_compare_t;
|
||||
|
||||
|
||||
/**@brief This command copies a new BootLoader.
|
||||
*
|
||||
* The MBR assumes that either @ref MBR_BOOTLOADER_ADDR or @ref MBR_UICR_BOOTLOADER_ADDR is set to
|
||||
* the address where the bootloader will be copied. If both addresses are set, the MBR will prioritize
|
||||
* @ref MBR_BOOTLOADER_ADDR.
|
||||
*
|
||||
* The bootloader destination is erased by this function.
|
||||
* If (destination+bl_len) is in the middle of a flash page, that whole flash page will be erased.
|
||||
*
|
||||
* This command requires that @ref MBR_PARAM_PAGE_ADDR or @ref MBR_UICR_PARAM_PAGE_ADDR is set,
|
||||
* see @ref sd_mbr_command.
|
||||
*
|
||||
* This command will use the flash protect peripheral (BPROT or ACL) to protect the flash that is
|
||||
* not intended to be written.
|
||||
*
|
||||
* On success, this function will not return. It will start the new bootloader from reset-vector as normal.
|
||||
*
|
||||
* @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen.
|
||||
* @retval ::NRF_ERROR_FORBIDDEN if the bootloader address is not set.
|
||||
* @retval ::NRF_ERROR_INVALID_LENGTH if parameters attempts to read or write outside flash area.
|
||||
* @retval ::NRF_ERROR_NO_MEM No MBR parameter page is provided. See @ref sd_mbr_command.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t *bl_src; /**< Pointer to the source of the bootloader to be be copied.*/
|
||||
uint32_t bl_len; /**< Number of 32 bit words to copy for BootLoader. */
|
||||
} sd_mbr_command_copy_bl_t;
|
||||
|
||||
/**@brief Change the address the MBR starts after a reset
|
||||
*
|
||||
* Once this function has been called, this address is where the MBR will start to forward
|
||||
* interrupts to after a reset.
|
||||
*
|
||||
* To restore default forwarding, this function should be called with @ref address set to 0. If a
|
||||
* bootloader is present, interrupts will be forwarded to the bootloader. If not, interrupts will
|
||||
* be forwarded to the SoftDevice.
|
||||
*
|
||||
* The location of a bootloader can be specified in @ref MBR_BOOTLOADER_ADDR or
|
||||
* @ref MBR_UICR_BOOTLOADER_ADDR. If both addresses are set, the MBR will prioritize
|
||||
* @ref MBR_BOOTLOADER_ADDR.
|
||||
*
|
||||
* This command requires that @ref MBR_PARAM_PAGE_ADDR or @ref MBR_UICR_PARAM_PAGE_ADDR is set,
|
||||
* see @ref sd_mbr_command.
|
||||
*
|
||||
* On success, this function will not return. It will reset the device.
|
||||
*
|
||||
* @retval ::NRF_ERROR_INTERNAL indicates an internal error that should not happen.
|
||||
* @retval ::NRF_ERROR_INVALID_ADDR if parameter address is outside of the flash size.
|
||||
* @retval ::NRF_ERROR_NO_MEM No MBR parameter page is provided. See @ref sd_mbr_command.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t address; /**< The base address of the interrupt vector table for forwarded interrupts.*/
|
||||
} sd_mbr_command_vector_table_base_set_t;
|
||||
|
||||
/**@brief Sets the base address of the interrupt vector table for interrupts forwarded from the MBR
|
||||
*
|
||||
* Unlike sd_mbr_command_vector_table_base_set_t, this function does not reset, and it does not
|
||||
* change where the MBR starts after reset.
|
||||
*
|
||||
* @retval ::NRF_SUCCESS
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t address; /**< The base address of the interrupt vector table for forwarded interrupts.*/
|
||||
} sd_mbr_command_irq_forward_address_set_t;
|
||||
|
||||
/**@brief Input structure containing data used when calling ::sd_mbr_command
|
||||
*
|
||||
* Depending on what command value that is set, the corresponding params value type must also be
|
||||
* set. See @ref NRF_MBR_COMMANDS for command types and corresponding params value type. If command
|
||||
* @ref SD_MBR_COMMAND_INIT_SD is set, it is not necessary to set any values under params.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t command; /**< Type of command to be issued. See @ref NRF_MBR_COMMANDS. */
|
||||
union
|
||||
{
|
||||
sd_mbr_command_copy_sd_t copy_sd; /**< Parameters for copy SoftDevice.*/
|
||||
sd_mbr_command_compare_t compare; /**< Parameters for verify.*/
|
||||
sd_mbr_command_copy_bl_t copy_bl; /**< Parameters for copy BootLoader. Requires parameter page. */
|
||||
sd_mbr_command_vector_table_base_set_t base_set; /**< Parameters for vector table base set. Requires parameter page.*/
|
||||
sd_mbr_command_irq_forward_address_set_t irq_forward_address_set; /**< Parameters for irq forward address set*/
|
||||
} params; /**< Command parameters. */
|
||||
} sd_mbr_command_t;
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @addtogroup NRF_MBR_FUNCTIONS Functions
|
||||
* @{ */
|
||||
|
||||
/**@brief Issue Master Boot Record commands
|
||||
*
|
||||
* Commands used when updating a SoftDevice and bootloader.
|
||||
*
|
||||
* The @ref SD_MBR_COMMAND_COPY_BL and @ref SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET requires
|
||||
* parameters to be retained by the MBR when resetting the IC. This is done in a separate flash
|
||||
* page. The location of the flash page should be provided by the application in either
|
||||
* @ref MBR_PARAM_PAGE_ADDR or @ref MBR_UICR_PARAM_PAGE_ADDR. If both addresses are set, the MBR
|
||||
* will prioritize @ref MBR_PARAM_PAGE_ADDR. This page will be cleared by the MBR and is used to
|
||||
* store the command before reset. When an address is specified, the page it refers to must not be
|
||||
* used by the application. If no address is provided by the application, i.e. both
|
||||
* @ref MBR_PARAM_PAGE_ADDR and @ref MBR_UICR_PARAM_PAGE_ADDR is 0xFFFFFFFF, MBR commands which use
|
||||
* flash will be unavailable and return @ref NRF_ERROR_NO_MEM.
|
||||
*
|
||||
* @param[in] param Pointer to a struct describing the command.
|
||||
*
|
||||
* @note For a complete set of return values, see ::sd_mbr_command_copy_sd_t,
|
||||
* ::sd_mbr_command_copy_bl_t, ::sd_mbr_command_compare_t,
|
||||
* ::sd_mbr_command_vector_table_base_set_t, ::sd_mbr_command_irq_forward_address_set_t
|
||||
*
|
||||
* @retval ::NRF_ERROR_NO_MEM No MBR parameter page provided
|
||||
* @retval ::NRF_ERROR_INVALID_PARAM if an invalid command is given.
|
||||
*/
|
||||
SVCALL(SD_MBR_COMMAND, uint32_t, sd_mbr_command(sd_mbr_command_t* param));
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif // NRF_MBR_H__
|
||||
|
||||
/**
|
||||
@}
|
||||
*/
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* Solutions for real time microcontroller applications *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
|
||||
--------- END-OF-HEADER --------------------------------------------
|
||||
File : Main_RTT_MenuApp.c
|
||||
Purpose : Sample application to demonstrate RTT bi-directional functionality
|
||||
*/
|
||||
|
||||
#define MAIN_C
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
|
||||
volatile int _Cnt;
|
||||
volatile int _Delay;
|
||||
|
||||
static char r;
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* main
|
||||
*/
|
||||
void main(void) {
|
||||
|
||||
SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n");
|
||||
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
|
||||
do {
|
||||
r = SEGGER_RTT_WaitKey();
|
||||
SEGGER_RTT_Write(0, &r, 1);
|
||||
r++;
|
||||
} while (1);
|
||||
}
|
||||
|
||||
/*************************** End of file ****************************/
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* Solutions for real time microcontroller applications *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
|
||||
--------- END-OF-HEADER --------------------------------------------
|
||||
File : Main_RTT_MenuApp.c
|
||||
Purpose : Sample application to demonstrate RTT bi-directional functionality
|
||||
*/
|
||||
|
||||
#define MAIN_C
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
|
||||
volatile int _Cnt;
|
||||
volatile int _Delay;
|
||||
|
||||
static char r;
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* main
|
||||
*/
|
||||
void main(void) {
|
||||
|
||||
SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n");
|
||||
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
|
||||
do {
|
||||
r = SEGGER_RTT_WaitKey();
|
||||
SEGGER_RTT_Write(0, &r, 1);
|
||||
r++;
|
||||
} while (1);
|
||||
}
|
||||
|
||||
/*************************** End of file ****************************/
|
||||
|
||||
+70
-70
@@ -1,70 +1,70 @@
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* Solutions for real time microcontroller applications *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
--------- END-OF-HEADER --------------------------------------------
|
||||
File : Main_RTT_MenuApp.c
|
||||
Purpose : Sample application to demonstrate RTT bi-directional functionality
|
||||
*/
|
||||
|
||||
#define MAIN_C
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
|
||||
volatile int _Cnt;
|
||||
volatile int _Delay;
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* main
|
||||
*/
|
||||
void main(void) {
|
||||
int r;
|
||||
int CancelOp;
|
||||
|
||||
do {
|
||||
_Cnt = 0;
|
||||
|
||||
SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n");
|
||||
SEGGER_RTT_WriteString(0, "Press <1> to continue in blocking mode (Application waits if necessary, no data lost)\r\n");
|
||||
SEGGER_RTT_WriteString(0, "Press <2> to continue in non-blocking mode (Application does not wait, data lost if fifo full)\r\n");
|
||||
do {
|
||||
r = SEGGER_RTT_WaitKey();
|
||||
} while ((r != '1') && (r != '2'));
|
||||
if (r == '1') {
|
||||
SEGGER_RTT_WriteString(0, "\r\nSelected <1>. Configuring RTT and starting...\r\n");
|
||||
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
|
||||
} else {
|
||||
SEGGER_RTT_WriteString(0, "\r\nSelected <2>. Configuring RTT and starting...\r\n");
|
||||
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
|
||||
}
|
||||
CancelOp = 0;
|
||||
do {
|
||||
//for (_Delay = 0; _Delay < 10000; _Delay++);
|
||||
SEGGER_RTT_printf(0, "Count: %d. Press <Space> to get back to menu.\r\n", _Cnt++);
|
||||
r = SEGGER_RTT_HasKey();
|
||||
if (r) {
|
||||
CancelOp = (SEGGER_RTT_GetKey() == ' ') ? 1 : 0;
|
||||
}
|
||||
//
|
||||
// Check if user selected to cancel the current operation
|
||||
//
|
||||
if (CancelOp) {
|
||||
SEGGER_RTT_WriteString(0, "Operation cancelled, going back to menu...\r\n");
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
SEGGER_RTT_GetKey();
|
||||
SEGGER_RTT_WriteString(0, "\r\n");
|
||||
} while (1);
|
||||
}
|
||||
|
||||
/*************************** End of file ****************************/
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* Solutions for real time microcontroller applications *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
--------- END-OF-HEADER --------------------------------------------
|
||||
File : Main_RTT_MenuApp.c
|
||||
Purpose : Sample application to demonstrate RTT bi-directional functionality
|
||||
*/
|
||||
|
||||
#define MAIN_C
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
|
||||
volatile int _Cnt;
|
||||
volatile int _Delay;
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* main
|
||||
*/
|
||||
void main(void) {
|
||||
int r;
|
||||
int CancelOp;
|
||||
|
||||
do {
|
||||
_Cnt = 0;
|
||||
|
||||
SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n");
|
||||
SEGGER_RTT_WriteString(0, "Press <1> to continue in blocking mode (Application waits if necessary, no data lost)\r\n");
|
||||
SEGGER_RTT_WriteString(0, "Press <2> to continue in non-blocking mode (Application does not wait, data lost if fifo full)\r\n");
|
||||
do {
|
||||
r = SEGGER_RTT_WaitKey();
|
||||
} while ((r != '1') && (r != '2'));
|
||||
if (r == '1') {
|
||||
SEGGER_RTT_WriteString(0, "\r\nSelected <1>. Configuring RTT and starting...\r\n");
|
||||
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
|
||||
} else {
|
||||
SEGGER_RTT_WriteString(0, "\r\nSelected <2>. Configuring RTT and starting...\r\n");
|
||||
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
|
||||
}
|
||||
CancelOp = 0;
|
||||
do {
|
||||
//for (_Delay = 0; _Delay < 10000; _Delay++);
|
||||
SEGGER_RTT_printf(0, "Count: %d. Press <Space> to get back to menu.\r\n", _Cnt++);
|
||||
r = SEGGER_RTT_HasKey();
|
||||
if (r) {
|
||||
CancelOp = (SEGGER_RTT_GetKey() == ' ') ? 1 : 0;
|
||||
}
|
||||
//
|
||||
// Check if user selected to cancel the current operation
|
||||
//
|
||||
if (CancelOp) {
|
||||
SEGGER_RTT_WriteString(0, "Operation cancelled, going back to menu...\r\n");
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
SEGGER_RTT_GetKey();
|
||||
SEGGER_RTT_WriteString(0, "\r\n");
|
||||
} while (1);
|
||||
}
|
||||
|
||||
/*************************** End of file ****************************/
|
||||
|
||||
+118
-118
@@ -1,118 +1,118 @@
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* Solutions for real time microcontroller applications *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
|
||||
--------- END-OF-HEADER --------------------------------------------
|
||||
File : Main_RTT_MenuApp.c
|
||||
Purpose : Sample application to demonstrate RTT bi-directional functionality
|
||||
*/
|
||||
|
||||
#define MAIN_C
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
|
||||
volatile int _Cnt;
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* main
|
||||
*/
|
||||
void main(void) {
|
||||
|
||||
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
|
||||
|
||||
SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n\r\n");
|
||||
SEGGER_RTT_WriteString(0, "###### Testing SEGGER_printf() ######\r\n");
|
||||
|
||||
SEGGER_RTT_printf(0, "printf Test: %%c, 'S' : %c.\r\n", 'S');
|
||||
SEGGER_RTT_printf(0, "printf Test: %%5c, 'E' : %5c.\r\n", 'E');
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-5c, 'G' : %-5c.\r\n", 'G');
|
||||
SEGGER_RTT_printf(0, "printf Test: %%5.3c, 'G' : %-5c.\r\n", 'G');
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.3c, 'E' : %-5c.\r\n", 'E');
|
||||
SEGGER_RTT_printf(0, "printf Test: %%c, 'R' : %c.\r\n", 'R');
|
||||
|
||||
SEGGER_RTT_printf(0, "printf Test: %%s, \"RTT\" : %s.\r\n", "RTT");
|
||||
SEGGER_RTT_printf(0, "printf Test: %%s, \"RTT\\r\\nRocks.\" : %s.\r\n", "RTT\r\nRocks.");
|
||||
|
||||
SEGGER_RTT_printf(0, "printf Test: %%u, 12345 : %u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%+u, 12345 : %+u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.3u, 12345 : %.3u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.6u, 12345 : %.6u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%6.3u, 12345 : %6.3u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%8.6u, 12345 : %8.6u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08u, 12345 : %08u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08.6u, 12345 : %08.6u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%0u, 12345 : %0u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-.6u, 12345 : %-.6u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-6.3u, 12345 : %-6.3u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-8.6u, 12345 : %-8.6u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08u, 12345 : %-08u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08.6u, 12345 : %-08.6u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-0u, 12345 : %-0u.\r\n", 12345);
|
||||
|
||||
SEGGER_RTT_printf(0, "printf Test: %%u, -12345 : %u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%+u, -12345 : %+u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.3u, -12345 : %.3u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.6u, -12345 : %.6u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%6.3u, -12345 : %6.3u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%8.6u, -12345 : %8.6u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08u, -12345 : %08u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08.6u, -12345 : %08.6u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%0u, -12345 : %0u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-.6u, -12345 : %-.6u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-6.3u, -12345 : %-6.3u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-8.6u, -12345 : %-8.6u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08u, -12345 : %-08u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08.6u, -12345 : %-08.6u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-0u, -12345 : %-0u.\r\n", -12345);
|
||||
|
||||
SEGGER_RTT_printf(0, "printf Test: %%d, -12345 : %d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%+d, -12345 : %+d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.3d, -12345 : %.3d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.6d, -12345 : %.6d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%6.3d, -12345 : %6.3d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%8.6d, -12345 : %8.6d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08d, -12345 : %08d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08.6d, -12345 : %08.6d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%0d, -12345 : %0d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-.6d, -12345 : %-.6d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-6.3d, -12345 : %-6.3d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-8.6d, -12345 : %-8.6d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08d, -12345 : %-08d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08.6d, -12345 : %-08.6d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-0d, -12345 : %-0d.\r\n", -12345);
|
||||
|
||||
SEGGER_RTT_printf(0, "printf Test: %%x, 0x1234ABC : %x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%+x, 0x1234ABC : %+x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.3x, 0x1234ABC : %.3x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.6x, 0x1234ABC : %.6x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%6.3x, 0x1234ABC : %6.3x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%8.6x, 0x1234ABC : %8.6x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08x, 0x1234ABC : %08x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08.6x, 0x1234ABC : %08.6x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%0x, 0x1234ABC : %0x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-.6x, 0x1234ABC : %-.6x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-6.3x, 0x1234ABC : %-6.3x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-8.6x, 0x1234ABC : %-8.6x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08x, 0x1234ABC : %-08x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08.6x, 0x1234ABC : %-08.6x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-0x, 0x1234ABC : %-0x.\r\n", 0x1234ABC);
|
||||
|
||||
SEGGER_RTT_printf(0, "printf Test: %%p, &_Cnt : %p.\r\n", &_Cnt);
|
||||
|
||||
SEGGER_RTT_WriteString(0, "###### SEGGER_printf() Tests done. ######\r\n");
|
||||
do {
|
||||
_Cnt++;
|
||||
} while (1);
|
||||
}
|
||||
|
||||
/*************************** End of file ****************************/
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* Solutions for real time microcontroller applications *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
|
||||
--------- END-OF-HEADER --------------------------------------------
|
||||
File : Main_RTT_MenuApp.c
|
||||
Purpose : Sample application to demonstrate RTT bi-directional functionality
|
||||
*/
|
||||
|
||||
#define MAIN_C
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
|
||||
volatile int _Cnt;
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* main
|
||||
*/
|
||||
void main(void) {
|
||||
|
||||
SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
|
||||
|
||||
SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal Sample\r\n\r\n");
|
||||
SEGGER_RTT_WriteString(0, "###### Testing SEGGER_printf() ######\r\n");
|
||||
|
||||
SEGGER_RTT_printf(0, "printf Test: %%c, 'S' : %c.\r\n", 'S');
|
||||
SEGGER_RTT_printf(0, "printf Test: %%5c, 'E' : %5c.\r\n", 'E');
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-5c, 'G' : %-5c.\r\n", 'G');
|
||||
SEGGER_RTT_printf(0, "printf Test: %%5.3c, 'G' : %-5c.\r\n", 'G');
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.3c, 'E' : %-5c.\r\n", 'E');
|
||||
SEGGER_RTT_printf(0, "printf Test: %%c, 'R' : %c.\r\n", 'R');
|
||||
|
||||
SEGGER_RTT_printf(0, "printf Test: %%s, \"RTT\" : %s.\r\n", "RTT");
|
||||
SEGGER_RTT_printf(0, "printf Test: %%s, \"RTT\\r\\nRocks.\" : %s.\r\n", "RTT\r\nRocks.");
|
||||
|
||||
SEGGER_RTT_printf(0, "printf Test: %%u, 12345 : %u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%+u, 12345 : %+u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.3u, 12345 : %.3u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.6u, 12345 : %.6u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%6.3u, 12345 : %6.3u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%8.6u, 12345 : %8.6u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08u, 12345 : %08u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08.6u, 12345 : %08.6u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%0u, 12345 : %0u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-.6u, 12345 : %-.6u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-6.3u, 12345 : %-6.3u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-8.6u, 12345 : %-8.6u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08u, 12345 : %-08u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08.6u, 12345 : %-08.6u.\r\n", 12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-0u, 12345 : %-0u.\r\n", 12345);
|
||||
|
||||
SEGGER_RTT_printf(0, "printf Test: %%u, -12345 : %u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%+u, -12345 : %+u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.3u, -12345 : %.3u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.6u, -12345 : %.6u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%6.3u, -12345 : %6.3u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%8.6u, -12345 : %8.6u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08u, -12345 : %08u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08.6u, -12345 : %08.6u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%0u, -12345 : %0u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-.6u, -12345 : %-.6u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-6.3u, -12345 : %-6.3u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-8.6u, -12345 : %-8.6u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08u, -12345 : %-08u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08.6u, -12345 : %-08.6u.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-0u, -12345 : %-0u.\r\n", -12345);
|
||||
|
||||
SEGGER_RTT_printf(0, "printf Test: %%d, -12345 : %d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%+d, -12345 : %+d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.3d, -12345 : %.3d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.6d, -12345 : %.6d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%6.3d, -12345 : %6.3d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%8.6d, -12345 : %8.6d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08d, -12345 : %08d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08.6d, -12345 : %08.6d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%0d, -12345 : %0d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-.6d, -12345 : %-.6d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-6.3d, -12345 : %-6.3d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-8.6d, -12345 : %-8.6d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08d, -12345 : %-08d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08.6d, -12345 : %-08.6d.\r\n", -12345);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-0d, -12345 : %-0d.\r\n", -12345);
|
||||
|
||||
SEGGER_RTT_printf(0, "printf Test: %%x, 0x1234ABC : %x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%+x, 0x1234ABC : %+x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.3x, 0x1234ABC : %.3x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%.6x, 0x1234ABC : %.6x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%6.3x, 0x1234ABC : %6.3x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%8.6x, 0x1234ABC : %8.6x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08x, 0x1234ABC : %08x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%08.6x, 0x1234ABC : %08.6x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%0x, 0x1234ABC : %0x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-.6x, 0x1234ABC : %-.6x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-6.3x, 0x1234ABC : %-6.3x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-8.6x, 0x1234ABC : %-8.6x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08x, 0x1234ABC : %-08x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-08.6x, 0x1234ABC : %-08.6x.\r\n", 0x1234ABC);
|
||||
SEGGER_RTT_printf(0, "printf Test: %%-0x, 0x1234ABC : %-0x.\r\n", 0x1234ABC);
|
||||
|
||||
SEGGER_RTT_printf(0, "printf Test: %%p, &_Cnt : %p.\r\n", &_Cnt);
|
||||
|
||||
SEGGER_RTT_WriteString(0, "###### SEGGER_printf() Tests done. ######\r\n");
|
||||
do {
|
||||
_Cnt++;
|
||||
} while (1);
|
||||
}
|
||||
|
||||
/*************************** End of file ****************************/
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* Solutions for real time microcontroller applications *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
|
||||
--------- END-OF-HEADER --------------------------------------------
|
||||
File : Main_RTT_SpeedTestApp.c
|
||||
Purpose : Sample program for measuring RTT performance.
|
||||
*/
|
||||
|
||||
#include "RTOS.h"
|
||||
#include "BSP.h"
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
#include <stdio.h>
|
||||
|
||||
OS_STACKPTR int StackHP[128], StackLP[128]; /* Task stacks */
|
||||
OS_TASK TCBHP, TCBLP; /* Task-control-blocks */
|
||||
|
||||
static void HPTask(void) {
|
||||
while (1) {
|
||||
//
|
||||
// Measure time needed for RTT output
|
||||
// Perform dummy write with 0 characters, so we know the overhead of toggling LEDs and RTT in general
|
||||
//
|
||||
// Set BP here. Then start sampling on scope
|
||||
BSP_ClrLED(0);
|
||||
SEGGER_RTT_Write(0, 0, 0);
|
||||
BSP_SetLED(0);
|
||||
BSP_ClrLED(0);
|
||||
SEGGER_RTT_Write(0, "01234567890123456789012345678901234567890123456789012345678901234567890123456789\r\n", 82);
|
||||
BSP_SetLED(0);
|
||||
// Set BP here. Then stop sampling on scope
|
||||
OS_Delay(200);
|
||||
}
|
||||
}
|
||||
|
||||
static void LPTask(void) {
|
||||
while (1) {
|
||||
BSP_ToggleLED(1);
|
||||
OS_Delay (500);
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* main
|
||||
*
|
||||
*********************************************************************/
|
||||
|
||||
int main(void) {
|
||||
OS_IncDI(); /* Initially disable interrupts */
|
||||
OS_InitKern(); /* Initialize OS */
|
||||
OS_InitHW(); /* Initialize Hardware for OS */
|
||||
BSP_Init(); /* Initialize LED ports */
|
||||
BSP_SetLED(0);
|
||||
/* You need to create at least one task before calling OS_Start() */
|
||||
OS_CREATETASK(&TCBHP, "HP Task", HPTask, 100, StackHP);
|
||||
OS_CREATETASK(&TCBLP, "LP Task", LPTask, 50, StackLP);
|
||||
OS_Start(); /* Start multitasking */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* Solutions for real time microcontroller applications *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
|
||||
--------- END-OF-HEADER --------------------------------------------
|
||||
File : Main_RTT_SpeedTestApp.c
|
||||
Purpose : Sample program for measuring RTT performance.
|
||||
*/
|
||||
|
||||
#include "RTOS.h"
|
||||
#include "BSP.h"
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
#include <stdio.h>
|
||||
|
||||
OS_STACKPTR int StackHP[128], StackLP[128]; /* Task stacks */
|
||||
OS_TASK TCBHP, TCBLP; /* Task-control-blocks */
|
||||
|
||||
static void HPTask(void) {
|
||||
while (1) {
|
||||
//
|
||||
// Measure time needed for RTT output
|
||||
// Perform dummy write with 0 characters, so we know the overhead of toggling LEDs and RTT in general
|
||||
//
|
||||
// Set BP here. Then start sampling on scope
|
||||
BSP_ClrLED(0);
|
||||
SEGGER_RTT_Write(0, 0, 0);
|
||||
BSP_SetLED(0);
|
||||
BSP_ClrLED(0);
|
||||
SEGGER_RTT_Write(0, "01234567890123456789012345678901234567890123456789012345678901234567890123456789\r\n", 82);
|
||||
BSP_SetLED(0);
|
||||
// Set BP here. Then stop sampling on scope
|
||||
OS_Delay(200);
|
||||
}
|
||||
}
|
||||
|
||||
static void LPTask(void) {
|
||||
while (1) {
|
||||
BSP_ToggleLED(1);
|
||||
OS_Delay (500);
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* main
|
||||
*
|
||||
*********************************************************************/
|
||||
|
||||
int main(void) {
|
||||
OS_IncDI(); /* Initially disable interrupts */
|
||||
OS_InitKern(); /* Initialize OS */
|
||||
OS_InitHW(); /* Initialize Hardware for OS */
|
||||
BSP_Init(); /* Initialize LED ports */
|
||||
BSP_SetLED(0);
|
||||
/* You need to create at least one task before calling OS_Start() */
|
||||
OS_CREATETASK(&TCBHP, "HP Task", HPTask, 100, StackHP);
|
||||
OS_CREATETASK(&TCBLP, "LP Task", LPTask, 50, StackLP);
|
||||
OS_Start(); /* Start multitasking */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+44
-44
@@ -1,44 +1,44 @@
|
||||
Important - Read carefully:
|
||||
|
||||
SEGGER RTT - Real Time Transfer for embedded targets
|
||||
|
||||
All rights reserved.
|
||||
|
||||
SEGGER strongly recommends to not make any changes
|
||||
to or modify the source code of this software in order to stay
|
||||
compatible with the RTT protocol and J-Link.
|
||||
|
||||
Redistribution and use in source and binary forms, with or
|
||||
without modification, are permitted provided that the following
|
||||
conditions are met:
|
||||
|
||||
o Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
o Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
o Neither the name of SEGGER Microcontroller GmbH
|
||||
nor the names of its contributors may be used to endorse or
|
||||
promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGE.
|
||||
|
||||
|
||||
(c) 2014 - 2016 SEGGER Microcontroller GmbH
|
||||
www.segger.com
|
||||
Important - Read carefully:
|
||||
|
||||
SEGGER RTT - Real Time Transfer for embedded targets
|
||||
|
||||
All rights reserved.
|
||||
|
||||
SEGGER strongly recommends to not make any changes
|
||||
to or modify the source code of this software in order to stay
|
||||
compatible with the RTT protocol and J-Link.
|
||||
|
||||
Redistribution and use in source and binary forms, with or
|
||||
without modification, are permitted provided that the following
|
||||
conditions are met:
|
||||
|
||||
o Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
o Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
o Neither the name of SEGGER Microcontroller GmbH
|
||||
nor the names of its contributors may be used to endorse or
|
||||
promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGE.
|
||||
|
||||
|
||||
(c) 2014 - 2016 SEGGER Microcontroller GmbH
|
||||
www.segger.com
|
||||
|
||||
+20
-20
@@ -1,20 +1,20 @@
|
||||
README.txt for the SEGGER RTT Implementation Pack.
|
||||
|
||||
Included files:
|
||||
===============
|
||||
Root Directory
|
||||
- Examples
|
||||
- Main_RTT_InputEchoApp.c - Sample application which echoes input on Channel 0.
|
||||
- Main_RTT_MenuApp.c - Sample application to demonstrate RTT bi-directional functionality.
|
||||
- Main_RTT_PrintfTest.c - Sample application to test RTT small printf implementation.
|
||||
- Main_RTT_SpeedTestApp.c - Sample application for measuring RTT performance. embOS needed.
|
||||
- RTT
|
||||
- SEGGER_RTT.c - The RTT implementation.
|
||||
- SEGGER_RTT.h - Header for RTT implementation.
|
||||
- SEGGER_RTT_Conf.h - Pre-processor configuration for the RTT implementation.
|
||||
- SEGGER_RTT_Printf.c - Simple implementation of printf to write formatted strings via RTT.
|
||||
- Syscalls
|
||||
- RTT_Syscalls_GCC.c - Low-level syscalls to retarget printf() to RTT with GCC / Newlib.
|
||||
- RTT_Syscalls_IAR.c - Low-level syscalls to retarget printf() to RTT with IAR compiler.
|
||||
- RTT_Syscalls_KEIL.c - Low-level syscalls to retarget printf() to RTT with KEIL/uVision compiler.
|
||||
- RTT_Syscalls_SES.c - Low-level syscalls to retarget printf() to RTT with SEGGER Embedded Studio.
|
||||
README.txt for the SEGGER RTT Implementation Pack.
|
||||
|
||||
Included files:
|
||||
===============
|
||||
Root Directory
|
||||
- Examples
|
||||
- Main_RTT_InputEchoApp.c - Sample application which echoes input on Channel 0.
|
||||
- Main_RTT_MenuApp.c - Sample application to demonstrate RTT bi-directional functionality.
|
||||
- Main_RTT_PrintfTest.c - Sample application to test RTT small printf implementation.
|
||||
- Main_RTT_SpeedTestApp.c - Sample application for measuring RTT performance. embOS needed.
|
||||
- RTT
|
||||
- SEGGER_RTT.c - The RTT implementation.
|
||||
- SEGGER_RTT.h - Header for RTT implementation.
|
||||
- SEGGER_RTT_Conf.h - Pre-processor configuration for the RTT implementation.
|
||||
- SEGGER_RTT_Printf.c - Simple implementation of printf to write formatted strings via RTT.
|
||||
- Syscalls
|
||||
- RTT_Syscalls_GCC.c - Low-level syscalls to retarget printf() to RTT with GCC / Newlib.
|
||||
- RTT_Syscalls_IAR.c - Low-level syscalls to retarget printf() to RTT with IAR compiler.
|
||||
- RTT_Syscalls_KEIL.c - Low-level syscalls to retarget printf() to RTT with KEIL/uVision compiler.
|
||||
- RTT_Syscalls_SES.c - Low-level syscalls to retarget printf() to RTT with SEGGER Embedded Studio.
|
||||
|
||||
+1761
-1761
File diff suppressed because it is too large
Load Diff
+260
-260
@@ -1,260 +1,260 @@
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* The Embedded Experts *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* SEGGER RTT * Real Time Transfer for embedded targets *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* SEGGER strongly recommends to not make any changes *
|
||||
* to or modify the source code of this software in order to stay *
|
||||
* compatible with the RTT protocol and J-Link. *
|
||||
* *
|
||||
* Redistribution and use in source and binary forms, with or *
|
||||
* without modification, are permitted provided that the following *
|
||||
* conditions are met: *
|
||||
* *
|
||||
* o Redistributions of source code must retain the above copyright *
|
||||
* notice, this list of conditions and the following disclaimer. *
|
||||
* *
|
||||
* o Redistributions in binary form must reproduce the above *
|
||||
* copyright notice, this list of conditions and the following *
|
||||
* disclaimer in the documentation and/or other materials provided *
|
||||
* with the distribution. *
|
||||
* *
|
||||
* o Neither the name of SEGGER Microcontroller GmbH *
|
||||
* nor the names of its contributors may be used to endorse or *
|
||||
* promote products derived from this software without specific *
|
||||
* prior written permission. *
|
||||
* *
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
|
||||
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
|
||||
* DAMAGE. *
|
||||
* *
|
||||
**********************************************************************
|
||||
---------------------------END-OF-HEADER------------------------------
|
||||
File : SEGGER_RTT.h
|
||||
Purpose : Implementation of SEGGER real-time transfer which allows
|
||||
real-time communication on targets which support debugger
|
||||
memory accesses while the CPU is running.
|
||||
Revision: $Rev: 12826 $
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef SEGGER_RTT_H
|
||||
#define SEGGER_RTT_H
|
||||
|
||||
#ifdef SEGGER_RTT_CONFIG_H
|
||||
#include SEGGER_RTT_CONFIG_H
|
||||
#else
|
||||
#include "SEGGER_RTT_Conf.h"
|
||||
#endif
|
||||
|
||||
#ifndef SEGGER_RTT_ASM // defined when SEGGER_RTT.h is included from assembly file
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Defines, fixed
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Types
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
//
|
||||
// Description for a circular buffer (also called "ring buffer")
|
||||
// which is used as up-buffer (T->H)
|
||||
//
|
||||
typedef struct {
|
||||
const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
|
||||
char* pBuffer; // Pointer to start of buffer
|
||||
unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
|
||||
unsigned WrOff; // Position of next item to be written by either target.
|
||||
volatile unsigned RdOff; // Position of next item to be read by host. Must be volatile since it may be modified by host.
|
||||
unsigned Flags; // Contains configuration flags
|
||||
} SEGGER_RTT_BUFFER_UP;
|
||||
|
||||
//
|
||||
// Description for a circular buffer (also called "ring buffer")
|
||||
// which is used as down-buffer (H->T)
|
||||
//
|
||||
typedef struct {
|
||||
const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
|
||||
char* pBuffer; // Pointer to start of buffer
|
||||
unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
|
||||
volatile unsigned WrOff; // Position of next item to be written by host. Must be volatile since it may be modified by host.
|
||||
unsigned RdOff; // Position of next item to be read by target (down-buffer).
|
||||
unsigned Flags; // Contains configuration flags
|
||||
} SEGGER_RTT_BUFFER_DOWN;
|
||||
|
||||
//
|
||||
// RTT control block which describes the number of buffers available
|
||||
// as well as the configuration for each buffer
|
||||
//
|
||||
//
|
||||
typedef struct {
|
||||
char acID[16]; // Initialized to "SEGGER RTT"
|
||||
int MaxNumUpBuffers; // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)
|
||||
int MaxNumDownBuffers; // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)
|
||||
SEGGER_RTT_BUFFER_UP aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS]; // Up buffers, transferring information up from target via debug probe to host
|
||||
SEGGER_RTT_BUFFER_DOWN aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS]; // Down buffers, transferring information down from host via debug probe to target
|
||||
} SEGGER_RTT_CB;
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Global data
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
extern SEGGER_RTT_CB _SEGGER_RTT;
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT API functions
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int SEGGER_RTT_AllocDownBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
|
||||
int SEGGER_RTT_AllocUpBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
|
||||
int SEGGER_RTT_ConfigUpBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
|
||||
int SEGGER_RTT_ConfigDownBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
|
||||
int SEGGER_RTT_GetKey (void);
|
||||
unsigned SEGGER_RTT_HasData (unsigned BufferIndex);
|
||||
int SEGGER_RTT_HasKey (void);
|
||||
unsigned SEGGER_RTT_HasDataUp (unsigned BufferIndex);
|
||||
void SEGGER_RTT_Init (void);
|
||||
unsigned SEGGER_RTT_Read (unsigned BufferIndex, void* pBuffer, unsigned BufferSize);
|
||||
unsigned SEGGER_RTT_ReadNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize);
|
||||
int SEGGER_RTT_SetNameDownBuffer (unsigned BufferIndex, const char* sName);
|
||||
int SEGGER_RTT_SetNameUpBuffer (unsigned BufferIndex, const char* sName);
|
||||
int SEGGER_RTT_SetFlagsDownBuffer (unsigned BufferIndex, unsigned Flags);
|
||||
int SEGGER_RTT_SetFlagsUpBuffer (unsigned BufferIndex, unsigned Flags);
|
||||
int SEGGER_RTT_WaitKey (void);
|
||||
unsigned SEGGER_RTT_Write (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
|
||||
unsigned SEGGER_RTT_WriteNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
|
||||
unsigned SEGGER_RTT_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
|
||||
unsigned SEGGER_RTT_WriteString (unsigned BufferIndex, const char* s);
|
||||
void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
|
||||
unsigned SEGGER_RTT_PutChar (unsigned BufferIndex, char c);
|
||||
unsigned SEGGER_RTT_PutCharSkip (unsigned BufferIndex, char c);
|
||||
unsigned SEGGER_RTT_PutCharSkipNoLock (unsigned BufferIndex, char c);
|
||||
//
|
||||
// Function macro for performance optimization
|
||||
//
|
||||
#define SEGGER_RTT_HASDATA(n) (_SEGGER_RTT.aDown[n].WrOff - _SEGGER_RTT.aDown[n].RdOff)
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT "Terminal" API functions
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
int SEGGER_RTT_SetTerminal (char TerminalId);
|
||||
int SEGGER_RTT_TerminalOut (char TerminalId, const char* s);
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT printf functions (require SEGGER_RTT_printf.c)
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
|
||||
int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SEGGER_RTT_ASM
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Defines
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
//
|
||||
// Operating modes. Define behavior if buffer is full (not enough space for entire message)
|
||||
//
|
||||
#define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0) // Skip. Do not block, output nothing. (Default)
|
||||
#define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1) // Trim: Do not block, output as much as fits.
|
||||
#define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (2) // Block: Wait until there is space in the buffer.
|
||||
#define SEGGER_RTT_MODE_MASK (3)
|
||||
|
||||
//
|
||||
// Control sequences, based on ANSI.
|
||||
// Can be used to control color, and clear the screen
|
||||
//
|
||||
#define RTT_CTRL_RESET "\x1B[0m" // Reset to default colors
|
||||
#define RTT_CTRL_CLEAR "\x1B[2J" // Clear screen, reposition cursor to top left
|
||||
|
||||
#define RTT_CTRL_TEXT_BLACK "\x1B[2;30m"
|
||||
#define RTT_CTRL_TEXT_RED "\x1B[2;31m"
|
||||
#define RTT_CTRL_TEXT_GREEN "\x1B[2;32m"
|
||||
#define RTT_CTRL_TEXT_YELLOW "\x1B[2;33m"
|
||||
#define RTT_CTRL_TEXT_BLUE "\x1B[2;34m"
|
||||
#define RTT_CTRL_TEXT_MAGENTA "\x1B[2;35m"
|
||||
#define RTT_CTRL_TEXT_CYAN "\x1B[2;36m"
|
||||
#define RTT_CTRL_TEXT_WHITE "\x1B[2;37m"
|
||||
|
||||
#define RTT_CTRL_TEXT_BRIGHT_BLACK "\x1B[1;30m"
|
||||
#define RTT_CTRL_TEXT_BRIGHT_RED "\x1B[1;31m"
|
||||
#define RTT_CTRL_TEXT_BRIGHT_GREEN "\x1B[1;32m"
|
||||
#define RTT_CTRL_TEXT_BRIGHT_YELLOW "\x1B[1;33m"
|
||||
#define RTT_CTRL_TEXT_BRIGHT_BLUE "\x1B[1;34m"
|
||||
#define RTT_CTRL_TEXT_BRIGHT_MAGENTA "\x1B[1;35m"
|
||||
#define RTT_CTRL_TEXT_BRIGHT_CYAN "\x1B[1;36m"
|
||||
#define RTT_CTRL_TEXT_BRIGHT_WHITE "\x1B[1;37m"
|
||||
|
||||
#define RTT_CTRL_BG_BLACK "\x1B[24;40m"
|
||||
#define RTT_CTRL_BG_RED "\x1B[24;41m"
|
||||
#define RTT_CTRL_BG_GREEN "\x1B[24;42m"
|
||||
#define RTT_CTRL_BG_YELLOW "\x1B[24;43m"
|
||||
#define RTT_CTRL_BG_BLUE "\x1B[24;44m"
|
||||
#define RTT_CTRL_BG_MAGENTA "\x1B[24;45m"
|
||||
#define RTT_CTRL_BG_CYAN "\x1B[24;46m"
|
||||
#define RTT_CTRL_BG_WHITE "\x1B[24;47m"
|
||||
|
||||
#define RTT_CTRL_BG_BRIGHT_BLACK "\x1B[4;40m"
|
||||
#define RTT_CTRL_BG_BRIGHT_RED "\x1B[4;41m"
|
||||
#define RTT_CTRL_BG_BRIGHT_GREEN "\x1B[4;42m"
|
||||
#define RTT_CTRL_BG_BRIGHT_YELLOW "\x1B[4;43m"
|
||||
#define RTT_CTRL_BG_BRIGHT_BLUE "\x1B[4;44m"
|
||||
#define RTT_CTRL_BG_BRIGHT_MAGENTA "\x1B[4;45m"
|
||||
#define RTT_CTRL_BG_BRIGHT_CYAN "\x1B[4;46m"
|
||||
#define RTT_CTRL_BG_BRIGHT_WHITE "\x1B[4;47m"
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*************************** End of file ****************************/
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* The Embedded Experts *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* SEGGER RTT * Real Time Transfer for embedded targets *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* SEGGER strongly recommends to not make any changes *
|
||||
* to or modify the source code of this software in order to stay *
|
||||
* compatible with the RTT protocol and J-Link. *
|
||||
* *
|
||||
* Redistribution and use in source and binary forms, with or *
|
||||
* without modification, are permitted provided that the following *
|
||||
* conditions are met: *
|
||||
* *
|
||||
* o Redistributions of source code must retain the above copyright *
|
||||
* notice, this list of conditions and the following disclaimer. *
|
||||
* *
|
||||
* o Redistributions in binary form must reproduce the above *
|
||||
* copyright notice, this list of conditions and the following *
|
||||
* disclaimer in the documentation and/or other materials provided *
|
||||
* with the distribution. *
|
||||
* *
|
||||
* o Neither the name of SEGGER Microcontroller GmbH *
|
||||
* nor the names of its contributors may be used to endorse or *
|
||||
* promote products derived from this software without specific *
|
||||
* prior written permission. *
|
||||
* *
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
|
||||
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
|
||||
* DAMAGE. *
|
||||
* *
|
||||
**********************************************************************
|
||||
---------------------------END-OF-HEADER------------------------------
|
||||
File : SEGGER_RTT.h
|
||||
Purpose : Implementation of SEGGER real-time transfer which allows
|
||||
real-time communication on targets which support debugger
|
||||
memory accesses while the CPU is running.
|
||||
Revision: $Rev: 12826 $
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef SEGGER_RTT_H
|
||||
#define SEGGER_RTT_H
|
||||
|
||||
#ifdef SEGGER_RTT_CONFIG_H
|
||||
#include SEGGER_RTT_CONFIG_H
|
||||
#else
|
||||
#include "SEGGER_RTT_Conf.h"
|
||||
#endif
|
||||
|
||||
#ifndef SEGGER_RTT_ASM // defined when SEGGER_RTT.h is included from assembly file
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Defines, fixed
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Types
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
//
|
||||
// Description for a circular buffer (also called "ring buffer")
|
||||
// which is used as up-buffer (T->H)
|
||||
//
|
||||
typedef struct {
|
||||
const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
|
||||
char* pBuffer; // Pointer to start of buffer
|
||||
unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
|
||||
unsigned WrOff; // Position of next item to be written by either target.
|
||||
volatile unsigned RdOff; // Position of next item to be read by host. Must be volatile since it may be modified by host.
|
||||
unsigned Flags; // Contains configuration flags
|
||||
} SEGGER_RTT_BUFFER_UP;
|
||||
|
||||
//
|
||||
// Description for a circular buffer (also called "ring buffer")
|
||||
// which is used as down-buffer (H->T)
|
||||
//
|
||||
typedef struct {
|
||||
const char* sName; // Optional name. Standard names so far are: "Terminal", "SysView", "J-Scope_t4i4"
|
||||
char* pBuffer; // Pointer to start of buffer
|
||||
unsigned SizeOfBuffer; // Buffer size in bytes. Note that one byte is lost, as this implementation does not fill up the buffer in order to avoid the problem of being unable to distinguish between full and empty.
|
||||
volatile unsigned WrOff; // Position of next item to be written by host. Must be volatile since it may be modified by host.
|
||||
unsigned RdOff; // Position of next item to be read by target (down-buffer).
|
||||
unsigned Flags; // Contains configuration flags
|
||||
} SEGGER_RTT_BUFFER_DOWN;
|
||||
|
||||
//
|
||||
// RTT control block which describes the number of buffers available
|
||||
// as well as the configuration for each buffer
|
||||
//
|
||||
//
|
||||
typedef struct {
|
||||
char acID[16]; // Initialized to "SEGGER RTT"
|
||||
int MaxNumUpBuffers; // Initialized to SEGGER_RTT_MAX_NUM_UP_BUFFERS (type. 2)
|
||||
int MaxNumDownBuffers; // Initialized to SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (type. 2)
|
||||
SEGGER_RTT_BUFFER_UP aUp[SEGGER_RTT_MAX_NUM_UP_BUFFERS]; // Up buffers, transferring information up from target via debug probe to host
|
||||
SEGGER_RTT_BUFFER_DOWN aDown[SEGGER_RTT_MAX_NUM_DOWN_BUFFERS]; // Down buffers, transferring information down from host via debug probe to target
|
||||
} SEGGER_RTT_CB;
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Global data
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
extern SEGGER_RTT_CB _SEGGER_RTT;
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT API functions
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int SEGGER_RTT_AllocDownBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
|
||||
int SEGGER_RTT_AllocUpBuffer (const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
|
||||
int SEGGER_RTT_ConfigUpBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
|
||||
int SEGGER_RTT_ConfigDownBuffer (unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags);
|
||||
int SEGGER_RTT_GetKey (void);
|
||||
unsigned SEGGER_RTT_HasData (unsigned BufferIndex);
|
||||
int SEGGER_RTT_HasKey (void);
|
||||
unsigned SEGGER_RTT_HasDataUp (unsigned BufferIndex);
|
||||
void SEGGER_RTT_Init (void);
|
||||
unsigned SEGGER_RTT_Read (unsigned BufferIndex, void* pBuffer, unsigned BufferSize);
|
||||
unsigned SEGGER_RTT_ReadNoLock (unsigned BufferIndex, void* pData, unsigned BufferSize);
|
||||
int SEGGER_RTT_SetNameDownBuffer (unsigned BufferIndex, const char* sName);
|
||||
int SEGGER_RTT_SetNameUpBuffer (unsigned BufferIndex, const char* sName);
|
||||
int SEGGER_RTT_SetFlagsDownBuffer (unsigned BufferIndex, unsigned Flags);
|
||||
int SEGGER_RTT_SetFlagsUpBuffer (unsigned BufferIndex, unsigned Flags);
|
||||
int SEGGER_RTT_WaitKey (void);
|
||||
unsigned SEGGER_RTT_Write (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
|
||||
unsigned SEGGER_RTT_WriteNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
|
||||
unsigned SEGGER_RTT_WriteSkipNoLock (unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
|
||||
unsigned SEGGER_RTT_WriteString (unsigned BufferIndex, const char* s);
|
||||
void SEGGER_RTT_WriteWithOverwriteNoLock(unsigned BufferIndex, const void* pBuffer, unsigned NumBytes);
|
||||
unsigned SEGGER_RTT_PutChar (unsigned BufferIndex, char c);
|
||||
unsigned SEGGER_RTT_PutCharSkip (unsigned BufferIndex, char c);
|
||||
unsigned SEGGER_RTT_PutCharSkipNoLock (unsigned BufferIndex, char c);
|
||||
//
|
||||
// Function macro for performance optimization
|
||||
//
|
||||
#define SEGGER_RTT_HASDATA(n) (_SEGGER_RTT.aDown[n].WrOff - _SEGGER_RTT.aDown[n].RdOff)
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT "Terminal" API functions
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
int SEGGER_RTT_SetTerminal (char TerminalId);
|
||||
int SEGGER_RTT_TerminalOut (char TerminalId, const char* s);
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT printf functions (require SEGGER_RTT_printf.c)
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
int SEGGER_RTT_printf(unsigned BufferIndex, const char * sFormat, ...);
|
||||
int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SEGGER_RTT_ASM
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Defines
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
//
|
||||
// Operating modes. Define behavior if buffer is full (not enough space for entire message)
|
||||
//
|
||||
#define SEGGER_RTT_MODE_NO_BLOCK_SKIP (0) // Skip. Do not block, output nothing. (Default)
|
||||
#define SEGGER_RTT_MODE_NO_BLOCK_TRIM (1) // Trim: Do not block, output as much as fits.
|
||||
#define SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL (2) // Block: Wait until there is space in the buffer.
|
||||
#define SEGGER_RTT_MODE_MASK (3)
|
||||
|
||||
//
|
||||
// Control sequences, based on ANSI.
|
||||
// Can be used to control color, and clear the screen
|
||||
//
|
||||
#define RTT_CTRL_RESET "\x1B[0m" // Reset to default colors
|
||||
#define RTT_CTRL_CLEAR "\x1B[2J" // Clear screen, reposition cursor to top left
|
||||
|
||||
#define RTT_CTRL_TEXT_BLACK "\x1B[2;30m"
|
||||
#define RTT_CTRL_TEXT_RED "\x1B[2;31m"
|
||||
#define RTT_CTRL_TEXT_GREEN "\x1B[2;32m"
|
||||
#define RTT_CTRL_TEXT_YELLOW "\x1B[2;33m"
|
||||
#define RTT_CTRL_TEXT_BLUE "\x1B[2;34m"
|
||||
#define RTT_CTRL_TEXT_MAGENTA "\x1B[2;35m"
|
||||
#define RTT_CTRL_TEXT_CYAN "\x1B[2;36m"
|
||||
#define RTT_CTRL_TEXT_WHITE "\x1B[2;37m"
|
||||
|
||||
#define RTT_CTRL_TEXT_BRIGHT_BLACK "\x1B[1;30m"
|
||||
#define RTT_CTRL_TEXT_BRIGHT_RED "\x1B[1;31m"
|
||||
#define RTT_CTRL_TEXT_BRIGHT_GREEN "\x1B[1;32m"
|
||||
#define RTT_CTRL_TEXT_BRIGHT_YELLOW "\x1B[1;33m"
|
||||
#define RTT_CTRL_TEXT_BRIGHT_BLUE "\x1B[1;34m"
|
||||
#define RTT_CTRL_TEXT_BRIGHT_MAGENTA "\x1B[1;35m"
|
||||
#define RTT_CTRL_TEXT_BRIGHT_CYAN "\x1B[1;36m"
|
||||
#define RTT_CTRL_TEXT_BRIGHT_WHITE "\x1B[1;37m"
|
||||
|
||||
#define RTT_CTRL_BG_BLACK "\x1B[24;40m"
|
||||
#define RTT_CTRL_BG_RED "\x1B[24;41m"
|
||||
#define RTT_CTRL_BG_GREEN "\x1B[24;42m"
|
||||
#define RTT_CTRL_BG_YELLOW "\x1B[24;43m"
|
||||
#define RTT_CTRL_BG_BLUE "\x1B[24;44m"
|
||||
#define RTT_CTRL_BG_MAGENTA "\x1B[24;45m"
|
||||
#define RTT_CTRL_BG_CYAN "\x1B[24;46m"
|
||||
#define RTT_CTRL_BG_WHITE "\x1B[24;47m"
|
||||
|
||||
#define RTT_CTRL_BG_BRIGHT_BLACK "\x1B[4;40m"
|
||||
#define RTT_CTRL_BG_BRIGHT_RED "\x1B[4;41m"
|
||||
#define RTT_CTRL_BG_BRIGHT_GREEN "\x1B[4;42m"
|
||||
#define RTT_CTRL_BG_BRIGHT_YELLOW "\x1B[4;43m"
|
||||
#define RTT_CTRL_BG_BRIGHT_BLUE "\x1B[4;44m"
|
||||
#define RTT_CTRL_BG_BRIGHT_MAGENTA "\x1B[4;45m"
|
||||
#define RTT_CTRL_BG_BRIGHT_CYAN "\x1B[4;46m"
|
||||
#define RTT_CTRL_BG_BRIGHT_WHITE "\x1B[4;47m"
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*************************** End of file ****************************/
|
||||
|
||||
+340
-340
@@ -1,340 +1,340 @@
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* The Embedded Experts *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* SEGGER RTT * Real Time Transfer for embedded targets *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* SEGGER strongly recommends to not make any changes *
|
||||
* to or modify the source code of this software in order to stay *
|
||||
* compatible with the RTT protocol and J-Link. *
|
||||
* *
|
||||
* Redistribution and use in source and binary forms, with or *
|
||||
* without modification, are permitted provided that the following *
|
||||
* conditions are met: *
|
||||
* *
|
||||
* o Redistributions of source code must retain the above copyright *
|
||||
* notice, this list of conditions and the following disclaimer. *
|
||||
* *
|
||||
* o Redistributions in binary form must reproduce the above *
|
||||
* copyright notice, this list of conditions and the following *
|
||||
* disclaimer in the documentation and/or other materials provided *
|
||||
* with the distribution. *
|
||||
* *
|
||||
* o Neither the name of SEGGER Microcontroller GmbH *
|
||||
* nor the names of its contributors may be used to endorse or *
|
||||
* promote products derived from this software without specific *
|
||||
* prior written permission. *
|
||||
* *
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
|
||||
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
|
||||
* DAMAGE. *
|
||||
* *
|
||||
**********************************************************************
|
||||
---------------------------END-OF-HEADER------------------------------
|
||||
File : SEGGER_RTT_Conf.h
|
||||
Purpose : Implementation of SEGGER real-time transfer (RTT) which
|
||||
allows real-time communication on targets which support
|
||||
debugger memory accesses while the CPU is running.
|
||||
Revision: $Rev: 12847 $
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SEGGER_RTT_CONF_H
|
||||
#define SEGGER_RTT_CONF_H
|
||||
|
||||
#ifdef __IAR_SYSTEMS_ICC__
|
||||
#include <intrinsics.h>
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Defines, configurable
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
#define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3)
|
||||
#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3)
|
||||
|
||||
#define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host (Default: 1k)
|
||||
#define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
|
||||
|
||||
#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)
|
||||
|
||||
#define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
|
||||
|
||||
#define USE_RTT_ASM (0) // Use assembler version of SEGGER_RTT.c when 1
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT memcpy configuration
|
||||
*
|
||||
* memcpy() is good for large amounts of data,
|
||||
* but the overhead is big for small amounts, which are usually stored via RTT.
|
||||
* With SEGGER_RTT_MEMCPY_USE_BYTELOOP a simple byte loop can be used instead.
|
||||
*
|
||||
* SEGGER_RTT_MEMCPY() can be used to replace standard memcpy() in RTT functions.
|
||||
* This is may be required with memory access restrictions,
|
||||
* such as on Cortex-A devices with MMU.
|
||||
*/
|
||||
#define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0 // 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop
|
||||
//
|
||||
// Example definition of SEGGER_RTT_MEMCPY to external memcpy with GCC toolchains and Cortex-A targets
|
||||
//
|
||||
//#if ((defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)) && (defined (__ARM_ARCH_7A__))
|
||||
// #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes) SEGGER_memcpy((pDest), (pSrc), (NumBytes))
|
||||
//#endif
|
||||
|
||||
//
|
||||
// Target is not allowed to perform other RTT operations while string still has not been stored completely.
|
||||
// Otherwise we would probably end up with a mixed string in the buffer.
|
||||
// If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
|
||||
//
|
||||
// SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.
|
||||
// Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.
|
||||
// When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.
|
||||
// (Higher priority = lower priority number)
|
||||
// Default value for embOS: 128u
|
||||
// Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
|
||||
// In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC
|
||||
// or define SEGGER_RTT_LOCK() to completely disable interrupts.
|
||||
//
|
||||
|
||||
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration for SEGGER Embedded Studio,
|
||||
* Rowley CrossStudio and GCC
|
||||
*/
|
||||
#if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__) || (defined __clang__)
|
||||
#if (defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_8M_BASE__))
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
__asm volatile ("mrs %0, primask \n\t" \
|
||||
"movs r1, $1 \n\t" \
|
||||
"msr primask, r1 \n\t" \
|
||||
: "=r" (LockState) \
|
||||
: \
|
||||
: "r1" \
|
||||
);
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \
|
||||
: \
|
||||
: "r" (LockState) \
|
||||
: \
|
||||
); \
|
||||
}
|
||||
#elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__))
|
||||
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
|
||||
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
|
||||
#endif
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
__asm volatile ("mrs %0, basepri \n\t" \
|
||||
"mov r1, %1 \n\t" \
|
||||
"msr basepri, r1 \n\t" \
|
||||
: "=r" (LockState) \
|
||||
: "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \
|
||||
: "r1" \
|
||||
);
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \
|
||||
: \
|
||||
: "r" (LockState) \
|
||||
: \
|
||||
); \
|
||||
}
|
||||
|
||||
#elif defined(__ARM_ARCH_7A__)
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
__asm volatile ("mrs r1, CPSR \n\t" \
|
||||
"mov %0, r1 \n\t" \
|
||||
"orr r1, r1, #0xC0 \n\t" \
|
||||
"msr CPSR_c, r1 \n\t" \
|
||||
: "=r" (LockState) \
|
||||
: \
|
||||
: "r1" \
|
||||
);
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \
|
||||
"mrs r1, CPSR \n\t" \
|
||||
"bic r1, r1, #0xC0 \n\t" \
|
||||
"and r0, r0, #0xC0 \n\t" \
|
||||
"orr r1, r1, r0 \n\t" \
|
||||
"msr CPSR_c, r1 \n\t" \
|
||||
: \
|
||||
: "r" (LockState) \
|
||||
: "r0", "r1" \
|
||||
); \
|
||||
}
|
||||
#else
|
||||
#define SEGGER_RTT_LOCK()
|
||||
#define SEGGER_RTT_UNLOCK()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration for IAR EWARM
|
||||
*/
|
||||
#ifdef __ICCARM__
|
||||
#if (defined (__ARM6M__) && (__CORE__ == __ARM6M__))
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
LockState = __get_PRIMASK(); \
|
||||
__set_PRIMASK(1);
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \
|
||||
}
|
||||
#elif ((defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || (defined (__ARM7M__) && (__CORE__ == __ARM7M__)))
|
||||
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
|
||||
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
|
||||
#endif
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
LockState = __get_BASEPRI(); \
|
||||
__set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __set_BASEPRI(LockState); \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration for IAR RX
|
||||
*/
|
||||
#ifdef __ICCRX__
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned long LockState; \
|
||||
LockState = __get_interrupt_state(); \
|
||||
__disable_interrupt();
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration for IAR RL78
|
||||
*/
|
||||
#ifdef __ICCRL78__
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
__istate_t LockState; \
|
||||
LockState = __get_interrupt_state(); \
|
||||
__disable_interrupt();
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration for KEIL ARM
|
||||
*/
|
||||
#ifdef __CC_ARM
|
||||
#if (defined __TARGET_ARCH_6S_M)
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
register unsigned char PRIMASK __asm( "primask"); \
|
||||
LockState = PRIMASK; \
|
||||
PRIMASK = 1u; \
|
||||
__schedule_barrier();
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() PRIMASK = LockState; \
|
||||
__schedule_barrier(); \
|
||||
}
|
||||
#elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))
|
||||
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
|
||||
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
|
||||
#endif
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
register unsigned char BASEPRI __asm( "basepri"); \
|
||||
LockState = BASEPRI; \
|
||||
BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY; \
|
||||
__schedule_barrier();
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() BASEPRI = LockState; \
|
||||
__schedule_barrier(); \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration for TI ARM
|
||||
*/
|
||||
#ifdef __TI_ARM__
|
||||
#if defined (__TI_ARM_V6M0__)
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
LockState = __get_PRIMASK(); \
|
||||
__set_PRIMASK(1);
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \
|
||||
}
|
||||
#elif (defined (__TI_ARM_V7M3__) || defined (__TI_ARM_V7M4__))
|
||||
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
|
||||
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
|
||||
#endif
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
LockState = _set_interrupt_priority(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() _set_interrupt_priority(LockState); \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration for CCRX
|
||||
*/
|
||||
#ifdef __RX
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned long LockState; \
|
||||
LockState = get_psw() & 0x010000; \
|
||||
clrpsw_i();
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() set_psw(get_psw() | LockState); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration fallback
|
||||
*/
|
||||
#ifndef SEGGER_RTT_LOCK
|
||||
#define SEGGER_RTT_LOCK() // Lock RTT (nestable) (i.e. disable interrupts)
|
||||
#endif
|
||||
|
||||
#ifndef SEGGER_RTT_UNLOCK
|
||||
#define SEGGER_RTT_UNLOCK() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*************************** End of file ****************************/
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* The Embedded Experts *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* SEGGER RTT * Real Time Transfer for embedded targets *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* SEGGER strongly recommends to not make any changes *
|
||||
* to or modify the source code of this software in order to stay *
|
||||
* compatible with the RTT protocol and J-Link. *
|
||||
* *
|
||||
* Redistribution and use in source and binary forms, with or *
|
||||
* without modification, are permitted provided that the following *
|
||||
* conditions are met: *
|
||||
* *
|
||||
* o Redistributions of source code must retain the above copyright *
|
||||
* notice, this list of conditions and the following disclaimer. *
|
||||
* *
|
||||
* o Redistributions in binary form must reproduce the above *
|
||||
* copyright notice, this list of conditions and the following *
|
||||
* disclaimer in the documentation and/or other materials provided *
|
||||
* with the distribution. *
|
||||
* *
|
||||
* o Neither the name of SEGGER Microcontroller GmbH *
|
||||
* nor the names of its contributors may be used to endorse or *
|
||||
* promote products derived from this software without specific *
|
||||
* prior written permission. *
|
||||
* *
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
|
||||
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
|
||||
* DAMAGE. *
|
||||
* *
|
||||
**********************************************************************
|
||||
---------------------------END-OF-HEADER------------------------------
|
||||
File : SEGGER_RTT_Conf.h
|
||||
Purpose : Implementation of SEGGER real-time transfer (RTT) which
|
||||
allows real-time communication on targets which support
|
||||
debugger memory accesses while the CPU is running.
|
||||
Revision: $Rev: 12847 $
|
||||
|
||||
*/
|
||||
|
||||
#ifndef SEGGER_RTT_CONF_H
|
||||
#define SEGGER_RTT_CONF_H
|
||||
|
||||
#ifdef __IAR_SYSTEMS_ICC__
|
||||
#include <intrinsics.h>
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Defines, configurable
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
#define SEGGER_RTT_MAX_NUM_UP_BUFFERS (3) // Max. number of up-buffers (T->H) available on this target (Default: 3)
|
||||
#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS (3) // Max. number of down-buffers (H->T) available on this target (Default: 3)
|
||||
|
||||
#define BUFFER_SIZE_UP (1024) // Size of the buffer for terminal output of target, up to host (Default: 1k)
|
||||
#define BUFFER_SIZE_DOWN (16) // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16)
|
||||
|
||||
#define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64)
|
||||
|
||||
#define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_NO_BLOCK_SKIP // Mode for pre-initialized terminal channel (buffer 0)
|
||||
|
||||
#define USE_RTT_ASM (0) // Use assembler version of SEGGER_RTT.c when 1
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT memcpy configuration
|
||||
*
|
||||
* memcpy() is good for large amounts of data,
|
||||
* but the overhead is big for small amounts, which are usually stored via RTT.
|
||||
* With SEGGER_RTT_MEMCPY_USE_BYTELOOP a simple byte loop can be used instead.
|
||||
*
|
||||
* SEGGER_RTT_MEMCPY() can be used to replace standard memcpy() in RTT functions.
|
||||
* This is may be required with memory access restrictions,
|
||||
* such as on Cortex-A devices with MMU.
|
||||
*/
|
||||
#define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0 // 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop
|
||||
//
|
||||
// Example definition of SEGGER_RTT_MEMCPY to external memcpy with GCC toolchains and Cortex-A targets
|
||||
//
|
||||
//#if ((defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)) && (defined (__ARM_ARCH_7A__))
|
||||
// #define SEGGER_RTT_MEMCPY(pDest, pSrc, NumBytes) SEGGER_memcpy((pDest), (pSrc), (NumBytes))
|
||||
//#endif
|
||||
|
||||
//
|
||||
// Target is not allowed to perform other RTT operations while string still has not been stored completely.
|
||||
// Otherwise we would probably end up with a mixed string in the buffer.
|
||||
// If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here.
|
||||
//
|
||||
// SEGGER_RTT_MAX_INTERRUPT_PRIORITY can be used in the sample lock routines on Cortex-M3/4.
|
||||
// Make sure to mask all interrupts which can send RTT data, i.e. generate SystemView events, or cause task switches.
|
||||
// When high-priority interrupts must not be masked while sending RTT data, SEGGER_RTT_MAX_INTERRUPT_PRIORITY needs to be adjusted accordingly.
|
||||
// (Higher priority = lower priority number)
|
||||
// Default value for embOS: 128u
|
||||
// Default configuration in FreeRTOS: configMAX_SYSCALL_INTERRUPT_PRIORITY: ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
|
||||
// In case of doubt mask all interrupts: 1 << (8 - BASEPRI_PRIO_BITS) i.e. 1 << 5 when 3 bits are implemented in NVIC
|
||||
// or define SEGGER_RTT_LOCK() to completely disable interrupts.
|
||||
//
|
||||
|
||||
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20) // Interrupt priority to lock on SEGGER_RTT_LOCK on Cortex-M3/4 (Default: 0x20)
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration for SEGGER Embedded Studio,
|
||||
* Rowley CrossStudio and GCC
|
||||
*/
|
||||
#if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__) || (defined __clang__)
|
||||
#if (defined(__ARM_ARCH_6M__) || defined(__ARM_ARCH_8M_BASE__))
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
__asm volatile ("mrs %0, primask \n\t" \
|
||||
"movs r1, $1 \n\t" \
|
||||
"msr primask, r1 \n\t" \
|
||||
: "=r" (LockState) \
|
||||
: \
|
||||
: "r1" \
|
||||
);
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __asm volatile ("msr primask, %0 \n\t" \
|
||||
: \
|
||||
: "r" (LockState) \
|
||||
: \
|
||||
); \
|
||||
}
|
||||
#elif (defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__))
|
||||
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
|
||||
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
|
||||
#endif
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
__asm volatile ("mrs %0, basepri \n\t" \
|
||||
"mov r1, %1 \n\t" \
|
||||
"msr basepri, r1 \n\t" \
|
||||
: "=r" (LockState) \
|
||||
: "i"(SEGGER_RTT_MAX_INTERRUPT_PRIORITY) \
|
||||
: "r1" \
|
||||
);
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __asm volatile ("msr basepri, %0 \n\t" \
|
||||
: \
|
||||
: "r" (LockState) \
|
||||
: \
|
||||
); \
|
||||
}
|
||||
|
||||
#elif defined(__ARM_ARCH_7A__)
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
__asm volatile ("mrs r1, CPSR \n\t" \
|
||||
"mov %0, r1 \n\t" \
|
||||
"orr r1, r1, #0xC0 \n\t" \
|
||||
"msr CPSR_c, r1 \n\t" \
|
||||
: "=r" (LockState) \
|
||||
: \
|
||||
: "r1" \
|
||||
);
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __asm volatile ("mov r0, %0 \n\t" \
|
||||
"mrs r1, CPSR \n\t" \
|
||||
"bic r1, r1, #0xC0 \n\t" \
|
||||
"and r0, r0, #0xC0 \n\t" \
|
||||
"orr r1, r1, r0 \n\t" \
|
||||
"msr CPSR_c, r1 \n\t" \
|
||||
: \
|
||||
: "r" (LockState) \
|
||||
: "r0", "r1" \
|
||||
); \
|
||||
}
|
||||
#else
|
||||
#define SEGGER_RTT_LOCK()
|
||||
#define SEGGER_RTT_UNLOCK()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration for IAR EWARM
|
||||
*/
|
||||
#ifdef __ICCARM__
|
||||
#if (defined (__ARM6M__) && (__CORE__ == __ARM6M__))
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
LockState = __get_PRIMASK(); \
|
||||
__set_PRIMASK(1);
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \
|
||||
}
|
||||
#elif ((defined (__ARM7EM__) && (__CORE__ == __ARM7EM__)) || (defined (__ARM7M__) && (__CORE__ == __ARM7M__)))
|
||||
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
|
||||
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
|
||||
#endif
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
LockState = __get_BASEPRI(); \
|
||||
__set_BASEPRI(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __set_BASEPRI(LockState); \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration for IAR RX
|
||||
*/
|
||||
#ifdef __ICCRX__
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned long LockState; \
|
||||
LockState = __get_interrupt_state(); \
|
||||
__disable_interrupt();
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration for IAR RL78
|
||||
*/
|
||||
#ifdef __ICCRL78__
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
__istate_t LockState; \
|
||||
LockState = __get_interrupt_state(); \
|
||||
__disable_interrupt();
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __set_interrupt_state(LockState); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration for KEIL ARM
|
||||
*/
|
||||
#ifdef __CC_ARM
|
||||
#if (defined __TARGET_ARCH_6S_M)
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
register unsigned char PRIMASK __asm( "primask"); \
|
||||
LockState = PRIMASK; \
|
||||
PRIMASK = 1u; \
|
||||
__schedule_barrier();
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() PRIMASK = LockState; \
|
||||
__schedule_barrier(); \
|
||||
}
|
||||
#elif (defined(__TARGET_ARCH_7_M) || defined(__TARGET_ARCH_7E_M))
|
||||
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
|
||||
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
|
||||
#endif
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
register unsigned char BASEPRI __asm( "basepri"); \
|
||||
LockState = BASEPRI; \
|
||||
BASEPRI = SEGGER_RTT_MAX_INTERRUPT_PRIORITY; \
|
||||
__schedule_barrier();
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() BASEPRI = LockState; \
|
||||
__schedule_barrier(); \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration for TI ARM
|
||||
*/
|
||||
#ifdef __TI_ARM__
|
||||
#if defined (__TI_ARM_V6M0__)
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
LockState = __get_PRIMASK(); \
|
||||
__set_PRIMASK(1);
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() __set_PRIMASK(LockState); \
|
||||
}
|
||||
#elif (defined (__TI_ARM_V7M3__) || defined (__TI_ARM_V7M4__))
|
||||
#ifndef SEGGER_RTT_MAX_INTERRUPT_PRIORITY
|
||||
#define SEGGER_RTT_MAX_INTERRUPT_PRIORITY (0x20)
|
||||
#endif
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
LockState = _set_interrupt_priority(SEGGER_RTT_MAX_INTERRUPT_PRIORITY);
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() _set_interrupt_priority(LockState); \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration for CCRX
|
||||
*/
|
||||
#ifdef __RX
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned long LockState; \
|
||||
LockState = get_psw() & 0x010000; \
|
||||
clrpsw_i();
|
||||
|
||||
#define SEGGER_RTT_UNLOCK() set_psw(get_psw() | LockState); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* RTT lock configuration fallback
|
||||
*/
|
||||
#ifndef SEGGER_RTT_LOCK
|
||||
#define SEGGER_RTT_LOCK() // Lock RTT (nestable) (i.e. disable interrupts)
|
||||
#endif
|
||||
|
||||
#ifndef SEGGER_RTT_UNLOCK
|
||||
#define SEGGER_RTT_UNLOCK() // Unlock RTT (nestable) (i.e. enable previous interrupt lock state)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*************************** End of file ****************************/
|
||||
|
||||
+510
-510
File diff suppressed because it is too large
Load Diff
+130
-130
@@ -1,130 +1,130 @@
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* Solutions for real time microcontroller applications *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* SEGGER RTT * Real Time Transfer for embedded targets *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* SEGGER strongly recommends to not make any changes *
|
||||
* to or modify the source code of this software in order to stay *
|
||||
* compatible with the RTT protocol and J-Link. *
|
||||
* *
|
||||
* Redistribution and use in source and binary forms, with or *
|
||||
* without modification, are permitted provided that the following *
|
||||
* conditions are met: *
|
||||
* *
|
||||
* o Redistributions of source code must retain the above copyright *
|
||||
* notice, this list of conditions and the following disclaimer. *
|
||||
* *
|
||||
* o Redistributions in binary form must reproduce the above *
|
||||
* copyright notice, this list of conditions and the following *
|
||||
* disclaimer in the documentation and/or other materials provided *
|
||||
* with the distribution. *
|
||||
* *
|
||||
* o Neither the name of SEGGER Microcontroller GmbH *
|
||||
* nor the names of its contributors may be used to endorse or *
|
||||
* promote products derived from this software without specific *
|
||||
* prior written permission. *
|
||||
* *
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
|
||||
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
|
||||
* DAMAGE. *
|
||||
* *
|
||||
**********************************************************************
|
||||
---------------------------END-OF-HEADER------------------------------
|
||||
File : SEGGER_RTT_Syscalls_GCC.c
|
||||
Purpose : Low-level functions for using printf() via RTT in GCC.
|
||||
To use RTT for printf output, include this file in your
|
||||
application.
|
||||
Revision: $Rev: 9599 $
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#if (defined __GNUC__) && !(defined __SES_ARM) && !(defined __CROSSWORKS_ARM)
|
||||
|
||||
#include <reent.h> // required for _write_r
|
||||
#include "SEGGER_RTT.h"
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Types
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
//
|
||||
// If necessary define the _reent struct
|
||||
// to match the one passed by the used standard library.
|
||||
//
|
||||
struct _reent;
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Function prototypes
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
int _write(int file, char *ptr, int len);
|
||||
int _write_r(struct _reent *r, int file, const void *ptr, int len);
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Global functions
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _write()
|
||||
*
|
||||
* Function description
|
||||
* Low-level write function.
|
||||
* libc subroutines will use this system routine for output to all files,
|
||||
* including stdout.
|
||||
* Write data via RTT.
|
||||
*/
|
||||
int _write(int file, char *ptr, int len) {
|
||||
(void) file; /* Not used, avoid warning */
|
||||
SEGGER_RTT_Write(0, ptr, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _write_r()
|
||||
*
|
||||
* Function description
|
||||
* Low-level reentrant write function.
|
||||
* libc subroutines will use this system routine for output to all files,
|
||||
* including stdout.
|
||||
* Write data via RTT.
|
||||
*/
|
||||
int _write_r(struct _reent *r, int file, const void *ptr, int len) {
|
||||
(void) file; /* Not used, avoid warning */
|
||||
(void) r; /* Not used, avoid warning */
|
||||
SEGGER_RTT_Write(0, ptr, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
#endif
|
||||
/****** End Of File *************************************************/
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* Solutions for real time microcontroller applications *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* SEGGER RTT * Real Time Transfer for embedded targets *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* SEGGER strongly recommends to not make any changes *
|
||||
* to or modify the source code of this software in order to stay *
|
||||
* compatible with the RTT protocol and J-Link. *
|
||||
* *
|
||||
* Redistribution and use in source and binary forms, with or *
|
||||
* without modification, are permitted provided that the following *
|
||||
* conditions are met: *
|
||||
* *
|
||||
* o Redistributions of source code must retain the above copyright *
|
||||
* notice, this list of conditions and the following disclaimer. *
|
||||
* *
|
||||
* o Redistributions in binary form must reproduce the above *
|
||||
* copyright notice, this list of conditions and the following *
|
||||
* disclaimer in the documentation and/or other materials provided *
|
||||
* with the distribution. *
|
||||
* *
|
||||
* o Neither the name of SEGGER Microcontroller GmbH *
|
||||
* nor the names of its contributors may be used to endorse or *
|
||||
* promote products derived from this software without specific *
|
||||
* prior written permission. *
|
||||
* *
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
|
||||
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
|
||||
* DAMAGE. *
|
||||
* *
|
||||
**********************************************************************
|
||||
---------------------------END-OF-HEADER------------------------------
|
||||
File : SEGGER_RTT_Syscalls_GCC.c
|
||||
Purpose : Low-level functions for using printf() via RTT in GCC.
|
||||
To use RTT for printf output, include this file in your
|
||||
application.
|
||||
Revision: $Rev: 9599 $
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#if (defined __GNUC__) && !(defined __SES_ARM) && !(defined __CROSSWORKS_ARM)
|
||||
|
||||
#include <reent.h> // required for _write_r
|
||||
#include "SEGGER_RTT.h"
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Types
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
//
|
||||
// If necessary define the _reent struct
|
||||
// to match the one passed by the used standard library.
|
||||
//
|
||||
struct _reent;
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Function prototypes
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
int _write(int file, char *ptr, int len);
|
||||
int _write_r(struct _reent *r, int file, const void *ptr, int len);
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Global functions
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _write()
|
||||
*
|
||||
* Function description
|
||||
* Low-level write function.
|
||||
* libc subroutines will use this system routine for output to all files,
|
||||
* including stdout.
|
||||
* Write data via RTT.
|
||||
*/
|
||||
int _write(int file, char *ptr, int len) {
|
||||
(void) file; /* Not used, avoid warning */
|
||||
SEGGER_RTT_Write(0, ptr, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _write_r()
|
||||
*
|
||||
* Function description
|
||||
* Low-level reentrant write function.
|
||||
* libc subroutines will use this system routine for output to all files,
|
||||
* including stdout.
|
||||
* Write data via RTT.
|
||||
*/
|
||||
int _write_r(struct _reent *r, int file, const void *ptr, int len) {
|
||||
(void) file; /* Not used, avoid warning */
|
||||
(void) r; /* Not used, avoid warning */
|
||||
SEGGER_RTT_Write(0, ptr, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
#endif
|
||||
/****** End Of File *************************************************/
|
||||
|
||||
+124
-124
@@ -1,124 +1,124 @@
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* Solutions for real time microcontroller applications *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* SEGGER RTT * Real Time Transfer for embedded targets *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* SEGGER strongly recommends to not make any changes *
|
||||
* to or modify the source code of this software in order to stay *
|
||||
* compatible with the RTT protocol and J-Link. *
|
||||
* *
|
||||
* Redistribution and use in source and binary forms, with or *
|
||||
* without modification, are permitted provided that the following *
|
||||
* conditions are met: *
|
||||
* *
|
||||
* o Redistributions of source code must retain the above copyright *
|
||||
* notice, this list of conditions and the following disclaimer. *
|
||||
* *
|
||||
* o Redistributions in binary form must reproduce the above *
|
||||
* copyright notice, this list of conditions and the following *
|
||||
* disclaimer in the documentation and/or other materials provided *
|
||||
* with the distribution. *
|
||||
* *
|
||||
* o Neither the name of SEGGER Microcontroller GmbH *
|
||||
* nor the names of its contributors may be used to endorse or *
|
||||
* promote products derived from this software without specific *
|
||||
* prior written permission. *
|
||||
* *
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
|
||||
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
|
||||
* DAMAGE. *
|
||||
* *
|
||||
**********************************************************************
|
||||
---------------------------END-OF-HEADER------------------------------
|
||||
File : SEGGER_RTT_Syscalls_IAR.c
|
||||
Purpose : Low-level functions for using printf() via RTT in IAR.
|
||||
To use RTT for printf output, include this file in your
|
||||
application and set the Library Configuration to Normal.
|
||||
Revision: $Rev: 12303 $
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#ifdef __IAR_SYSTEMS_ICC__
|
||||
|
||||
//
|
||||
// Since IAR EWARM V8 yfuns.h is considered as deprecated and LowLevelIOInterface.h shall be used instead
|
||||
// To not break any compatibility with older compiler versions, we have a version check in here
|
||||
//
|
||||
#if __VER__ >= 8000000
|
||||
#include <LowLevelIOInterface.h>
|
||||
#else
|
||||
#include <yfuns.h>
|
||||
#endif
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
#pragma module_name = "?__write"
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Function prototypes
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
size_t __write(int handle, const unsigned char * buffer, size_t size);
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Global functions
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*********************************************************************
|
||||
*
|
||||
* __write()
|
||||
*
|
||||
* Function description
|
||||
* Low-level write function.
|
||||
* Standard library subroutines will use this system routine
|
||||
* for output to all files, including stdout.
|
||||
* Write data via RTT.
|
||||
*/
|
||||
size_t __write(int handle, const unsigned char * buffer, size_t size) {
|
||||
(void) handle; /* Not used, avoid warning */
|
||||
SEGGER_RTT_Write(0, (const char*)buffer, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* __write_buffered()
|
||||
*
|
||||
* Function description
|
||||
* Low-level write function.
|
||||
* Standard library subroutines will use this system routine
|
||||
* for output to all files, including stdout.
|
||||
* Write data via RTT.
|
||||
*/
|
||||
size_t __write_buffered(int handle, const unsigned char * buffer, size_t size) {
|
||||
(void) handle; /* Not used, avoid warning */
|
||||
SEGGER_RTT_Write(0, (const char*)buffer, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
#endif
|
||||
/****** End Of File *************************************************/
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* Solutions for real time microcontroller applications *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* SEGGER RTT * Real Time Transfer for embedded targets *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* SEGGER strongly recommends to not make any changes *
|
||||
* to or modify the source code of this software in order to stay *
|
||||
* compatible with the RTT protocol and J-Link. *
|
||||
* *
|
||||
* Redistribution and use in source and binary forms, with or *
|
||||
* without modification, are permitted provided that the following *
|
||||
* conditions are met: *
|
||||
* *
|
||||
* o Redistributions of source code must retain the above copyright *
|
||||
* notice, this list of conditions and the following disclaimer. *
|
||||
* *
|
||||
* o Redistributions in binary form must reproduce the above *
|
||||
* copyright notice, this list of conditions and the following *
|
||||
* disclaimer in the documentation and/or other materials provided *
|
||||
* with the distribution. *
|
||||
* *
|
||||
* o Neither the name of SEGGER Microcontroller GmbH *
|
||||
* nor the names of its contributors may be used to endorse or *
|
||||
* promote products derived from this software without specific *
|
||||
* prior written permission. *
|
||||
* *
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
|
||||
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
|
||||
* DAMAGE. *
|
||||
* *
|
||||
**********************************************************************
|
||||
---------------------------END-OF-HEADER------------------------------
|
||||
File : SEGGER_RTT_Syscalls_IAR.c
|
||||
Purpose : Low-level functions for using printf() via RTT in IAR.
|
||||
To use RTT for printf output, include this file in your
|
||||
application and set the Library Configuration to Normal.
|
||||
Revision: $Rev: 12303 $
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#ifdef __IAR_SYSTEMS_ICC__
|
||||
|
||||
//
|
||||
// Since IAR EWARM V8 yfuns.h is considered as deprecated and LowLevelIOInterface.h shall be used instead
|
||||
// To not break any compatibility with older compiler versions, we have a version check in here
|
||||
//
|
||||
#if __VER__ >= 8000000
|
||||
#include <LowLevelIOInterface.h>
|
||||
#else
|
||||
#include <yfuns.h>
|
||||
#endif
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
#pragma module_name = "?__write"
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Function prototypes
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
size_t __write(int handle, const unsigned char * buffer, size_t size);
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Global functions
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*********************************************************************
|
||||
*
|
||||
* __write()
|
||||
*
|
||||
* Function description
|
||||
* Low-level write function.
|
||||
* Standard library subroutines will use this system routine
|
||||
* for output to all files, including stdout.
|
||||
* Write data via RTT.
|
||||
*/
|
||||
size_t __write(int handle, const unsigned char * buffer, size_t size) {
|
||||
(void) handle; /* Not used, avoid warning */
|
||||
SEGGER_RTT_Write(0, (const char*)buffer, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* __write_buffered()
|
||||
*
|
||||
* Function description
|
||||
* Low-level write function.
|
||||
* Standard library subroutines will use this system routine
|
||||
* for output to all files, including stdout.
|
||||
* Write data via RTT.
|
||||
*/
|
||||
size_t __write_buffered(int handle, const unsigned char * buffer, size_t size) {
|
||||
(void) handle; /* Not used, avoid warning */
|
||||
SEGGER_RTT_Write(0, (const char*)buffer, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
#endif
|
||||
/****** End Of File *************************************************/
|
||||
|
||||
+374
-374
@@ -1,374 +1,374 @@
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* Solutions for real time microcontroller applications *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* SEGGER RTT * Real Time Transfer for embedded targets *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* SEGGER strongly recommends to not make any changes *
|
||||
* to or modify the source code of this software in order to stay *
|
||||
* compatible with the RTT protocol and J-Link. *
|
||||
* *
|
||||
* Redistribution and use in source and binary forms, with or *
|
||||
* without modification, are permitted provided that the following *
|
||||
* conditions are met: *
|
||||
* *
|
||||
* o Redistributions of source code must retain the above copyright *
|
||||
* notice, this list of conditions and the following disclaimer. *
|
||||
* *
|
||||
* o Redistributions in binary form must reproduce the above *
|
||||
* copyright notice, this list of conditions and the following *
|
||||
* disclaimer in the documentation and/or other materials provided *
|
||||
* with the distribution. *
|
||||
* *
|
||||
* o Neither the name of SEGGER Microcontroller GmbH *
|
||||
* nor the names of its contributors may be used to endorse or *
|
||||
* promote products derived from this software without specific *
|
||||
* prior written permission. *
|
||||
* *
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
|
||||
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
|
||||
* DAMAGE. *
|
||||
* *
|
||||
**********************************************************************
|
||||
---------------------------END-OF-HEADER------------------------------
|
||||
File : RTT_Syscalls_KEIL.c
|
||||
Purpose : Retargeting module for KEIL MDK-CM3.
|
||||
Low-level functions for using printf() via RTT
|
||||
Revision: $Rev: 9599 $
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#ifdef __CC_ARM
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <rt_sys.h>
|
||||
#include <rt_misc.h>
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
/*********************************************************************
|
||||
*
|
||||
* #pragmas
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
#pragma import(__use_no_semihosting)
|
||||
|
||||
#ifdef _MICROLIB
|
||||
#pragma import(__use_full_stdio)
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Defines non-configurable
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/* Standard IO device handles - arbitrary, but any real file system handles must be
|
||||
less than 0x8000. */
|
||||
#define STDIN 0x8001 // Standard Input Stream
|
||||
#define STDOUT 0x8002 // Standard Output Stream
|
||||
#define STDERR 0x8003 // Standard Error Stream
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Public const
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
//const char __stdin_name[] = "STDIN";
|
||||
const char __stdout_name[] = "STDOUT";
|
||||
const char __stderr_name[] = "STDERR";
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Public code
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _ttywrch
|
||||
*
|
||||
* Function description:
|
||||
* Outputs a character to the console
|
||||
*
|
||||
* Parameters:
|
||||
* c - character to output
|
||||
*
|
||||
*/
|
||||
void _ttywrch(int c) {
|
||||
fputc(c, stdout); // stdout
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_open
|
||||
*
|
||||
* Function description:
|
||||
* Opens the device/file in order to do read/write operations
|
||||
*
|
||||
* Parameters:
|
||||
* sName - sName of the device/file to open
|
||||
* OpenMode - This parameter is currently ignored
|
||||
*
|
||||
* Return value:
|
||||
* != 0 - Handle to the object to open, otherwise
|
||||
* == 0 -"device" is not handled by this module
|
||||
*
|
||||
*/
|
||||
FILEHANDLE _sys_open(const char * sName, int OpenMode) {
|
||||
(void)OpenMode;
|
||||
// Register standard Input Output devices.
|
||||
if (strcmp(sName, __stdout_name) == 0) {
|
||||
return (STDOUT);
|
||||
} else if (strcmp(sName, __stderr_name) == 0) {
|
||||
return (STDERR);
|
||||
} else
|
||||
return (0); // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_close
|
||||
*
|
||||
* Function description:
|
||||
* Closes the handle to the open device/file
|
||||
*
|
||||
* Parameters:
|
||||
* hFile - Handle to a file opened via _sys_open
|
||||
*
|
||||
* Return value:
|
||||
* 0 - device/file closed
|
||||
*
|
||||
*/
|
||||
int _sys_close(FILEHANDLE hFile) {
|
||||
(void)hFile;
|
||||
return 0; // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_write
|
||||
*
|
||||
* Function description:
|
||||
* Writes the data to an open handle.
|
||||
* Currently this function only outputs data to the console
|
||||
*
|
||||
* Parameters:
|
||||
* hFile - Handle to a file opened via _sys_open
|
||||
* pBuffer - Pointer to the data that shall be written
|
||||
* NumBytes - Number of bytes to write
|
||||
* Mode - The Mode that shall be used
|
||||
*
|
||||
* Return value:
|
||||
* Number of bytes *not* written to the file/device
|
||||
*
|
||||
*/
|
||||
int _sys_write(FILEHANDLE hFile, const unsigned char * pBuffer, unsigned NumBytes, int Mode) {
|
||||
int r = 0;
|
||||
|
||||
(void)Mode;
|
||||
if (hFile == STDOUT) {
|
||||
return NumBytes - SEGGER_RTT_Write(0, (const char*)pBuffer, NumBytes);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_read
|
||||
*
|
||||
* Function description:
|
||||
* Reads data from an open handle.
|
||||
* Currently this modules does nothing.
|
||||
*
|
||||
* Parameters:
|
||||
* hFile - Handle to a file opened via _sys_open
|
||||
* pBuffer - Pointer to buffer to store the read data
|
||||
* NumBytes - Number of bytes to read
|
||||
* Mode - The Mode that shall be used
|
||||
*
|
||||
* Return value:
|
||||
* Number of bytes read from the file/device
|
||||
*
|
||||
*/
|
||||
int _sys_read(FILEHANDLE hFile, unsigned char * pBuffer, unsigned NumBytes, int Mode) {
|
||||
(void)hFile;
|
||||
(void)pBuffer;
|
||||
(void)NumBytes;
|
||||
(void)Mode;
|
||||
return (0); // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_istty
|
||||
*
|
||||
* Function description:
|
||||
* This function shall return whether the opened file
|
||||
* is a console device or not.
|
||||
*
|
||||
* Parameters:
|
||||
* hFile - Handle to a file opened via _sys_open
|
||||
*
|
||||
* Return value:
|
||||
* 1 - Device is a console
|
||||
* 0 - Device is not a console
|
||||
*
|
||||
*/
|
||||
int _sys_istty(FILEHANDLE hFile) {
|
||||
if (hFile > 0x8000) {
|
||||
return (1);
|
||||
}
|
||||
return (0); // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_seek
|
||||
*
|
||||
* Function description:
|
||||
* Seeks via the file to a specific position
|
||||
*
|
||||
* Parameters:
|
||||
* hFile - Handle to a file opened via _sys_open
|
||||
* Pos -
|
||||
*
|
||||
* Return value:
|
||||
* int -
|
||||
*
|
||||
*/
|
||||
int _sys_seek(FILEHANDLE hFile, long Pos) {
|
||||
(void)hFile;
|
||||
(void)Pos;
|
||||
return (0); // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_ensure
|
||||
*
|
||||
* Function description:
|
||||
*
|
||||
*
|
||||
* Parameters:
|
||||
* hFile - Handle to a file opened via _sys_open
|
||||
*
|
||||
* Return value:
|
||||
* int -
|
||||
*
|
||||
*/
|
||||
int _sys_ensure(FILEHANDLE hFile) {
|
||||
(void)hFile;
|
||||
return (-1); // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_flen
|
||||
*
|
||||
* Function description:
|
||||
* Returns the length of the opened file handle
|
||||
*
|
||||
* Parameters:
|
||||
* hFile - Handle to a file opened via _sys_open
|
||||
*
|
||||
* Return value:
|
||||
* Length of the file
|
||||
*
|
||||
*/
|
||||
long _sys_flen(FILEHANDLE hFile) {
|
||||
(void)hFile;
|
||||
return (0); // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_tmpnam
|
||||
*
|
||||
* Function description:
|
||||
* This function converts the file number fileno for a temporary
|
||||
* file to a unique filename, for example, tmp0001.
|
||||
*
|
||||
* Parameters:
|
||||
* pBuffer - Pointer to a buffer to store the name
|
||||
* FileNum - file number to convert
|
||||
* MaxLen - Size of the buffer
|
||||
*
|
||||
* Return value:
|
||||
* 1 - Error
|
||||
* 0 - Success
|
||||
*
|
||||
*/
|
||||
int _sys_tmpnam(char * pBuffer, int FileNum, unsigned MaxLen) {
|
||||
(void)pBuffer;
|
||||
(void)FileNum;
|
||||
(void)MaxLen;
|
||||
return (1); // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_command_string
|
||||
*
|
||||
* Function description:
|
||||
* This function shall execute a system command.
|
||||
*
|
||||
* Parameters:
|
||||
* cmd - Pointer to the command string
|
||||
* len - Length of the string
|
||||
*
|
||||
* Return value:
|
||||
* == NULL - Command was not successfully executed
|
||||
* == sCmd - Command was passed successfully
|
||||
*
|
||||
*/
|
||||
char * _sys_command_string(char * cmd, int len) {
|
||||
(void)len;
|
||||
return cmd; // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_exit
|
||||
*
|
||||
* Function description:
|
||||
* This function is called when the application returns from main
|
||||
*
|
||||
* Parameters:
|
||||
* ReturnCode - Return code from the main function
|
||||
*
|
||||
*
|
||||
*/
|
||||
void _sys_exit(int ReturnCode) {
|
||||
(void)ReturnCode;
|
||||
while (1); // Not implemented
|
||||
}
|
||||
|
||||
#endif
|
||||
/*************************** End of file ****************************/
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* Solutions for real time microcontroller applications *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* SEGGER RTT * Real Time Transfer for embedded targets *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* SEGGER strongly recommends to not make any changes *
|
||||
* to or modify the source code of this software in order to stay *
|
||||
* compatible with the RTT protocol and J-Link. *
|
||||
* *
|
||||
* Redistribution and use in source and binary forms, with or *
|
||||
* without modification, are permitted provided that the following *
|
||||
* conditions are met: *
|
||||
* *
|
||||
* o Redistributions of source code must retain the above copyright *
|
||||
* notice, this list of conditions and the following disclaimer. *
|
||||
* *
|
||||
* o Redistributions in binary form must reproduce the above *
|
||||
* copyright notice, this list of conditions and the following *
|
||||
* disclaimer in the documentation and/or other materials provided *
|
||||
* with the distribution. *
|
||||
* *
|
||||
* o Neither the name of SEGGER Microcontroller GmbH *
|
||||
* nor the names of its contributors may be used to endorse or *
|
||||
* promote products derived from this software without specific *
|
||||
* prior written permission. *
|
||||
* *
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
|
||||
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
|
||||
* DAMAGE. *
|
||||
* *
|
||||
**********************************************************************
|
||||
---------------------------END-OF-HEADER------------------------------
|
||||
File : RTT_Syscalls_KEIL.c
|
||||
Purpose : Retargeting module for KEIL MDK-CM3.
|
||||
Low-level functions for using printf() via RTT
|
||||
Revision: $Rev: 9599 $
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#ifdef __CC_ARM
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <rt_sys.h>
|
||||
#include <rt_misc.h>
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
/*********************************************************************
|
||||
*
|
||||
* #pragmas
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
#pragma import(__use_no_semihosting)
|
||||
|
||||
#ifdef _MICROLIB
|
||||
#pragma import(__use_full_stdio)
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Defines non-configurable
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/* Standard IO device handles - arbitrary, but any real file system handles must be
|
||||
less than 0x8000. */
|
||||
#define STDIN 0x8001 // Standard Input Stream
|
||||
#define STDOUT 0x8002 // Standard Output Stream
|
||||
#define STDERR 0x8003 // Standard Error Stream
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Public const
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
//const char __stdin_name[] = "STDIN";
|
||||
const char __stdout_name[] = "STDOUT";
|
||||
const char __stderr_name[] = "STDERR";
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Public code
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _ttywrch
|
||||
*
|
||||
* Function description:
|
||||
* Outputs a character to the console
|
||||
*
|
||||
* Parameters:
|
||||
* c - character to output
|
||||
*
|
||||
*/
|
||||
void _ttywrch(int c) {
|
||||
fputc(c, stdout); // stdout
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_open
|
||||
*
|
||||
* Function description:
|
||||
* Opens the device/file in order to do read/write operations
|
||||
*
|
||||
* Parameters:
|
||||
* sName - sName of the device/file to open
|
||||
* OpenMode - This parameter is currently ignored
|
||||
*
|
||||
* Return value:
|
||||
* != 0 - Handle to the object to open, otherwise
|
||||
* == 0 -"device" is not handled by this module
|
||||
*
|
||||
*/
|
||||
FILEHANDLE _sys_open(const char * sName, int OpenMode) {
|
||||
(void)OpenMode;
|
||||
// Register standard Input Output devices.
|
||||
if (strcmp(sName, __stdout_name) == 0) {
|
||||
return (STDOUT);
|
||||
} else if (strcmp(sName, __stderr_name) == 0) {
|
||||
return (STDERR);
|
||||
} else
|
||||
return (0); // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_close
|
||||
*
|
||||
* Function description:
|
||||
* Closes the handle to the open device/file
|
||||
*
|
||||
* Parameters:
|
||||
* hFile - Handle to a file opened via _sys_open
|
||||
*
|
||||
* Return value:
|
||||
* 0 - device/file closed
|
||||
*
|
||||
*/
|
||||
int _sys_close(FILEHANDLE hFile) {
|
||||
(void)hFile;
|
||||
return 0; // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_write
|
||||
*
|
||||
* Function description:
|
||||
* Writes the data to an open handle.
|
||||
* Currently this function only outputs data to the console
|
||||
*
|
||||
* Parameters:
|
||||
* hFile - Handle to a file opened via _sys_open
|
||||
* pBuffer - Pointer to the data that shall be written
|
||||
* NumBytes - Number of bytes to write
|
||||
* Mode - The Mode that shall be used
|
||||
*
|
||||
* Return value:
|
||||
* Number of bytes *not* written to the file/device
|
||||
*
|
||||
*/
|
||||
int _sys_write(FILEHANDLE hFile, const unsigned char * pBuffer, unsigned NumBytes, int Mode) {
|
||||
int r = 0;
|
||||
|
||||
(void)Mode;
|
||||
if (hFile == STDOUT) {
|
||||
return NumBytes - SEGGER_RTT_Write(0, (const char*)pBuffer, NumBytes);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_read
|
||||
*
|
||||
* Function description:
|
||||
* Reads data from an open handle.
|
||||
* Currently this modules does nothing.
|
||||
*
|
||||
* Parameters:
|
||||
* hFile - Handle to a file opened via _sys_open
|
||||
* pBuffer - Pointer to buffer to store the read data
|
||||
* NumBytes - Number of bytes to read
|
||||
* Mode - The Mode that shall be used
|
||||
*
|
||||
* Return value:
|
||||
* Number of bytes read from the file/device
|
||||
*
|
||||
*/
|
||||
int _sys_read(FILEHANDLE hFile, unsigned char * pBuffer, unsigned NumBytes, int Mode) {
|
||||
(void)hFile;
|
||||
(void)pBuffer;
|
||||
(void)NumBytes;
|
||||
(void)Mode;
|
||||
return (0); // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_istty
|
||||
*
|
||||
* Function description:
|
||||
* This function shall return whether the opened file
|
||||
* is a console device or not.
|
||||
*
|
||||
* Parameters:
|
||||
* hFile - Handle to a file opened via _sys_open
|
||||
*
|
||||
* Return value:
|
||||
* 1 - Device is a console
|
||||
* 0 - Device is not a console
|
||||
*
|
||||
*/
|
||||
int _sys_istty(FILEHANDLE hFile) {
|
||||
if (hFile > 0x8000) {
|
||||
return (1);
|
||||
}
|
||||
return (0); // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_seek
|
||||
*
|
||||
* Function description:
|
||||
* Seeks via the file to a specific position
|
||||
*
|
||||
* Parameters:
|
||||
* hFile - Handle to a file opened via _sys_open
|
||||
* Pos -
|
||||
*
|
||||
* Return value:
|
||||
* int -
|
||||
*
|
||||
*/
|
||||
int _sys_seek(FILEHANDLE hFile, long Pos) {
|
||||
(void)hFile;
|
||||
(void)Pos;
|
||||
return (0); // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_ensure
|
||||
*
|
||||
* Function description:
|
||||
*
|
||||
*
|
||||
* Parameters:
|
||||
* hFile - Handle to a file opened via _sys_open
|
||||
*
|
||||
* Return value:
|
||||
* int -
|
||||
*
|
||||
*/
|
||||
int _sys_ensure(FILEHANDLE hFile) {
|
||||
(void)hFile;
|
||||
return (-1); // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_flen
|
||||
*
|
||||
* Function description:
|
||||
* Returns the length of the opened file handle
|
||||
*
|
||||
* Parameters:
|
||||
* hFile - Handle to a file opened via _sys_open
|
||||
*
|
||||
* Return value:
|
||||
* Length of the file
|
||||
*
|
||||
*/
|
||||
long _sys_flen(FILEHANDLE hFile) {
|
||||
(void)hFile;
|
||||
return (0); // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_tmpnam
|
||||
*
|
||||
* Function description:
|
||||
* This function converts the file number fileno for a temporary
|
||||
* file to a unique filename, for example, tmp0001.
|
||||
*
|
||||
* Parameters:
|
||||
* pBuffer - Pointer to a buffer to store the name
|
||||
* FileNum - file number to convert
|
||||
* MaxLen - Size of the buffer
|
||||
*
|
||||
* Return value:
|
||||
* 1 - Error
|
||||
* 0 - Success
|
||||
*
|
||||
*/
|
||||
int _sys_tmpnam(char * pBuffer, int FileNum, unsigned MaxLen) {
|
||||
(void)pBuffer;
|
||||
(void)FileNum;
|
||||
(void)MaxLen;
|
||||
return (1); // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_command_string
|
||||
*
|
||||
* Function description:
|
||||
* This function shall execute a system command.
|
||||
*
|
||||
* Parameters:
|
||||
* cmd - Pointer to the command string
|
||||
* len - Length of the string
|
||||
*
|
||||
* Return value:
|
||||
* == NULL - Command was not successfully executed
|
||||
* == sCmd - Command was passed successfully
|
||||
*
|
||||
*/
|
||||
char * _sys_command_string(char * cmd, int len) {
|
||||
(void)len;
|
||||
return cmd; // Not implemented
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* _sys_exit
|
||||
*
|
||||
* Function description:
|
||||
* This function is called when the application returns from main
|
||||
*
|
||||
* Parameters:
|
||||
* ReturnCode - Return code from the main function
|
||||
*
|
||||
*
|
||||
*/
|
||||
void _sys_exit(int ReturnCode) {
|
||||
(void)ReturnCode;
|
||||
while (1); // Not implemented
|
||||
}
|
||||
|
||||
#endif
|
||||
/*************************** End of file ****************************/
|
||||
|
||||
+257
-257
@@ -1,257 +1,257 @@
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* The Embedded Experts *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* SEGGER RTT * Real Time Transfer for embedded targets *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* SEGGER strongly recommends to not make any changes *
|
||||
* to or modify the source code of this software in order to stay *
|
||||
* compatible with the RTT protocol and J-Link. *
|
||||
* *
|
||||
* Redistribution and use in source and binary forms, with or *
|
||||
* without modification, are permitted provided that the following *
|
||||
* conditions are met: *
|
||||
* *
|
||||
* o Redistributions of source code must retain the above copyright *
|
||||
* notice, this list of conditions and the following disclaimer. *
|
||||
* *
|
||||
* o Redistributions in binary form must reproduce the above *
|
||||
* copyright notice, this list of conditions and the following *
|
||||
* disclaimer in the documentation and/or other materials provided *
|
||||
* with the distribution. *
|
||||
* *
|
||||
* o Neither the name of SEGGER Microcontroller GmbH *
|
||||
* nor the names of its contributors may be used to endorse or *
|
||||
* promote products derived from this software without specific *
|
||||
* prior written permission. *
|
||||
* *
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
|
||||
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
|
||||
* DAMAGE. *
|
||||
* *
|
||||
**********************************************************************
|
||||
---------------------------END-OF-HEADER------------------------------
|
||||
File : SEGGER_RTT_Syscalls_SES.c
|
||||
Purpose : Reimplementation of printf, puts and __getchar using RTT
|
||||
in SEGGER Embedded Studio.
|
||||
To use RTT for printf output, include this file in your
|
||||
application.
|
||||
Revision: $Rev: 12804 $
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#if (defined __SES_ARM) || (defined __CROSSWORKS_ARM)
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include "limits.h"
|
||||
#include "__libc.h"
|
||||
#include "__vfprintf.h"
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Defines, configurable
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
//
|
||||
// Select string formatting implementation.
|
||||
//
|
||||
// RTT printf formatting
|
||||
// - Configurable stack usage. (SEGGER_RTT_PRINTF_BUFFER_SIZE in SEGGER_RTT_Conf.h)
|
||||
// - No maximum string length.
|
||||
// - Limited conversion specifiers and flags. (See SEGGER_RTT_printf.c)
|
||||
// Standard library printf formatting
|
||||
// - Configurable formatting capabilities.
|
||||
// - Full conversion specifier and flag support.
|
||||
// - Maximum string length has to be known or (slightly) slower character-wise output.
|
||||
//
|
||||
// #define PRINTF_USE_SEGGER_RTT_FORMATTING 0 // Use standard library formatting
|
||||
// #define PRINTF_USE_SEGGER_RTT_FORMATTING 1 // Use RTT formatting
|
||||
//
|
||||
#ifndef PRINTF_USE_SEGGER_RTT_FORMATTING
|
||||
#define PRINTF_USE_SEGGER_RTT_FORMATTING 0
|
||||
#endif
|
||||
//
|
||||
// If using standard library formatting,
|
||||
// select maximum output string buffer size or character-wise output.
|
||||
//
|
||||
// #define PRINTF_BUFFER_SIZE 0 // Use character-wise output
|
||||
// #define PRINTF_BUFFER_SIZE 128 // Default maximum string length
|
||||
//
|
||||
#ifndef PRINTF_BUFFER_SIZE
|
||||
#define PRINTF_BUFFER_SIZE 128
|
||||
#endif
|
||||
|
||||
#if PRINTF_USE_SEGGER_RTT_FORMATTING // Use SEGGER RTT formatting implementation
|
||||
/*********************************************************************
|
||||
*
|
||||
* Function prototypes
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Global functions, printf
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*********************************************************************
|
||||
*
|
||||
* printf()
|
||||
*
|
||||
* Function description
|
||||
* print a formatted string using RTT and SEGGER RTT formatting.
|
||||
*/
|
||||
int printf(const char *fmt,...) {
|
||||
int n;
|
||||
va_list args;
|
||||
|
||||
va_start (args, fmt);
|
||||
n = SEGGER_RTT_vprintf(0, fmt, &args);
|
||||
va_end(args);
|
||||
return n;
|
||||
}
|
||||
|
||||
#elif PRINTF_BUFFER_SIZE == 0 // Use standard library formatting with character-wise output
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Static functions
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
static int _putchar(int x, __printf_tag_ptr ctx) {
|
||||
(void)ctx;
|
||||
SEGGER_RTT_Write(0, (char *)&x, 1);
|
||||
return x;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Global functions, printf
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*********************************************************************
|
||||
*
|
||||
* printf()
|
||||
*
|
||||
* Function description
|
||||
* print a formatted string character-wise, using RTT and standard
|
||||
* library formatting.
|
||||
*/
|
||||
int printf(const char *fmt, ...) {
|
||||
int n;
|
||||
va_list args;
|
||||
__printf_t iod;
|
||||
|
||||
va_start(args, fmt);
|
||||
iod.string = 0;
|
||||
iod.maxchars = INT_MAX;
|
||||
iod.output_fn = _putchar;
|
||||
SEGGER_RTT_LOCK();
|
||||
n = __vfprintf(&iod, fmt, args);
|
||||
SEGGER_RTT_UNLOCK();
|
||||
va_end(args);
|
||||
return n;
|
||||
}
|
||||
|
||||
#else // Use standard library formatting with static buffer
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Global functions, printf
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*********************************************************************
|
||||
*
|
||||
* printf()
|
||||
*
|
||||
* Function description
|
||||
* print a formatted string using RTT and standard library formatting.
|
||||
*/
|
||||
int printf(const char *fmt,...) {
|
||||
int n;
|
||||
char aBuffer[PRINTF_BUFFER_SIZE];
|
||||
va_list args;
|
||||
|
||||
va_start (args, fmt);
|
||||
n = vsnprintf(aBuffer, sizeof(aBuffer), fmt, args);
|
||||
if (n > (int)sizeof(aBuffer)) {
|
||||
SEGGER_RTT_Write(0, aBuffer, sizeof(aBuffer));
|
||||
} else if (n > 0) {
|
||||
SEGGER_RTT_Write(0, aBuffer, n);
|
||||
}
|
||||
va_end(args);
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Global functions
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*********************************************************************
|
||||
*
|
||||
* puts()
|
||||
*
|
||||
* Function description
|
||||
* print a string using RTT.
|
||||
*/
|
||||
int puts(const char *s) {
|
||||
return SEGGER_RTT_WriteString(0, s);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* __putchar()
|
||||
*
|
||||
* Function description
|
||||
* Write one character via RTT.
|
||||
*/
|
||||
int __putchar(int x, __printf_tag_ptr ctx) {
|
||||
(void)ctx;
|
||||
SEGGER_RTT_Write(0, (char *)&x, 1);
|
||||
return x;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* __getchar()
|
||||
*
|
||||
* Function description
|
||||
* Wait for and get a character via RTT.
|
||||
*/
|
||||
int __getchar() {
|
||||
return SEGGER_RTT_WaitKey();
|
||||
}
|
||||
|
||||
#endif
|
||||
/****** End Of File *************************************************/
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
* The Embedded Experts *
|
||||
**********************************************************************
|
||||
* *
|
||||
* (c) 1995 - 2018 SEGGER Microcontroller GmbH *
|
||||
* *
|
||||
* www.segger.com Support: support@segger.com *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* SEGGER RTT * Real Time Transfer for embedded targets *
|
||||
* *
|
||||
**********************************************************************
|
||||
* *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* SEGGER strongly recommends to not make any changes *
|
||||
* to or modify the source code of this software in order to stay *
|
||||
* compatible with the RTT protocol and J-Link. *
|
||||
* *
|
||||
* Redistribution and use in source and binary forms, with or *
|
||||
* without modification, are permitted provided that the following *
|
||||
* conditions are met: *
|
||||
* *
|
||||
* o Redistributions of source code must retain the above copyright *
|
||||
* notice, this list of conditions and the following disclaimer. *
|
||||
* *
|
||||
* o Redistributions in binary form must reproduce the above *
|
||||
* copyright notice, this list of conditions and the following *
|
||||
* disclaimer in the documentation and/or other materials provided *
|
||||
* with the distribution. *
|
||||
* *
|
||||
* o Neither the name of SEGGER Microcontroller GmbH *
|
||||
* nor the names of its contributors may be used to endorse or *
|
||||
* promote products derived from this software without specific *
|
||||
* prior written permission. *
|
||||
* *
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
|
||||
* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
|
||||
* DAMAGE. *
|
||||
* *
|
||||
**********************************************************************
|
||||
---------------------------END-OF-HEADER------------------------------
|
||||
File : SEGGER_RTT_Syscalls_SES.c
|
||||
Purpose : Reimplementation of printf, puts and __getchar using RTT
|
||||
in SEGGER Embedded Studio.
|
||||
To use RTT for printf output, include this file in your
|
||||
application.
|
||||
Revision: $Rev: 12804 $
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#if (defined __SES_ARM) || (defined __CROSSWORKS_ARM)
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include "limits.h"
|
||||
#include "__libc.h"
|
||||
#include "__vfprintf.h"
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Defines, configurable
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
//
|
||||
// Select string formatting implementation.
|
||||
//
|
||||
// RTT printf formatting
|
||||
// - Configurable stack usage. (SEGGER_RTT_PRINTF_BUFFER_SIZE in SEGGER_RTT_Conf.h)
|
||||
// - No maximum string length.
|
||||
// - Limited conversion specifiers and flags. (See SEGGER_RTT_printf.c)
|
||||
// Standard library printf formatting
|
||||
// - Configurable formatting capabilities.
|
||||
// - Full conversion specifier and flag support.
|
||||
// - Maximum string length has to be known or (slightly) slower character-wise output.
|
||||
//
|
||||
// #define PRINTF_USE_SEGGER_RTT_FORMATTING 0 // Use standard library formatting
|
||||
// #define PRINTF_USE_SEGGER_RTT_FORMATTING 1 // Use RTT formatting
|
||||
//
|
||||
#ifndef PRINTF_USE_SEGGER_RTT_FORMATTING
|
||||
#define PRINTF_USE_SEGGER_RTT_FORMATTING 0
|
||||
#endif
|
||||
//
|
||||
// If using standard library formatting,
|
||||
// select maximum output string buffer size or character-wise output.
|
||||
//
|
||||
// #define PRINTF_BUFFER_SIZE 0 // Use character-wise output
|
||||
// #define PRINTF_BUFFER_SIZE 128 // Default maximum string length
|
||||
//
|
||||
#ifndef PRINTF_BUFFER_SIZE
|
||||
#define PRINTF_BUFFER_SIZE 128
|
||||
#endif
|
||||
|
||||
#if PRINTF_USE_SEGGER_RTT_FORMATTING // Use SEGGER RTT formatting implementation
|
||||
/*********************************************************************
|
||||
*
|
||||
* Function prototypes
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Global functions, printf
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*********************************************************************
|
||||
*
|
||||
* printf()
|
||||
*
|
||||
* Function description
|
||||
* print a formatted string using RTT and SEGGER RTT formatting.
|
||||
*/
|
||||
int printf(const char *fmt,...) {
|
||||
int n;
|
||||
va_list args;
|
||||
|
||||
va_start (args, fmt);
|
||||
n = SEGGER_RTT_vprintf(0, fmt, &args);
|
||||
va_end(args);
|
||||
return n;
|
||||
}
|
||||
|
||||
#elif PRINTF_BUFFER_SIZE == 0 // Use standard library formatting with character-wise output
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Static functions
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
static int _putchar(int x, __printf_tag_ptr ctx) {
|
||||
(void)ctx;
|
||||
SEGGER_RTT_Write(0, (char *)&x, 1);
|
||||
return x;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Global functions, printf
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*********************************************************************
|
||||
*
|
||||
* printf()
|
||||
*
|
||||
* Function description
|
||||
* print a formatted string character-wise, using RTT and standard
|
||||
* library formatting.
|
||||
*/
|
||||
int printf(const char *fmt, ...) {
|
||||
int n;
|
||||
va_list args;
|
||||
__printf_t iod;
|
||||
|
||||
va_start(args, fmt);
|
||||
iod.string = 0;
|
||||
iod.maxchars = INT_MAX;
|
||||
iod.output_fn = _putchar;
|
||||
SEGGER_RTT_LOCK();
|
||||
n = __vfprintf(&iod, fmt, args);
|
||||
SEGGER_RTT_UNLOCK();
|
||||
va_end(args);
|
||||
return n;
|
||||
}
|
||||
|
||||
#else // Use standard library formatting with static buffer
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Global functions, printf
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*********************************************************************
|
||||
*
|
||||
* printf()
|
||||
*
|
||||
* Function description
|
||||
* print a formatted string using RTT and standard library formatting.
|
||||
*/
|
||||
int printf(const char *fmt,...) {
|
||||
int n;
|
||||
char aBuffer[PRINTF_BUFFER_SIZE];
|
||||
va_list args;
|
||||
|
||||
va_start (args, fmt);
|
||||
n = vsnprintf(aBuffer, sizeof(aBuffer), fmt, args);
|
||||
if (n > (int)sizeof(aBuffer)) {
|
||||
SEGGER_RTT_Write(0, aBuffer, sizeof(aBuffer));
|
||||
} else if (n > 0) {
|
||||
SEGGER_RTT_Write(0, aBuffer, n);
|
||||
}
|
||||
va_end(args);
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* Global functions
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
/*********************************************************************
|
||||
*
|
||||
* puts()
|
||||
*
|
||||
* Function description
|
||||
* print a string using RTT.
|
||||
*/
|
||||
int puts(const char *s) {
|
||||
return SEGGER_RTT_WriteString(0, s);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* __putchar()
|
||||
*
|
||||
* Function description
|
||||
* Write one character via RTT.
|
||||
*/
|
||||
int __putchar(int x, __printf_tag_ptr ctx) {
|
||||
(void)ctx;
|
||||
SEGGER_RTT_Write(0, (char *)&x, 1);
|
||||
return x;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
* __getchar()
|
||||
*
|
||||
* Function description
|
||||
* Wait for and get a character via RTT.
|
||||
*/
|
||||
int __getchar() {
|
||||
return SEGGER_RTT_WaitKey();
|
||||
}
|
||||
|
||||
#endif
|
||||
/****** End Of File *************************************************/
|
||||
|
||||
Reference in New Issue
Block a user